Skip to content

Commit c3ddabf

Browse files
ybezsonovYuriy Bezsonov
andauthored
feat(cdk): Upgrade to aws-cdk-lib 2.250 and graduated eks_v2 (#922)
Move infra/cdk to the highest CDK baseline that keeps cdk-nag suppressions working, and off the deprecated EKS alpha module. - Bump aws-cdk-lib 2.235.0 -> 2.250.0 (highest before the native Validations framework in 2.251 breaks cdk-nag 2.x suppression). - Drop the deprecated eks-v2-alpha module and repoint imports to the graduated stable software.amazon.awscdk.services.eks_v2 package. - Add appliesTo evidence to the IAM4/IAM5 nag suppressions so they actually suppress under the current CDK CLI (a bare rule id does not). - Document the version ceiling and the concrete update trigger in infra/cdk/NAG.md. - Update the workshop IAM policy resource id. Verified: cdk synth passes with 0 cdk-nag findings under the latest CLI. Co-authored-by: Yuriy Bezsonov <bezsonov@amazon.de>
1 parent c9660e3 commit c3ddabf

6 files changed

Lines changed: 100 additions & 28 deletions

File tree

infra/cdk/NAG.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# cdk-nag / CDK version ceiling
2+
3+
## Current pinned versions
4+
- `aws-cdk-lib`: **2.250.0**
5+
- `cdk-nag`: **2.38.2**
6+
- EKS: stable `software.amazon.awscdk.services.eks_v2` (the deprecated `eks-v2-alpha` module was dropped).
7+
8+
`cdk synth` passes with **0 cdk-nag findings** under the latest CDK CLI with this
9+
combination. IAM4/IAM5 suppressions in `WorkshopApp` carry explicit `appliesTo`
10+
evidence (a bare `AwsSolutions-IAM5` id does not suppress).
11+
12+
## Why not newer
13+
14+
`aws-cdk-lib` 2.251.0 introduced CDK's native policy-validation framework
15+
(`software.amazon.awscdk.Validations`). From 2.251 onward, cdk-nag findings are
16+
routed through it and must be suppressed via `Validations.of(scope).acknowledge()`
17+
instead of `NagSuppressions`.
18+
19+
That acknowledge API treats `::` as a reserved `prefix::ruleName` delimiter, so it
20+
rejects finding ids that embed IAM ARNs (which contain `iam::aws` and
21+
`arn:<AWS::Partition>:...`), e.g.:
22+
23+
AwsSolutions::AwsSolutions-IAM4[Policy::arn:<AWS::Partition>:iam::aws:policy/AdministratorAccess]
24+
-> InvalidValidationId: The '::' delimiter is reserved for separating the prefix from the rule name
25+
26+
Because every AWS managed-policy finding embeds `iam::aws`, IAM4/IAM5 findings
27+
cannot currently be acknowledged on aws-cdk-lib >= 2.251.
28+
29+
cdk-nag 3.x does not help: its `NagPack` is plugin-only
30+
(`IPolicyValidationPlugin`, no `IAspect`), so it relies entirely on the same
31+
native `acknowledge` mechanism and cannot run report-only either.
32+
33+
Verified: 2.250 synth passes (0 findings); 2.260 synth fails with 19 IAM4/IAM5
34+
findings even with correct `appliesTo`.
35+
36+
## Trigger to update
37+
38+
Do NOT pin the CDK CLI and do NOT add a Dependabot `ignore` for these bumps.
39+
CI runs `cdk synth` with the latest CLI, so the Dependabot PR that bumps
40+
`aws-cdk-lib` to >= 2.251 (or `cdk-nag` to 3.x) is a live tripwire:
41+
42+
- While the `build-infra` check on that PR is **red**, the upstream gap is still open.
43+
- When that check goes **green**, the fix has landed. Then:
44+
1. bump `aws-cdk-lib` (and optionally `cdk-nag` to 3.x),
45+
2. switch the IAM4/IAM5 suppressions in `WorkshopApp` from
46+
`NagSuppressions` to `Validations.of(stack).acknowledge(...)`,
47+
3. delete this note.
48+
49+
### Manual recheck
50+
On a scratch branch with `aws-cdk-lib >= 2.251` + `cdk-nag` 3.x, confirm that
51+
52+
Validations.of(stack).acknowledge(
53+
Acknowledgment.builder()
54+
.id("AwsSolutions-IAM4[Policy::arn:<AWS::Partition>:iam::aws:policy/AdministratorAccess]")
55+
.reason("...").build());
56+
57+
no longer throws `InvalidValidationId` and that `cdk synth` exits 0.
58+
59+
## Upstream references
60+
- aws/aws-cdk#26844 - cdk synth used to return exit 0 despite policy-validation
61+
failures (fixed in recent CLIs; this is what surfaced the findings).
62+
- cdk-nag v3 README: prefix / bulk suppression "not yet supported" (tracked upstream).
63+
- Watch `aws-cdk-lib` release notes for `Validations.acknowledge` id parsing that
64+
accepts embedded `::`.

infra/cdk/pom.xml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1212
<maven.compiler.source>25</maven.compiler.source>
1313
<maven.compiler.target>25</maven.compiler.target>
14-
<cdk.version>2.235.0</cdk.version>
14+
<cdk.version>2.250.0</cdk.version>
1515
<constructs.version>10.6.0</constructs.version>
1616
<cdknag.version>2.38.2</cdknag.version>
1717
<junit.version>6.1.1</junit.version>
@@ -54,13 +54,6 @@
5454
<version>${constructs.version}</version>
5555
</dependency>
5656

57-
<!-- EKS v2 Alpha L2 Construct -->
58-
<dependency>
59-
<groupId>software.amazon.awscdk</groupId>
60-
<artifactId>eks-v2-alpha</artifactId>
61-
<version>${cdk.version}-alpha.0</version>
62-
</dependency>
63-
6457
<!-- CDK Nag for best practices validation -->
6558
<dependency>
6659
<groupId>io.github.cdklabs</groupId>

infra/cdk/src/main/java/sample/com/WorkshopApp.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,24 @@ public static void main(final String[] args) {
3737
new NagPackSuppression.Builder().id("AwsSolutions-APIG6").reason("API Gateway access logging not needed for workshop").build(),
3838
new NagPackSuppression.Builder().id("AwsSolutions-COG4").reason("Workshop environment does not require Cognito User Pool authorization").build(),
3939

40-
// IAM
41-
new NagPackSuppression.Builder().id("AwsSolutions-IAM4").reason("AWS Managed policies are acceptable for workshop").build(),
42-
new NagPackSuppression.Builder().id("AwsSolutions-IAM5").reason("Wildcard permissions acceptable for workshop parallel resource creation").build(),
40+
// IAM - IAM4/IAM5 require appliesTo evidence to suppress
41+
new NagPackSuppression.Builder().id("AwsSolutions-IAM4")
42+
.appliesTo(List.of(
43+
"Policy::arn:<AWS::Partition>:iam::aws:policy/AdministratorAccess",
44+
"Policy::arn:<AWS::Partition>:iam::aws:policy/PowerUserAccess",
45+
"Policy::arn:<AWS::Partition>:iam::aws:policy/ReadOnlyAccess",
46+
"Policy::arn:<AWS::Partition>:iam::aws:policy/AmazonSSMManagedInstanceCore",
47+
"Policy::arn:<AWS::Partition>:iam::aws:policy/CloudWatchAgentServerPolicy",
48+
"Policy::arn:<AWS::Partition>:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"))
49+
.reason("AWS managed policies are acceptable for workshop").build(),
50+
new NagPackSuppression.Builder().id("AwsSolutions-IAM5")
51+
.appliesTo(List.of(
52+
"Resource::*",
53+
"Resource::arn:<AWS::Partition>:ec2:<AWS::Region>:<AWS::AccountId>:network-interface/*",
54+
"Resource::arn:<AWS::Partition>:codebuild:<AWS::Region>:<AWS::AccountId>:report-group/<CodeBuildProjectA0FF5539>-*",
55+
"Resource::arn:<AWS::Partition>:logs:<AWS::Region>:<AWS::AccountId>:log-group:/aws/codebuild/<CodeBuildProjectA0FF5539>:*",
56+
"Resource::arn:aws:logs:<AWS::Region>:<AWS::AccountId>:log-group:/aws/bedrock/*"))
57+
.reason("Wildcard permissions acceptable for workshop parallel resource creation").build(),
4358

4459
// RDS
4560
new NagPackSuppression.Builder().id("AwsSolutions-RDS2").reason("Workshop non-sensitive test database does not need encryption at rest").build(),

infra/cdk/src/main/java/sample/com/constructs/Eks.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
import software.amazon.awscdk.services.ec2.IVpc;
44
import software.amazon.awscdk.services.ec2.ISecurityGroup;
55
import software.amazon.awscdk.services.iam.IRole;
6-
import software.amazon.awscdk.services.eks.v2.alpha.Cluster;
7-
import software.amazon.awscdk.services.eks.v2.alpha.KubernetesVersion;
8-
import software.amazon.awscdk.services.eks.v2.alpha.AccessEntry;
9-
import software.amazon.awscdk.services.eks.v2.alpha.AccessEntryType;
10-
import software.amazon.awscdk.services.eks.v2.alpha.AccessPolicy;
11-
import software.amazon.awscdk.services.eks.v2.alpha.IAccessPolicy;
12-
import software.amazon.awscdk.services.eks.v2.alpha.AccessPolicyNameOptions;
13-
import software.amazon.awscdk.services.eks.v2.alpha.AccessScopeType;
14-
import software.amazon.awscdk.services.eks.v2.alpha.Addon;
6+
import software.amazon.awscdk.services.eks_v2.Cluster;
7+
import software.amazon.awscdk.services.eks_v2.KubernetesVersion;
8+
import software.amazon.awscdk.services.eks_v2.AccessEntry;
9+
import software.amazon.awscdk.services.eks_v2.AccessEntryType;
10+
import software.amazon.awscdk.services.eks_v2.AccessPolicy;
11+
import software.amazon.awscdk.services.eks_v2.IAccessPolicy;
12+
import software.amazon.awscdk.services.eks_v2.AccessPolicyNameOptions;
13+
import software.amazon.awscdk.services.eks_v2.AccessScopeType;
14+
import software.amazon.awscdk.services.eks_v2.Addon;
1515
import software.amazon.awscdk.services.iam.Effect;
1616
import software.amazon.awscdk.services.iam.ManagedPolicy;
1717
import software.amazon.awscdk.services.iam.PolicyStatement;

infra/cdk/src/main/java/sample/com/constructs/ThreadAnalysis.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import software.amazon.awscdk.Duration;
44
import software.amazon.awscdk.RemovalPolicy;
55
import software.amazon.awscdk.services.ec2.*;
6-
import software.amazon.awscdk.services.eks.v2.alpha.AccessEntry;
7-
import software.amazon.awscdk.services.eks.v2.alpha.AccessEntryType;
8-
import software.amazon.awscdk.services.eks.v2.alpha.AccessPolicy;
9-
import software.amazon.awscdk.services.eks.v2.alpha.AccessPolicyNameOptions;
10-
import software.amazon.awscdk.services.eks.v2.alpha.AccessScopeType;
11-
import software.amazon.awscdk.services.eks.v2.alpha.Cluster;
12-
import software.amazon.awscdk.services.eks.v2.alpha.IAccessPolicy;
6+
import software.amazon.awscdk.services.eks_v2.AccessEntry;
7+
import software.amazon.awscdk.services.eks_v2.AccessEntryType;
8+
import software.amazon.awscdk.services.eks_v2.AccessPolicy;
9+
import software.amazon.awscdk.services.eks_v2.AccessPolicyNameOptions;
10+
import software.amazon.awscdk.services.eks_v2.AccessScopeType;
11+
import software.amazon.awscdk.services.eks_v2.Cluster;
12+
import software.amazon.awscdk.services.eks_v2.IAccessPolicy;
1313
import software.amazon.awscdk.services.iam.*;
1414
import software.amazon.awscdk.services.lambda.Code;
1515
import software.amazon.awscdk.services.lambda.Function;

infra/cdk/src/main/resources/iam-policy.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"prod-xdkflymybwmvi",
1818
"prod-mxcfnwvpd6kb4",
1919
"prod-jhuafngbly644",
20-
"prod-4pmewlybdftbs",
20+
"prod-5ukwuglpt66kg",
2121
"prod-ffvjxvh4ltq64"
2222
]
2323
}

0 commit comments

Comments
 (0)