Description
For an internal web service, list only its client CIDRs or source security groups and required ports under rules. For a public website, keep public access on the ports its clients need.
Potential impact
0.0.0.0/0 and ::/0 include every IPv4 and IPv6 source, respectively. With public addressing, a route and a listening service, an administrative port can also receive external connections.
Remediation
To narrow ingress, keep the default purge_rules: true and list every rule that must remain. Check both address families and verify that approved clients connect and unapproved connections are blocked.
Examples
Both tasks manage the same group in eu-west-1. Supply the target VPC as vpc_id and replace 172.16.17.0/24 with the actual client range.
Before
- name: example
amazon.aws.ec2_group:
name: example1
description: an example EC2 group
vpc_id: "{{ vpc_id }}"
region: eu-west-1
rules:
- proto: tcp
ports:
- 80
- 443
- 8080-8099
cidr_ip: 0.0.0.0/0
The first allows TCP 80, 443 and 8080–8099 from every IPv4 address.
After
- name: example
amazon.aws.ec2_group:
name: example1
description: an example EC2 group
vpc_id: "{{ vpc_id }}"
region: eu-west-1
rules:
- proto: tcp
ports:
- 80
- 443
cidr_ip: 172.16.17.0/24
The second keeps only TCP 80 and 443 from the specified range.