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-db-security-group-with-public-scope.md.
A documentation index is available at /llms.txt.
Security groups must not allow unrestricted IP ranges because a cidr_ip of 0.0.0.0/0 grants access from the entire Internet and exposes instances to unauthorized access, brute-force attacks, and data exfiltration.
For Ansible tasks using the amazon.aws.ec2_group or ec2_group modules, check the rules (ingress) and rules_egress (egress) entries and ensure each cidr_ip is not 0.0.0.0/0. Prefer specific trusted CIDRs, private address ranges (for example 10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12), or references to other security groups.
This rule flags any ec2_group.rules[].cidr_ip or ec2_group.rules_egress[].cidr_ip set to a public scope such as 0.0.0.0/0. Review and replace wide-open CIDRs with least-privilege network ranges or security-group references.
- name:example ec2 group2ec2_group:name:example1description:an example EC2 groupvpc_id:12345region:eu-west-1aaws_secret_key:SECRETaws_access_key:ACCESSrules:- proto:tcpfrom_port:80to_port:80cidr_ip:10.1.1.1/32rules_egress:- proto:tcpfrom_port:80to_port:80cidr_ip:10.1.1.1/32group_name:example-other# description to use if example-other needs to be createdgroup_desc:other example EC2 group
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_security_groups:["example"]- name:example ec2 groupec2_group:name:exampledescription:an example EC2 groupvpc_id:12345region:eu-west-1aaws_secret_key:SECRETaws_access_key:ACCESSrules:- proto:tcpfrom_port:80to_port:80cidr_ip:0.0.0.0/0- proto:tcpfrom_port:22to_port:22cidr_ip:10.0.0.0/8- proto:tcpfrom_port:443to_port:443group_id:amazon-elb/sg-87654321/amazon-elb-sg- proto:tcpfrom_port:3306to_port:3306group_id:123412341234/sg-87654321/exact-name-of-sg- proto:udpfrom_port:10050to_port:10050cidr_ip:10.0.0.0/8- proto:udpfrom_port:10051to_port:10051group_id:sg-12345678- proto:icmpfrom_port:8# icmp type, -1 = any typeto_port:-1# icmp subtype, -1 = any subtypecidr_ip:192.168.1.0/24- proto:allgroup_name:examplerules_egress:- proto:tcpfrom_port:80to_port:80cidr_ip:0.0.0.0/0group_name:example-othergroup_desc:other example EC2 group
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.