Repository navigation
Conversation
There was a problem hiding this comment.
The pull request linter fails with the following errors:
❌ Fixes must contain a change to an integration test file and the resulting snapshot.
If you believe this pull request should receive an exemption, please comment and provide a justification. A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed, add Clarification Request to a comment.
✅ A exemption request has been requested. Please wait for a maintainer's review.
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
|
@aws-cdk-automation Exemption Request - Requested changes have been committed. |
leonmk-aws
left a comment
There was a problem hiding this comment.
This adds validation that rejects input which previously synthesized and deployed successfully — a misaligned base like 10.0.1.0/20 used to be rounded to 10.0.0.0/20 and deployed fine. Existing apps that pass a misaligned CIDR (deliberately or by typo that "worked") will now fail at synth the moment they upgrade, with no opt-out.
Adding this validation should be done under a feature flag to preserve backwards compatibility.
There was a problem hiding this comment.
Integ tests for EC2 reside in: packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test, though I don't think we need an integration test for this.
|
|
||
| ### Bug Fixes | ||
|
|
||
| * **ec2:** validate that mis-aligned CIDR blocks now throw an error instead of silently rounding up (#34784) |
There was a problem hiding this comment.
The changelog is auto generated, no need to edit this file.
| export class InvalidCidrRangeError extends Error { | ||
| constructor(cidr: string) { | ||
| super(cidr + ' is not a valid VPC CIDR range. VPCs must be between /16 and /28 and the minimum subnet size is /28.'); | ||
| super( |
There was a problem hiding this comment.
Let's not do these linting changes (applies to the other changes as well).
…tion Resolve conflicts by taking upstream's version of the CIDR code and drop the previous approach (unconditional validation in CidrBlock, formatting changes, manual CHANGELOG entry and integ test files) in favor of a feature-flagged check in the follow-up commit.
A misaligned CIDR block passed to `IpAddresses.cidr()` (or the deprecated `cidr` property), such as `10.0.40.0/19`, is silently rounded up to the next aligned block (`10.0.64.0/19`). Add the `@aws-cdk/aws-ec2:validateVpcCidrAlignment` feature flag. When enabled, `Vpc` throws a validation error for a misaligned CIDR block and suggests the aligned blocks below and above it. When disabled, the existing rounding behavior is preserved. Closes aws#34784.
|
@leonmk-aws thanks for the review. I've reworked the PR to address all of your feedback:
I also fixed the README example, which used a misaligned CIDR ( |
|
Exemption Request - this change only adds a synthesis-time validation behind a feature flag and is fully covered by unit tests for both flag states. As suggested in review, an integration test isn't needed for this change. |
Issue # (if applicable)
Closes #34784.
Reason for this change
When a
Vpcis given a CIDR block throughIpAddresses.cidr()(or the deprecatedcidrproperty) whose base address is not aligned to its prefix length, such as10.0.40.0/19, the CDK silently rounds the block up to the next aligned block (10.0.64.0/19). The deployed VPC then has a different address range than the one requested, which can go unnoticed and cause routing or peering issues later.Rejecting these CIDRs unconditionally would break existing apps that currently synthesize and deploy with a misaligned CIDR, so the validation is introduced behind a feature flag.
Description of changes
@aws-cdk/aws-ec2:validateVpcCidrAlignmentbug-fix feature flag (unconfiguredBehavesLike: false, recommended valuetrue).Vpcthrows aValidationErrorif the CIDR block provided throughIpAddresses.cidr()or the deprecatedcidrproperty is not aligned to its prefix length. The error suggests the aligned blocks below and above the given one, e.g.:Vpc(where the construct scope needed to read the flag is available) and only applies to the localIpAddresses.cidr()provider.CidrBlockandNetworkBuilderare unchanged, so subnet allocation behaves exactly as before.aws-ec2README and fix two doc examples that used a misaligned CIDR (10.0.1.0/20).FEATURE_FLAGS.mdandrecommended-feature-flags.json.Describe any new or updated permissions being added
N/A
Description of how you validated changes
Added unit tests in
aws-ec2/test/ip-addresses.test.tscovering:IpAddresses.cidr()and the deprecatedcidrproperty,Added the flag to the defaults check in
cx-api/test/features.test.ts. Theip-addresses,network-utilsandfeaturestest suites pass, and ESLint passes on the changed files.No integration test was added, as the change only affects synthesis-time validation and is fully covered by unit tests (per review feedback).
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license