🛡️ 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
- Tags:
- Policy Type:
COMPLIANCE_POLICY
- Policy Categories:
SECURITY
,RELIABILITY
Logic
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