cdk-insights 1.5.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 (28) 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 +41 -0
  6. package/dist/analysis/templateLevel/checks/schemaDrift/checkSchemaDrift.test.d.ts +1 -0
  7. package/dist/analysis/templateLevel/types.d.ts +2 -1
  8. package/dist/aspects/CdkInsightsAspect.js +23 -23
  9. package/dist/cli/commands/setup.d.ts +12 -0
  10. package/dist/cli/commands/setup.test.d.ts +1 -0
  11. package/dist/cli/commands/setupCdkNag.d.ts +1 -2
  12. package/dist/constants/cdkSchemaChanges.d.ts +64 -0
  13. package/dist/entry.js +158 -186
  14. package/dist/functions/factories/awsServices.d.ts +1 -0
  15. package/dist/helpers/detectCdkVersion/detectCdkVersion.d.ts +2 -0
  16. package/dist/helpers/issueSuppressions/issueSuppressions.d.ts +20 -0
  17. package/dist/helpers/issueSuppressions/issueSuppressions.test.d.ts +1 -0
  18. package/dist/helpers/loadAcknowledgementsForTemplate/loadAcknowledgementsForTemplate.d.ts +10 -0
  19. package/dist/helpers/loadAcknowledgementsForTemplate/loadAcknowledgementsForTemplate.test.d.ts +1 -0
  20. package/dist/helpers/loadProjectSuppressions/loadProjectSuppressions.d.ts +10 -0
  21. package/dist/helpers/loadProjectSuppressions/loadProjectSuppressions.test.d.ts +1 -0
  22. package/dist/helpers/synthesizeCdkStacks/synthesizeCdkStacks.d.ts +2 -1
  23. package/dist/index.d.ts +2 -1
  24. package/dist/index.js +117 -117
  25. package/dist/types/analysis.types.d.ts +20 -0
  26. package/dist/validation/CdkInsightsPolicyValidationPlugin.d.ts +87 -0
  27. package/dist/validation/CdkInsightsPolicyValidationPlugin.test.d.ts +1 -0
  28. 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;
@@ -0,0 +1,41 @@
1
+ import { type SchemaChange } from '../../../../constants/cdkSchemaChanges';
2
+ import type { AnalysisResults, CloudFormationStack, CreateFindingFunction } from '../../../../types/analysis.types';
3
+ import type { RuleRegistry } from '../../../../types/rules.types';
4
+ type RuleRegistryLike = RuleRegistry;
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';
16
+ /**
17
+ * Inner function exposed for unit tests so cdkVersion and the registries can be
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.
23
+ */
24
+ export declare const findSchemaDriftFindings: (template: CloudFormationStack, createFinding: CreateFindingFunction, cdkVersion: string | null, kind?: SchemaDriftKind, schemaChanges?: SchemaChangeRegistry, rules?: RuleRegistryLike) => AnalysisResults;
25
+ /**
26
+ * Template-level check: surface known L1 schema-drift events that may have
27
+ * silently invalidated rule coverage in the user's CDK version (removed or
28
+ * renamed properties on covered resource types).
29
+ *
30
+ * Silent fallback when the user's aws-cdk-lib version cannot be resolved.
31
+ */
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;
41
+ export {};
@@ -11,8 +11,9 @@ import type { CloudFormationStack, CreateFindingFunction, AnalysisResults, Sever
11
11
  * TL-LIMIT-xxx = Service limit checks
12
12
  * TL-XRES-xxx = Cross-resource anti-pattern checks
13
13
  * TL-POL-xxx = Policy analysis checks
14
+ * TL-DRIFT-xxx = CDK L1 schema-drift checks
14
15
  */
15
- export type TemplateLevelCategory = 'serviceLimits' | 'crossResourceAntiPatterns' | 'policyAnalysis';
16
+ export type TemplateLevelCategory = 'serviceLimits' | 'crossResourceAntiPatterns' | 'policyAnalysis' | 'schemaDrift';
16
17
  /**
17
18
  * A template-level check function.
18
19
  * Receives the FULL CloudFormation stack (all resources).