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-unrestricted-security-group-ingress.md.
A documentation index is available at /llms.txt.
Security group ingress rules must not allow traffic from the entire Internet (IPv4 0.0.0.0/0 or IPv6 ::/0) to specific ports. This exposes services to unauthorized access and automated attacks such as brute force and port scanning.
This rule inspects Ansible amazon.aws.ec2_group and ec2_group tasks and flags rules entries that define ports (via from_port/to_port or ports) where cidr_ip is 0.0.0.0/0 or cidr_ipv6 is ::/0. It also detects these values when CIDRs are provided as lists.
To remediate, restrict ingress to specific trusted CIDR ranges, use security group-to-security group references or VPN/bastion hosts, and remove or replace 0.0.0.0/0 and ::/0 from rules that open ports.
Secure configuration example (restrict SSH to a trusted IPv4 range and allow HTTPS from a specific IPv6 range):
- name:Create restricted SGamazon.aws.ec2_group:name:my-sgdescription:"Restrict SSH and HTTPS to trusted networks"rules:- proto:tcpfrom_port:22to_port:22cidr_ip:10.0.0.0/24- proto:tcpfrom_port:443to_port:443cidr_ipv6:"2001:db8::/32"
Compliant Code Examples
- name:example1amazon.aws.ec2_group:name:example1description:an example EC2 groupvpc_id:12345region:eu-west-1rules:- proto:tcpports:- 80- 443- 8080-8099cidr_ip:172.16.17.0/24- name:example2amazon.aws.ec2_group:name:example2description:an example EC2 groupvpc_id:12345region:eu-west-1rules:- proto:tcpports:- 80- 443- 8080-8099cidr_ip:- 172.16.1.0/24- name:example3amazon.aws.ec2_group:name:example3description:an example EC2 groupvpc_id:12345region:eu-west-1rules:- proto:tcpports:- 80- 443- 8080-8099cidr_ipv6:2607:F8B0::/32- name:example4amazon.aws.ec2_group:name:example4description:an example EC2 groupvpc_id:12345region:eu-west-1rules:- proto:tcpports:- 80- 443- 8080-8099cidr_ipv6:- 64:ff9b::/96- 2607:F8B0::/32
Non-Compliant Code Examples
---- name:example1amazon.aws.ec2_group:name:example1description:an example EC2 groupvpc_id:12345region:eu-west-1rules:- proto:tcpports:- 80- 443- 8080-8099cidr_ip:0.0.0.0/0- name:example2amazon.aws.ec2_group:name:example2description:an example EC2 groupvpc_id:12345region:eu-west-1rules:- proto:tcpports:- 80- 443- 8080-8099cidr_ip:- 0.0.0.0/0- name:example3amazon.aws.ec2_group:name:example3description:an example EC2 groupvpc_id:12345region:eu-west-1rules:- proto:tcpports:- 80- 443- 8080-8099cidr_ipv6:::/0- name:example4amazon.aws.ec2_group:name:example4description:an example EC2 groupvpc_id:12345region:eu-west-1rules:- proto:tcpports:- 80- 443- 8080-8099cidr_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.