-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(aws-ec2): Disabling auto-assign public IP to public subnets #16838
Comments
Thanks for the feature request. I agree with the proposed solution. Contributions welcome!
You can use escape hatches to alter the setting in the interim. |
…ets (#17346) **Issue (Fixes #14194, #16838 When creating a VPC you can define a SubnetConfiguration but it is not possible to define `mapPublicIpOnLaunch` for public subnets. VPC Example: ``` const vpc = new ec2.Vpc(this, 'vpc-id', { maxAzs: 2, subnetConfiguration: [ { name: 'private-subnet-1', subnetType: ec2.SubnetType.PRIVATE, cidrMask: 24, }, { name: 'public-subnet-1', subnetType: ec2.SubnetType.PUBLIC, cidrMask: 24, }, ] }); ``` Proposal: ``` const vpc = new ec2.Vpc(this, 'vpc-id', { maxAzs: 2, subnetConfiguration: [ { name: 'private-subnet-1', subnetType: ec2.SubnetType.PRIVATE, cidrMask: 24, }, { name: 'public-subnet-1', subnetType: ec2.SubnetType.PUBLIC, cidrMask: 24, mapPublicIpOnLaunch: false, // or true }, ] }); ```
…ets (aws#17346) **Issue (Fixes aws#14194, aws#16838 When creating a VPC you can define a SubnetConfiguration but it is not possible to define `mapPublicIpOnLaunch` for public subnets. VPC Example: ``` const vpc = new ec2.Vpc(this, 'vpc-id', { maxAzs: 2, subnetConfiguration: [ { name: 'private-subnet-1', subnetType: ec2.SubnetType.PRIVATE, cidrMask: 24, }, { name: 'public-subnet-1', subnetType: ec2.SubnetType.PUBLIC, cidrMask: 24, }, ] }); ``` Proposal: ``` const vpc = new ec2.Vpc(this, 'vpc-id', { maxAzs: 2, subnetConfiguration: [ { name: 'private-subnet-1', subnetType: ec2.SubnetType.PRIVATE, cidrMask: 24, }, { name: 'public-subnet-1', subnetType: ec2.SubnetType.PUBLIC, cidrMask: 24, mapPublicIpOnLaunch: false, // or true }, ] }); ```
…ets (aws#17346) **Issue (Fixes aws#14194, aws#16838 When creating a VPC you can define a SubnetConfiguration but it is not possible to define `mapPublicIpOnLaunch` for public subnets. VPC Example: ``` const vpc = new ec2.Vpc(this, 'vpc-id', { maxAzs: 2, subnetConfiguration: [ { name: 'private-subnet-1', subnetType: ec2.SubnetType.PRIVATE, cidrMask: 24, }, { name: 'public-subnet-1', subnetType: ec2.SubnetType.PUBLIC, cidrMask: 24, }, ] }); ``` Proposal: ``` const vpc = new ec2.Vpc(this, 'vpc-id', { maxAzs: 2, subnetConfiguration: [ { name: 'private-subnet-1', subnetType: ec2.SubnetType.PRIVATE, cidrMask: 24, }, { name: 'public-subnet-1', subnetType: ec2.SubnetType.PUBLIC, cidrMask: 24, mapPublicIpOnLaunch: false, // or true }, ] }); ```
I'm shocked this hasn't been prioritized, having the CDK violate AWS Foundational Security Best Practices by default and not providing settings to remedy this is not the kind of security first prioritisation I expect from AWS. Apart from anything else, what are the teams within AWS who use the CDK doing? Also, asking us to use the escape hatches without an example is a bit of an ask, reaching into the VPC to find the CFN objects for the public subnets and update them is not trivial. For reference for those who need it, this is how I did things in Python:
|
Definitely should be considered as part of #5927 |
Description
I think it would be great if there is a way to make it possible to disable auto-assign public IP to public subnets on VPC creation.
When you create a VPC with subnets, public subnets will always have auto-assigned IP address.
example code:
CDK implementation:
aws-cdk/packages/@aws-cdk/aws-ec2/lib/vpc.ts
Line 1433 in d29a20b
However, this behavior occurs problems in some situation, for example, "AWS Foundational Security Best Practices" does not allow this.
https://docs.aws.amazon.com/securityhub/latest/userguide/securityhub-standards-fsbp-controls.html#fsbp-ec2-15
Use Case
If you don't want all public subnets to have auto-assigned IPs, you can disable subnet-level public IP auto-assignment, and your architecture will meet the "AWS Foundational Security Best Practices" standards.
Proposed Solution
You can pass the flag for enabling or disabling auto-assign public IP to public subnets, like the following:
Other information
I look forward to have any workaround for disabling auto-assign public IP to public subnets in current version of CDK.
Acknowledge
The text was updated successfully, but these errors were encountered: