RDS instances must not be deployed into public subnets because public routability exposes the database to direct internet access, increasing the risk of unauthorized access, brute-force attacks, and data exfiltration. In AWS CloudFormation, verify the AWS::RDS::DBInstanceDBSubnetGroupName reference and ensure the referenced AWS::RDS::DBSubnetGroupSubnetIds do not include any AWS::EC2::Subnet with unrestricted CIDRs. Specifically, flag subnets where CidrBlock equals 0.0.0.0/0 or Ipv6CidrBlock equals ::/0. Database subnet groups containing such subnets will be reported as insecure.
Secure example with private subnets:
MyPrivateSubnet1:Type:AWS::EC2::SubnetProperties:CidrBlock:10.0.1.0/24VpcId:vpc-12345MyPrivateSubnet2:Type:AWS::EC2::SubnetProperties:CidrBlock:10.0.2.0/24VpcId:vpc-12345MyDBSubnetGroup:Type:AWS::RDS::DBSubnetGroupProperties:DBSubnetGroupDescription:"Private subnets for RDS"SubnetIds:- !Ref MyPrivateSubnet1- !Ref MyPrivateSubnet2MyDBInstance:Type:AWS::RDS::DBInstanceProperties:DBSubnetGroupName:!Ref MyDBSubnetGroupEngine:mysqlDBInstanceClass:db.t3.medium