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-security-group-ingress-not-restricted.md.
A documentation index is available at /llms.txt.
Security groups must not allow unrestricted ingress from the public internet to all protocols and ports. Such rules expose instances to network scanning, exploitation, and unauthorized access.
In Ansible amazon.aws.ec2_group and ec2_group resources, each rules entry must not combine from_port: 0 and to_port: 0 with a non-explicit proto and an entire-network CIDR such as cidr_ip: 0.0.0.0/0 or cidr_ipv6: ::/0.
The proto property must be an explicit protocol such as tcp, udp, icmp, icmpv6, or numeric values 1, 6, 17, 58. Rules where proto is missing or set to a catch-all (-1/all) with ports 0-0 and an entire-network CIDR are flagged.
To fix this, restrict the CIDR to trusted IP ranges or specify the exact protocol and port range required for the service.
Secure configuration example:
- name:secure security groupamazon.aws.ec2_group:name:my_sgdescription:"Allow SSH from admin network and HTTPS from anywhere"rules:- proto:tcpfrom_port:22to_port:22cidr_ip:203.0.113.0/24- proto:tcpfrom_port:443to_port:443cidr_ip:0.0.0.0/0
Compliant Code Examples
- name:example ec2 group v3amazon.aws.ec2_group:name:exampledescription:an example EC2 groupvpc_id:12345region:eu-west-1rules:- proto:tcpfrom_port:80to_port:80cidr_ip:10.0.0.0/8- name:example ec2 group v4amazon.aws.ec2_group:name:exampledescription:an example EC2 groupvpc_id:12345region:eu-west-1rules:- proto:tcpfrom_port:80to_port:80cidr_ipv6:2001:DB8:8086:6502::/32
Non-Compliant Code Examples
- name:example ec2 groupamazon.aws.ec2_group:name:exampledescription:an example EC2 groupvpc_id:12345region:eu-west-1rules:- proto:-1from_port:0to_port:0cidr_ip:0.0.0.0/0- proto:allfrom_port:0to_port:0cidr_ip:0.0.0.0/0- proto:12121from_port:0to_port:0cidr_ip:0.0.0.0/0- name:example ec2 group v2amazon.aws.ec2_group:name:exampledescription:an example EC2 groupvpc_id:12345region:eu-west-1rules:- proto:-1from_port:0to_port:0cidr_ipv6:::/0- proto:allfrom_port:0to_port:0cidr_ipv6:::/0- proto:121212from_port:0to_port:0cidr_ipv6:::/0
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.