Security group ingress allows all IPv4 or IPv6 sources

Review whether all-source security group ingress is needed, and restrict internal services and administrative access to approved sources.

Description

An ingress rule with 0.0.0.0/0 allows any IPv4 source. ::/0 allows any IPv6 source. Each applies to the ports and protocol in that rule.

Potential impact

If an internet path exists, unwanted connections can reach multiple resources that share the group.

Remediation

  1. Limit internal and administrative access to approved client CIDRs or supported security group references. For VPN clients, check the source address the service actually sees.
  2. For public services, allow only required ports and protocols and retain application authentication. Review other attached groups as well.
  3. By default, purge_rules is true and removes inbound rules omitted from the task. List every rule you need to keep. Test both allowed and blocked connections after applying the change.

Examples

Supply the target vpc_id and AWS credentials in the execution environment. Both tasks manage the same group’s TCP port 80 rule.

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

After

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: 10.1.1.1/32

10.1.1.1/32 permits one IPv4 address. Replace it with the approved client’s actual source range.

References