π AWS EC2 Instance with an auto-assigned public IP address is in a default subnet π’
- Contextual name: π Instance with an auto-assigned public IP address is in a default subnet π’
- ID:
/ce/ca/aws/ec2/instance-with-public-ip-in-default-subnet
- Located in: π AWS EC2
Flagsβ
- π’ Policy with categories
- π’ Policy with type
- π’ Production policy
Our Metadataβ
- Policy Type:
COMPLIANCE_POLICY
- Policy Category:
SECURITY
RELIABILITY
Logicβ
- π§ prod.logic.yaml π’
Descriptionβ
Descriptionβ
This policy checks if any AWS EC2 Instance with a public IP address is deployed within a default subnet.
By default, a default subnet is configured as a public subnet because the main route table is associated with an internet gateway, enabling outbound traffic to the internet.
Instances launched into a default subnet are automatically assigned a public IPv4 address, a private IPv4 address, and both public and private DNS hostnames.
Rationaleβ
Deploying instances in default subnets can inadvertently expose them to the public internet. Default VPCs and subnets are intended for ease of deployment and testing, rather than for building secure, production-grade environments.
Production workloads and sensitive resources should always be provisioned in custom VPCs with dedicated subnets, where routing, access, and security controls are explicitly defined and managed.
Auditβ
This policy flags an AWS EC2 Instance as
INCOMPLIANT
if it has aPublic IP Address
and resides in a VPC Subnet where bothDefault For AZ
andMap Public IP On Launch
checkboxes are set to true.... see more
Remediationβ
Remediationβ
From Command Lineβ
Consider two remediation paths:
- Option 1: Remove the public IP address if it is not required.
- Option 2: Relocate the instance to a purpose-built subnet (public or private, depending on requirements).
Option 1: Remove the Public IP Addressβ
If direct inbound access from the internet is not required, remove the public IP.
Modify network interface settings to disable public IP auto-assignment:
aws ec2 modify-network-interface-attribute \
--network-interface-id {{network-interface-id}} \
--no-associate-public-ip-address(Recommended) Disable the Auto-assign Public IPv4 Address Subnet Attributeβ
aws ec2 modify-subnet-attribute \
--subnet-id {{subnet-id}} \
--no-map-public-ip-on-launchOption 2: Move the Instance to a Custom Subnetβ
If the instance must remain publicly accessible, it should be deployed in a custom public subnet with explicit security controls (e.g., restrictive security groups, NACLs).
If it only requires outbound internet access, deploy it into a private subnet that routes traffic through a NAT Gateway.
... see more