id: ec2-public-ip info: name: Public IP on EC2 Instances author: princechaddha severity: unknown description: | Ensures Amazon EC2 instances, especially backend ones, do not use public IP addresses to minimize Internet exposure. impact: | Instances with public IP addresses are more vulnerable to Internet-based threats, compromising network security. remediation: | Restrict public IP assignment for EC2 instances, particularly for backend instances. Use private IPs and manage access via AWS VPC and security groups. reference: - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-instance-addressing.html#concepts-public-addresses metadata: max-request: 2 tags: cloud,devops,aws,amazon,ec2,aws-cloud-config variables: region: "us-east-1" flow: | code(1) for(let InstancesName of iterate(template.instances)){ set("ec2instance", InstancesName) code(2) } self-contained: true code: - engine: - sh - bash source: | aws ec2 describe-instances --region $region --output json --query 'Reservations[*].Instances[*].InstanceId' extractors: - type: json name: instances internal: true json: - '.[].[]' - engine: - sh - bash source: | aws ec2 describe-instances --region $region --instance-ids $ec2instance --query "Reservations[*].Instances[*].NetworkInterfaces[*].Association.IpOwnerId[] | []" matchers: - type: word words: - "amazon" extractors: - type: dsl dsl: - '"The Amazon Instance " + ec2instance + " uses public IP addresses"' # digest: 4a0a00473045022100d6d48dea82c4b3c88a81c6060dbedadb56502f1d2b692dd7d309e67b7d20504602203063ae7dcaa055dc54d9d6f0f534a96feb3966280b2a9004201fc21fe7752964:922c64590222798bb761d5b6d8e72950