For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/ansible-aws-rds-associated-with-public-subnet.md.
A documentation index is available at /llms.txt.
RDS instances must not be placed in public subnets because an internet-routable subnet exposes the database endpoint to the internet, increasing the risk of unauthorized access and data exfiltration. This rule inspects Ansible tasks that create RDS instances (resource types amazon.aws.rds_instance or rds_instance) and requires the subnet group property (db_subnet_group_name or subnet_group) to reference a subnet group composed only of private subnets.
It verifies the referenced subnet group tasks (amazon.aws.rds_subnet_group or rds_subnet_group) and the subnet tasks (amazon.aws.ec2_vpc_subnet or ec2_vpc_subnet). Any subnet with cidr equal to 0.0.0.0/0 or ipv6_cidr equal to ::/0 is treated as public and triggers a finding.
Resources that are missing the subnet-group property or that include any public subnet in the subnet group are flagged. Ensure subnet groups list subnets using private CIDR ranges and that registered subnet task names match the entries in the subnet group.
Secure example with private subnet CIDRs:
- name:Create private subnetamazon.aws.ec2_vpc_subnet:vpc_id:vpc-123cidr:10.0.1.0/24register:private_subnet_a- name:Create RDS subnet group using private subnetsamazon.aws.rds_subnet_group:name:my-db-subnet-groupsubnets:- "{{ private_subnet_a }}"- name:Create RDS instance in private subnet groupamazon.aws.rds_instance:db_subnet_group_name:my-db-subnet-group# other RDS properties...
Compliant Code Examples
- name:create minimal aurora instance in default VPC and default subnet group2amazon.aws.rds_instance:engine:auroradb_instance_identifier:ansible-test-aurora-db-instanceinstance_type:db.t2.smallpassword:"{{ password }}"username:"{{ username }}"cluster_id:ansible-test-clusterdb_subnet_group_name:my_subnet_group2- name:Add or change a subnet group2amazon.aws.rds_subnet_group:state:presentname:my_subnet_group2description:My Fancy Ex Parrot Subnet Groupsubnets:- "{{ subnet22.subnet.id }}"register:my_subnet_group2- name:Create subnet for database servers22amazon.aws.ec2_vpc_subnet:state:presentvpc_id:vpc-123456cidr:10.0.1.16/28tags:Name:Database Subnetregister:subnet22
Non-Compliant Code Examples
- name:create minimal aurora instance in default VPC and default subnet groupamazon.aws.rds_instance:engine:auroradb_instance_identifier:ansible-test-aurora-db-instanceinstance_type:db.t2.smallpassword:"{{ password }}"username:"{{ username }}"cluster_id:ansible-test-clusterdb_subnet_group_name:my_subnet_group- name:Add or change a subnet groupamazon.aws.rds_subnet_group:state:presentname:my_subnet_groupdescription:My Fancy Ex Parrot Subnet Groupsubnets:- "{{ subnet1.subnet.id }}"- "{{ subnet2.subnet.id }}"register:my_subnet_group- name:Create subnet for database serversamazon.aws.ec2_vpc_subnet:state:presentvpc_id:vpc-123456cidr:0.0.0.0/0tags:Name:Database Subnetregister:subnet1- name:Create subnet for database servers2amazon.aws.ec2_vpc_subnet:state:presentvpc_id:vpc-123456cidr:10.0.1.16/28tags:Name:Database Subnetregister:subnet2
1
2
rulesets:- Ansible / AWS # Rules to enforce / AWS.
Request a personalized demo
Get Started with Datadog
Ask AI
AI-generated responses may be inaccurate. Verify important info.