cdk-insights 1.6.0 → 1.7.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.
Files changed (24) hide show
  1. package/README.md +43 -5
  2. package/dist/analysis/static/awsServices/ECS/logging/ecsServiceConnectAccessLogs.d.ts +2 -0
  3. package/dist/analysis/static/awsServices/ECS/logging/ecsServiceConnectAccessLogs.test.d.ts +1 -0
  4. package/dist/analysis/static/staticAnalysis.d.ts +1 -1
  5. package/dist/analysis/templateLevel/checks/schemaDrift/checkSchemaDrift.d.ts +26 -3
  6. package/dist/cli/commands/setup.d.ts +12 -0
  7. package/dist/cli/commands/setup.test.d.ts +1 -0
  8. package/dist/cli/commands/setupCdkNag.d.ts +1 -2
  9. package/dist/constants/cdkSchemaChanges.d.ts +14 -3
  10. package/dist/entry.js +158 -186
  11. package/dist/functions/factories/awsServices.d.ts +1 -0
  12. package/dist/helpers/issueSuppressions/issueSuppressions.d.ts +20 -0
  13. package/dist/helpers/issueSuppressions/issueSuppressions.test.d.ts +1 -0
  14. package/dist/helpers/loadAcknowledgementsForTemplate/loadAcknowledgementsForTemplate.d.ts +10 -0
  15. package/dist/helpers/loadAcknowledgementsForTemplate/loadAcknowledgementsForTemplate.test.d.ts +1 -0
  16. package/dist/helpers/loadProjectSuppressions/loadProjectSuppressions.d.ts +10 -0
  17. package/dist/helpers/loadProjectSuppressions/loadProjectSuppressions.test.d.ts +1 -0
  18. package/dist/helpers/synthesizeCdkStacks/synthesizeCdkStacks.d.ts +2 -1
  19. package/dist/index.d.ts +2 -1
  20. package/dist/index.js +108 -108
  21. package/dist/types/analysis.types.d.ts +20 -0
  22. package/dist/validation/CdkInsightsPolicyValidationPlugin.d.ts +87 -0
  23. package/dist/validation/CdkInsightsPolicyValidationPlugin.test.d.ts +1 -0
  24. package/package.json +1 -1
package/README.md CHANGED
@@ -146,21 +146,59 @@ Create a `.cdk-insights.json` in your project root, or run:
146
146
  npx cdk-insights config setup
147
147
  ```
148
148
 
149
- ### CDK Aspect (Enhanced Analysis)
149
+ ### In-App Integration
150
150
 
151
- For precise file/line metadata and richer context, add the aspect in your CDK app:
151
+ CDK Insights ships two integration points; they are complementary, and most projects want both. Install them interactively with:
152
+
153
+ ```bash
154
+ npx cdk-insights setup
155
+ ```
156
+
157
+ | Integration | When to use | What you get |
158
+ |-------------|-------------|--------------|
159
+ | **Aspect** | Always — pairs with `cdk-insights scan` | Precise file/line metadata, source-location tracking, richer findings |
160
+ | **Validations plugin** (`aws-cdk-lib` ≥ 2.251.0) | When you want CI to fail on synth | `cdk synth` blocks on findings; native CDK plugin surface; one less CI step |
161
+
162
+ #### Aspect — for precise findings
152
163
 
153
164
  ```ts
154
165
  import { App, Aspects } from 'aws-cdk-lib';
155
- import { CdkInsightsAspect } from 'cdk-insights';
166
+ import { createCdkInsightsAspect } from 'cdk-insights';
156
167
 
157
168
  const app = new App();
158
- Aspects.of(app).add(new CdkInsightsAspect());
169
+ Aspects.of(app).add(createCdkInsightsAspect());
159
170
  // define stacks...
160
171
  app.synth();
