EC2 instance subnet has public IP mapping on launch
This product is not supported for your selected
Datadog site. (
).
Id: b3de4e4c-14be-4159-b99d-9ad194365e4c
Cloud Provider: AWS
Platform: CloudFormation
Severity: Medium
Category: Networking and Firewall
Learn More
Description
Subnets must not automatically assign public IPv4 addresses to instances because automatic public IP assignment exposes instances directly to the internet and increases the risk of unauthorized access and data exposure. For CloudFormation, the AWS::EC2::Subnet resource’s Properties.MapPublicIpOnLaunch property must be defined and set to false. Resources with MapPublicIpOnLaunch set to true will be flagged. For private subnets, explicitly set this property to false and use NAT gateways, bastion hosts, or load balancers to provide controlled outbound or inbound access.
Secure configuration example:
MyPrivateSubnet:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref MyVPC
CidrBlock: 10.0.1.0/24
MapPublicIpOnLaunch: false
Compliant Code Examples
AWSTemplateFormatVersion: "2010-09-09"
Description: A sample template
Resources:
mySubnet:
Type: AWS::EC2::Subnet
Properties:
MapPublicIpOnLaunch: false
VpcId: myVPC
CidrBlock: 10.0.0.0/24
AvailabilityZone: "us-east-1a"
Tags:
- Key: foo
Value: bar
{
"Resources": {
"mySubnet": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"Tags": [
{
"Key": "foo",
"Value": "bar"
}
],
"MapPublicIpOnLaunch": false,
"VpcId": "myVPC",
"CidrBlock": "10.0.0.0/24",
"AvailabilityZone": "us-east-1a"
}
}
},
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "A sample template"
}
Non-Compliant Code Examples
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "A sample template",
"Resources": {
"mySubnet": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"MapPublicIpOnLaunch": true,
"VpcId": "myVPC",
"CidrBlock": "10.0.0.0/24",
"AvailabilityZone": "us-east-1a",
"Tags": [
{
"Key": "foo",
"Value": "bar"
}
]
}
}
}
}
AWSTemplateFormatVersion: "2010-09-09"
Description: A sample template
Resources:
mySubnet:
Type: AWS::EC2::Subnet
Properties:
MapPublicIpOnLaunch: true
VpcId: myVPC
CidrBlock: 10.0.0.0/24
AvailabilityZone: "us-east-1a"
Tags:
- Key: foo
Value: bar