cdk-insights 1.16.1 → 1.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -172,6 +172,34 @@ Aspects.of(app).add(createCdkInsightsAspect());
172
172
  app.synth();
173
173
  ```
174
174
 
175
+ The aspect runs `cdk-nag`'s `AwsSolutionsChecks` rule pack alongside cdk-insights' own rules. As of 1.17.0, those findings are emitted as **non-blocking Info annotations** (`cdk-insights::nagFinding::*`) instead of cdk-nag's default Error/Warning annotations — the Validations Plugin (below) remains the actual deploy gate, configured per severity.
176
+
177
+ ##### Auto-suppress CDK / AWS boilerplate
178
+
179
+ cdk-nag's `AwsSolutionsChecks` rule pack flags two patterns that are universally noisy for CDK consumers — they're either AWS-recommended defaults or stale rule heuristics:
180
+
181
+ - **`AwsSolutions-IAM4`** flags any AWS-managed policy attached to a role, including the standard Lambda execution policies CDK auto-attaches based on event sources (`AWSLambdaBasicExecutionRole`, `AWSLambdaVPCAccessExecutionRole`, `AWSLambdaSQSQueueExecutionRole`, `AWSLambdaDynamoDBExecutionRole`, `AWSLambdaKinesisExecutionRole`). Each is narrowly scoped to a single AWS service — replacing them with customer-managed copies is busywork with no security gain.
182
+ - **`AwsSolutions-L1`** asserts that Lambda runtimes match cdk-nag's known "latest" list, which lags actual AWS LTS releases. Node 20.x / 22.x, Python 3.11–3.13, Java 17/21, .NET 8 are all current AWS LTS at time of writing but get flagged depending on how recent your `aws-cdk-lib` version is.
183
+
184
+ Pass `cdkBoilerplateSuppressions: true` to short-circuit both:
185
+
186
+ ```ts
187
+ Aspects.of(app).add(createCdkInsightsAspect({
188
+ cdkBoilerplateSuppressions: true,
189
+ }));
190
+ ```
191
+
192
+ This attaches `NagSuppressions` (with named justifications and `appliesTo` filters) before cdk-nag evaluates each construct, so the matching findings are never emitted. Anything outside the boilerplate set continues to surface — if a role has `AWSLambdaBasicExecutionRole` *and* a custom managed policy, only the boilerplate one is suppressed; the custom policy still produces a finding.
193
+
194
+ | Rule | What's suppressed | What still fires |
195
+ |---|---|---|
196
+ | `AwsSolutions-IAM4` | The 5 AWS-managed Lambda execution policy ARNs above | Any other managed policy attached to the same role |
197
+ | `AwsSolutions-L1` | Node 18/20/22, Python 3.11/3.12/3.13, Java 17/21, .NET 8 | Anything outside the LTS allowlist (older runtimes, unsupported ones, custom families) |
198
+
199
+ To extend with project-specific suppressions, call `NagSuppressions.addResourceSuppressions(...)` from `cdk-nag` after constructing your stacks. Project decisions like "MFA is opt-in by product policy" belong in the consumer codebase, with a written justification.
200
+
201
+ Default is `false` — opt-in is conservative and additive.
202
+
175
203
  For accurate `file:line` source attribution, CDK needs to record per-construct stack traces during synth. Three ways to enable this, easiest first:
176
204
 
177
205
  - **`npx cdk-insights setup`** writes `"@aws-cdk/core:stackTrace": true` into your `cdk.json` `context` block — durable across every `cdk synth` invocation, no env-var dance. Recommended.
@@ -5,6 +5,13 @@ import type { IConstruct } from 'constructs';
5
5
  declare const CDK_INSIGHTS_METADATA_VERSION = "2.2.0";
6
6
  /** Prefix used to identify cdk-insights annotations in CloudFormation metadata */
7
7
  declare const CDK_INSIGHTS_ANNOTATION_PREFIX = "cdk-insights::";
8
+ /**
9
+ * Sub-prefix for nag findings captured by `CdkInsightsNagDelegate` and emitted
10
+ * as Info annotations. Format: `cdk-insights::nagFinding::<json>`. The scan-side
11
+ * parser branches on this so nag findings flow through the same findings stream
12
+ * as cdk-insights' native rules instead of polluting CDK's error/warning channel.
13
+ */
14
+ declare const CDK_INSIGHTS_NAG_FINDING_PREFIX = "cdk-insights::nagFinding::";
8
15
  /** Confidence level for source location detection */
9
16
  export type SourceLocationConfidence = 'high' | 'medium' | 'low';
10
17
  /** Source location information for a construct */
@@ -147,6 +154,39 @@ export interface CdkInsightsAspectOptions {
147
154
  * around the construct definition for quick reference.
148
155
  */
149
156
  includeCodeSnippets?: boolean;
157
+ /**
158
+ * Auto-suppress cdk-nag findings for well-known CDK / AWS boilerplate
159
+ * patterns (default: false). When `true`, the aspect attaches
160
+ * `NagSuppressions` to matching constructs **before** cdk-nag evaluates
161
+ * its rules, so the suppressed findings disappear from scan output
162
+ * entirely. Each suppression carries a named justification.
163
+ *
164
+ * Currently covers two universally-noisy rules:
165
+ *
166
+ * - **`AwsSolutions-IAM4`** for the AWS-managed Lambda execution
167
+ * policies CDK auto-attaches based on event sources
168
+ * (`AWSLambdaBasicExecutionRole`, `AWSLambdaVPCAccessExecutionRole`,
169
+ * `AWSLambdaSQSQueueExecutionRole`, `AWSLambdaDynamoDBExecutionRole`,
170
+ * `AWSLambdaKinesisExecutionRole`). Each is narrowly scoped to a
171
+ * single AWS service; replacing them with customer-managed copies is
172
+ * busywork with no security gain. The suppression uses `appliesTo`
173
+ * so any *other* managed policy attached to the same role still
174
+ * surfaces a finding.
175
+ *
176
+ * - **`AwsSolutions-L1`** for current AWS Lambda LTS runtimes
177
+ * (Node 18/20/22, Python 3.11/3.12/3.13, Java 17/21, .NET 8).
178
+ * cdk-nag's "latest runtime" check is heuristic and lags new LTS
179
+ * releases; this allowlist updates with cdk-insights releases.
180
+ *
181
+ * Anything not in the lists above continues to surface normally — opt-in
182
+ * is conservative and additive.
183
+ *
184
+ * Recommended for any project that uses cdk-insights' aspect. To
185
+ * extend with project-specific suppressions, call
186
+ * `NagSuppressions.addResourceSuppressions(...)` from `cdk-nag` after
187
+ * constructing your stacks.
188
+ */
189
+ cdkBoilerplateSuppressions?: boolean;
150
190
  }
151
191
  /**
152
192
  * Helper function to check if CDK stack traces are enabled.
@@ -168,6 +208,38 @@ export declare const createCdkInsightsLogger: (options?: CdkInsightsLoggerOption
168
208
  * Useful for development and debugging.
169
209
  */
170
210
  export declare const createExtremelyHelpfulConsoleLogger: (options?: CdkInsightsLoggerOptions) => INagLogger;
211
+ /**
212
+ * Captures a non-compliant nag finding as a cdk-insights Info annotation.
213
+ *
214
+ * The on-the-wire shape is intentionally small and stable — the scan-side
215
+ * parser depends on it. Severity is mapped from cdk-nag's binary
216
+ * `NagMessageLevel` (ERROR/WARN) into cdk-insights' richer Severity enum:
217
+ *
218
+ * - `NagMessageLevel.ERROR` → `HIGH` (rule pack author rated it security-critical)
219
+ * - `NagMessageLevel.WARN` → `MEDIUM` (advisory)
220
+ *
221
+ * `HIGH` is the conservative choice for ERROR — it preserves today's behaviour
222
+ * when the Validation Plugin is set to `minimumSeverity: "CRITICAL"` (nothing
223
+ * blocks deploy from nag), while letting users tighten to `HIGH` later to
224
+ * promote ERROR-rated nag findings into deploy gates.
225
+ */
226
+ interface CdkInsightsNagFinding {
227
+ source: 'cdk-nag';
228
+ ruleId: string;
229
+ ruleOriginalName: string;
230
+ ruleInfo: string;
231
+ ruleExplanation: string;
232
+ /** Mapped from NagMessageLevel: ERROR→HIGH, WARN→MEDIUM. */
233
+ severity: 'HIGH' | 'MEDIUM';
234
+ /** Original cdk-nag level — kept so consumers can recover the source signal. */
235
+ level: 'Error' | 'Warning';
236
+ /** Sub-finding identifier from rules that emit multiple findings per resource. */
237
+ findingId?: string;
238
+ /** Construct path of the resource that failed the rule. */
239
+ resourcePath: string;
240
+ /** CloudFormation logical ID of the resource. */
241
+ logicalId: string;
242
+ }
171
243
  /**
172
244
  * Creates a CDK Insights aspect using functional composition.
173
245
  * This is the recommended approach for new projects.
@@ -230,7 +302,8 @@ export declare class CdkInsightsAspect extends NagPack implements IAspect {
230
302
  visit(node: IConstruct): void;
231
303
  }
232
304
  /** Re-export constants for external use */
233
- export { CDK_INSIGHTS_METADATA_VERSION, CDK_INSIGHTS_ANNOTATION_PREFIX };
305
+ export { CDK_INSIGHTS_METADATA_VERSION, CDK_INSIGHTS_ANNOTATION_PREFIX, CDK_INSIGHTS_NAG_FINDING_PREFIX, };
306
+ export type { CdkInsightsNagFinding };
234
307
  /**
235
308
  * Clears all internal caches. Useful for testing or when processing
236
309
  * multiple independent CDK apps in the same process.