161
172
  ```
162
173
 
163
- Run synth with `CDK_DEBUG=true` so CDK records stack traces for each construct. On `aws-cdk-lib` ≥ 2.252.0, findings on deferred or post-construction property assignments (lifecycle rules, env vars, role policies, `Lazy.string`/`Lazy.any` values) now point at the property setter line — not the construct constructor — automatically. Older CDKs continue to work; you'll just get construct-level attribution.
174
+ Run synth with `CDK_DEBUG=true` so CDK records stack traces for each construct. On `aws-cdk-lib` ≥ 2.252.0, findings on deferred or post-construction property assignments (lifecycle rules, env vars, role policies, `Lazy.string`/`Lazy.any` values) point at the property setter line — not the construct constructor — automatically. Older CDKs continue to work; you'll just get construct-level attribution.
175
+
176
+ #### Validations plugin — for synth-time enforcement
177
+
178
+ Requires `aws-cdk-lib` ≥ 2.251.0:
179
+
180
+ ```ts
181
+ import { App, Validations } from 'aws-cdk-lib';
182
+ import { CdkInsightsPolicyValidationPlugin } from 'cdk-insights';
183
+
184
+ const app = new App();
185
+ Validations.of(app).addPlugins(new CdkInsightsPolicyValidationPlugin());
186
+ // define stacks...
187
+ app.synth();
188
+ ```
189
+
190
+ `cdk synth` will fail with a CDK Insights report if any rules trigger. Pass `selectedServices`, `minimumSeverity`, or `customRules` to scope what counts as a synth-time block:
191
+
192
+ ```ts
193
+ new CdkInsightsPolicyValidationPlugin({
194
+ selectedServices: ['IAM', 'S3'],
195
+ minimumSeverity: 'HIGH',
196
+ });
197
+ ```
198
+
199
+ The plugin sees synthesized templates only — no construct tree. Pair it with the aspect (above) when you also want source-location capture in the `cdk-insights scan` report.
200
+
201
+ The plugin honours the same suppressions as `cdk-insights scan` — `.cdk-insights.json` (`ignoreRules` / `ignorePaths`) and inline `Validations.of(scope).acknowledge(...)` entries are both respected, so a finding suppressed in the CLI is also suppressed at synth time. Pass `ignoreProjectConfig: true` or `ignoreInlineAcknowledgements: true` to opt out of either source.
164
202
 
165
203
  ### Suppressing Findings
166
204
 
@@ -0,0 +1,2 @@
1
+ import type { AnalysisResults, CloudFormationStack, CreateFindingFunction } from '../../../../../types/analysis.types';
2
+ export declare const checkECSServiceConnectAccessLogs: (template: CloudFormationStack, createFinding: CreateFindingFunction) => AnalysisResults;
@@ -1,6 +1,6 @@
1
+ import type { CustomRuleDefinition } from '../../rules/customRules.types';
1
2
  import type { AnalysisResults, CloudFormationStack, CreateFindingFunction, ServiceName, Severity } from '../../types/analysis.types';
2
3
  import type { ConstructMetadata } from './solutionConstructs/loadConstructMetadata';
3
- import type { CustomRuleDefinition } from '../../rules/customRules.types';
4
4
  export type AnalysisStatistics = {
5
5
  totalResources: number;
6
6
  analyzedResources: number;
@@ -3,16 +3,39 @@ import type { AnalysisResults, CloudFormationStack, CreateFindingFunction } from
3
3
  import type { RuleRegistry } from '../../../../types/rules.types';
4
4
  type RuleRegistryLike = RuleRegistry;
5
5
  type SchemaChangeRegistry = Record<string, SchemaChange[]>;
6
+ /**
7
+ * Two finding kinds share the same registry and traversal:
8
+ * - `regression`: a previously-readable property was removed or renamed,
9
+ * so an existing rule may have silently lost coverage.
10
+ * - `coverage-gap`: a new property was added on a resource type we already
11
+ * have rules for, so a maintainer should *consider* whether a rule should
12
+ * evaluate it. Lower urgency, lower noise — only fires for resource types
13
+ * already on our radar.
14
+ */
15
+ export type SchemaDriftKind = 'regression' | 'coverage-gap';
6
16
  /**
7
17
  * Inner function exposed for unit tests so cdkVersion and the registries can be
8
- * injected directly. Production callers should use `checkSchemaDrift`.
18
+ * injected directly. Production callers should use the named wrapper for the
19
+ * specific finding kind they want to surface.
20
+ *
21
+ * @param kind - Which finding category to emit. Defaults to `regression` for
22
+ * backwards compatibility with the original single-kind behaviour.
9
23
  */
10
- export declare const findSchemaDriftFindings: (template: CloudFormationStack, createFinding: CreateFindingFunction, cdkVersion: string | null, schemaChanges?: SchemaChangeRegistry, rules?: RuleRegistryLike) => AnalysisResults;
24
+ export declare const findSchemaDriftFindings: (template: CloudFormationStack, createFinding: CreateFindingFunction, cdkVersion: string | null, kind?: SchemaDriftKind, schemaChanges?: SchemaChangeRegistry, rules?: RuleRegistryLike) => AnalysisResults;
11
25
  /**
12
26
  * Template-level check: surface known L1 schema-drift events that may have
13
- * affected rule coverage in the user's CDK version.
27
+ * silently invalidated rule coverage in the user's CDK version (removed or
28
+ * renamed properties on covered resource types).
14
29
  *
15
30
  * Silent fallback when the user's aws-cdk-lib version cannot be resolved.
16
31
  */
17
32
  export declare const checkSchemaDrift: (template: CloudFormationStack, createFinding: CreateFindingFunction) => AnalysisResults;
33
+ /**
34
+ * Template-level check: surface newly-added L1 properties on resource types
35
+ * already covered by cdk-insights rules. Hint to maintainers/users that a new
36
+ * rule may be worth opening — not a regression.
37
+ *
38
+ * Silent fallback when the user's aws-cdk-lib version cannot be resolved.
39
+ */
40
+ export declare const checkSchemaDriftCoverageGaps: (template: CloudFormationStack, createFinding: CreateFindingFunction) => AnalysisResults;
18
41
  export {};
@@ -0,0 +1,12 @@
1
+ import type { CommandModule } from 'yargs';
2
+ type IntegrationChoice = 'aspect-and-plugin' | 'plugin-only' | 'aspect-only' | 'cdk-nag-only' | 'skip';
3
+ interface SnippetParts {
4
+ imports: string[];
5
+ body: string[];
6
+ }
7
+ export declare const buildSnippet: (choice: IntegrationChoice, isJavaScript: boolean) => SnippetParts;
8
+ export declare const alreadyInstalled: (source: string, parts: SnippetParts) => boolean;
9
+ export declare const insertSnippet: (source: string, parts: SnippetParts) => string | null;
10
+ export declare const setupCommand: CommandModule;
11
+ export declare const setupCdkNagCommand: CommandModule;
12
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,2 +1 @@
1
- import type { CommandModule } from 'yargs';
2
- export declare const setupCdkNagCommand: CommandModule;
1
+ export { setupCdkNagCommand } from './setup';
@@ -27,6 +27,15 @@ export type SchemaChange = {
27
27
  from: string;
28
28
  to: string;
29
29
  }[];
30
+ /**
31
+ * Properties newly added in this release. Treated as a coverage *hint*, not
32
+ * a regression: the `coverage-gap` finding kind only fires when the
33
+ * `resourceType` is already targeted by at least one existing rule, so users
34
+ * are not nagged about resources they don't analyse. Use this to capture
35
+ * additions that look security-, cost-, reliability-, or compliance-relevant
36
+ * and may warrant a new rule. Exhaustive coverage is explicitly not the goal.
37
+ */
38
+ addedProperties?: string[];
30
39
  /**
31
40
  * Names of GetAtt return attributes that were removed. Recorded for
32
41
  * completeness, but does not drive findings on its own — rules don't read
@@ -46,8 +55,10 @@ export type SchemaChange = {
46
55
  /**
47
56
  * Map of aws-cdk-lib version → schema changes introduced in that release.
48
57
  *
49
- * Adding an entry: include the release tag link, only populate `removedProperties`
50
- * / `renamedProperties` if the change touches CFN-level properties (those drive
51
- * findings). Attributes/types are recorded for traceability but stay silent.
58
+ * Adding an entry: include the release tag link. Populate `removedProperties` /
59
+ * `renamedProperties` for regressions that may have invalidated rule coverage,
60
+ * and `addedProperties` for newly-introduced properties that look worth a new
61
+ * rule (security, cost, reliability, compliance). Attributes/types are
62
+ * recorded for traceability but stay silent.
52
63
  */
53
64
  export declare const CDK_L1_SCHEMA_CHANGES: Record<string, SchemaChange[]>;