Description
Identify the service listening on TCP 8001–8002 and the clients that need it. An unfamiliar port can serve a legitimate public or internal service.
Potential impact
With public addressing and a route, 0.0.0.0/0 may expose the service to all IPv4 clients and ::/0 to all IPv6 clients.
Remediation
Limit internal and administrative services to approved CIDRs or source security groups. For a public service, keep only the required ports and check authentication and security updates. Test permitted and denied connections with all attached groups and host controls in effect.
Examples
Supply AWS credentials in the execution environment, vpc_id and allowed_client_cidr. Both tasks manage the same group. The default purge_rules: true removes unlisted ingress rules, so include all those that must remain.
Before
- 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: 8001
to_port: 8002
cidr_ip: 0.0.0.0/0
The first rule allows TCP 8001–8002 from all IPv4 sources.
After
- 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: 8001
to_port: 8002
cidr_ip: "{{ allowed_client_cidr }}"
The second keeps both ports and restricts the source to the approved client range. Configure the group attachment and routes separately.