Skip to content
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

fix(aws-ec2): imported VPC subnets never recognized as PRIVATE_ISOLATED #17496

Merged
merged 13 commits into from
Dec 1, 2021

Conversation

encron
Copy link
Contributor

@encron encron commented Nov 13, 2021

fixes #17035

I do want to note that this does not cover all cases. For example, it could also be that there is a NAT instance used for internet routing instead of a NAT gateway. It's however near impossible to figure out if a route to an instance is a route to a NAT instance or just a random EC2 instance.

Next to that, it can also be that the NAT gateway is running in a private subnet to do routing between different VPCs instead of the internet. In that case, the subnet would not match any of the current "variations" that are defined in the aws-cdk documentation (https://docs.aws.amazon.com/cdk/api/latest/docs/aws-ec2-readme.html).

But since the types are referred to as PRIVATE_WITH_NAT and PRIVATE_WITHOUT_NAT, I assume this implementation to be sufficient. I did add an extra check on the destination CIDR block being 0.0.0.0/0 since that is what someone would commonly use if the purpose of the NAT gateway is internet routing in any case. See f.e. https://docs.aws.amazon.com/vpc/latest/userguide/route-table-options.html#route-tables-nat.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Nov 13, 2021

@github-actions github-actions bot added the @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud label Nov 13, 2021
Copy link
Contributor

@njlynch njlynch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Sorry for the delay in response.

Can you add just one more test for the ISOLATED case? Given that's the new behavior here, it would be good to have a test capturing it.

@mergify mergify bot dismissed njlynch’s stale review December 1, 2021 14:24

Pull request has been modified.

@encron
Copy link
Contributor Author

encron commented Dec 1, 2021

No worries, thanks for the review!

Can you add just one more test for the ISOLATED case? Given that's the new behavior here, it would be good to have a test capturing it.

Makes sense indeed, I've added extra test cases for an Isolated subnet. Also updated the in-line comment to better explain the process of determining the subnet type.

njlynch
njlynch previously approved these changes Dec 1, 2021
Copy link
Contributor

@njlynch njlynch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@njlynch njlynch changed the title fix(aws-ec2): SubnetType.PRIVATE_WITH_NAT selection with imported VPC also returns isolated subnet(s) fix(aws-ec2): imported VPC subnets never recognized as ISOLATED. Dec 1, 2021
@njlynch njlynch changed the title fix(aws-ec2): imported VPC subnets never recognized as ISOLATED. fix(aws-ec2): imported VPC subnets never recognized as PRIVATE_ISOLATED Dec 1, 2021
@mergify mergify bot dismissed njlynch’s stale review December 1, 2021 15:19

Pull request has been modified.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 7e8d4a4
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit ba6a8ef into aws:master Dec 1, 2021
@mergify
Copy link
Contributor

mergify bot commented Dec 1, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Feb 21, 2022
…ED (aws#17496)

fixes aws#17035

I do want to note that this does not cover all cases. For example, it could also be that there is a NAT instance used for internet routing instead of a NAT gateway. It's however near impossible to figure out if a route to an instance is a route to a NAT instance or just a random EC2 instance.

Next to that, it can also be that the NAT gateway is running in a private subnet to do routing between different VPCs instead of the internet. In that case, the subnet would not match any of the current "variations" that are defined in the `aws-cdk` documentation (https://docs.aws.amazon.com/cdk/api/latest/docs/aws-ec2-readme.html).

But since the types are referred to as `PRIVATE_WITH_NAT` and `PRIVATE_WITHOUT_NAT`, I assume this implementation to be sufficient. I did add an extra check on the destination CIDR block being `0.0.0.0/0` since that is what someone would commonly use if the purpose of the NAT gateway is internet routing in any case. See f.e. https://docs.aws.amazon.com/vpc/latest/userguide/route-table-options.html#route-tables-nat.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws-ec2): SubnetType.PRIVATE_WITH_NAT selection with imported VPC also returns isolated subnet(s)
3 participants