Description
Limit inbound traffic to the sources that use the service. Even a private CIDR can include unrelated hosts. Check the actual clients, listening port and protocol for every resource that shares the group.
Potential impact
Any host in the allowed range with a network path to the service can attempt a connection. Service authentication still controls access to data.
Remediation
- Use an approved client CIDR or a source security group where supported. Check routing and every attached group for other rules allowing the same port.
purge_rulesdefaults totrue, so the task removes existing inbound rules omitted from the list. Leave purging enabled when narrowing the source and include every rule to keep. After applying the change, test new connections from approved and unapproved sources.
Examples
Supply vpc_id and AWS credentials for Ansible. Both tasks manage the same group in eu-west-1 and use TCP port 80 as an example.
Before
yaml
- name: example ec2 group
amazon.aws.ec2_security_group:
name: example
description: an example EC2 group
vpc_id: "{{ vpc_id }}"
region: eu-west-1
rules:
- proto: tcp
from_port: 80
to_port: 80
cidr_ip: 0.0.0.0/0
0.0.0.0/0 allows all IPv4 sources on that port.
After
yaml
- name: example ec2 group2
amazon.aws.ec2_security_group:
name: example
description: an example EC2 group
vpc_id: "{{ vpc_id }}"
region: eu-west-1
rules:
- proto: tcp
from_port: 80
to_port: 80
cidr_ip: 10.1.1.1/32
10.1.1.1/32 allows one IPv4 source. Replace it with the approved client’s address.