cdk-real-drift 0.2.66 → 0.2.68
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 +18 -2
- package/dist/cli.js +98 -20
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -484,7 +484,12 @@ ignore:
|
|
|
484
484
|
`?` is **unbounded within that bracket** (the brackets delimit the key, so a `.`
|
|
485
485
|
between them is data): `Alb.LoadBalancerAttributes[*]` and
|
|
486
486
|
`Alb.LoadBalancerAttributes[routing.*]` both match the dotted key
|
|
487
|
-
`[routing.http2.enabled]`.
|
|
487
|
+
`[routing.http2.enabled]`. To match a **literal** `*` / `?` in a `path`
|
|
488
|
+
(e.g. an API Gateway `MethodSettings[*]` key from `HttpMethod: '*'`, or an S3
|
|
489
|
+
lifecycle `Id` like `clean*tmp`), backslash-escape it — `\*` / `\?` (and `\\`
|
|
490
|
+
for a literal backslash). The `ignore` verb writes such paths pre-escaped, so
|
|
491
|
+
a machine-written rule matches only the finding it came from; hand-copied rules
|
|
492
|
+
need the escape added. On **stack / account / region**, `*` / `?` are unbounded
|
|
488
493
|
(those names carry no `.`). The three scope axes are exactly the
|
|
489
494
|
baseline file's identity axes; each is **omitted to leave that axis unscoped**
|
|
490
495
|
(match-all) — a present-but-empty `""` is rejected (it would match nothing),
|
|
@@ -574,8 +579,19 @@ element so a consumer sees which stacks ran: it carries `"error": "<reason>"` al
|
|
|
574
579
|
`"drifted": 0` and an empty `"findings": []`. (`error` is absent on a
|
|
575
580
|
successfully-checked stack.)
|
|
576
581
|
|
|
582
|
+
A **stack deleted out of band** — its committed baseline proves it was once deployed but
|
|
583
|
+
it is now gone from CloudFormation — is the strongest drift, so it carries
|
|
584
|
+
`"drifted": 1` and `"stackDeleted": true` (never `"error"`, which is reserved for a
|
|
585
|
+
pre-check failure). A consumer summing `drifted` across stacks therefore sees the
|
|
586
|
+
deletion instead of a misleading zero.
|
|
587
|
+
|
|
588
|
+
If the whole invocation fails before any stack is reached (bad config, an
|
|
589
|
+
un-synthesizable app, or a zero-stack app), stdout is still a valid empty array
|
|
590
|
+
`[]` (exit code non-zero, the reason on stderr) — never empty bytes.
|
|
591
|
+
|
|
577
592
|
Each stack element is `{ "stack": "<name> (<region>)", "drifted": <n>, "findings": [...] }`
|
|
578
|
-
(`error` added only on failure
|
|
593
|
+
(`error` added only on a pre-check failure; `stackDeleted: true` only on a deleted
|
|
594
|
+
stack). Each **finding** has a stable shape:
|
|
579
595
|
|
|
580
596
|
- Always present: `tier`, `logicalId`, `resourceType`, `path`.
|
|
581
597
|
- Usually present: `desired`, `actual`, `note`, `physicalId`, `constructPath` (any of
|
package/dist/cli.js
CHANGED
|
@@ -370,16 +370,56 @@ function parseCommonArgs(args, verb) {
|
|
|
370
370
|
|
|
371
371
|
//#endregion
|
|
372
372
|
//#region src/commands/glob-match.ts
|
|
373
|
-
/** True when `s` contains
|
|
373
|
+
/** True when `s` contains an UNESCAPED glob metachar (`*` or `?`). A `\*` / `\?` is a
|
|
374
|
+
* literal, not a wildcard, so a pattern made only of escaped metachars is NOT a glob. */
|
|
374
375
|
function isGlob(s) {
|
|
375
|
-
|
|
376
|
+
for (let i = 0; i < s.length; i++) {
|
|
377
|
+
if (s[i] === "\\") {
|
|
378
|
+
i++;
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
if (s[i] === "*" || s[i] === "?") return true;
|
|
382
|
+
}
|
|
383
|
+
return false;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Collapse runs of consecutive UNESCAPED `*` to a single `*` (see `globToRegExp` for the
|
|
387
|
+
* ReDoS rationale), leaving `\`-escaped sequences untouched. An escaped `\*` must NOT be
|
|
388
|
+
* merged into (or collapsed with) an adjacent real `*` — `\**` is a literal `*` followed
|
|
389
|
+
* by a wildcard, which must survive as two distinct tokens.
|
|
390
|
+
*/
|
|
391
|
+
function collapseStars(pattern) {
|
|
392
|
+
let out = "";
|
|
393
|
+
let i = 0;
|
|
394
|
+
while (i < pattern.length) {
|
|
395
|
+
const ch = pattern[i];
|
|
396
|
+
if (ch === "\\") {
|
|
397
|
+
out += pattern.slice(i, i + 2);
|
|
398
|
+
i += pattern[i + 1] === void 0 ? 1 : 2;
|
|
399
|
+
} else if (ch === "*") {
|
|
400
|
+
out += "*";
|
|
401
|
+
while (pattern[i] === "*") i++;
|
|
402
|
+
} else {
|
|
403
|
+
out += ch;
|
|
404
|
+
i++;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
return out;
|
|
376
408
|
}
|
|
377
409
|
/** Convert a glob pattern to an anchored RegExp (other metachars escaped to literals). */
|
|
378
410
|
function globToRegExp(pattern) {
|
|
379
411
|
let out = "^";
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
412
|
+
const collapsed = collapseStars(pattern);
|
|
413
|
+
for (let i = 0; i < collapsed.length; i++) {
|
|
414
|
+
const ch = collapsed[i];
|
|
415
|
+
if (ch === "\\") {
|
|
416
|
+
const next = collapsed[i + 1] ?? "\\";
|
|
417
|
+
out += next.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
418
|
+
if (collapsed[i + 1] !== void 0) i++;
|
|
419
|
+
} else if (ch === "*") out += ".*";
|
|
420
|
+
else if (ch === "?") out += ".";
|
|
421
|
+
else out += ch.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
422
|
+
}
|
|
383
423
|
out += "$";
|
|
384
424
|
return new RegExp(out);
|
|
385
425
|
}
|
|
@@ -416,12 +456,20 @@ function matchesGlob(pattern, name) {
|
|
|
416
456
|
function matchesPathGlob(pattern, target) {
|
|
417
457
|
let out = "^";
|
|
418
458
|
let inBracket = false;
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
if (ch === "
|
|
423
|
-
|
|
424
|
-
|
|
459
|
+
const collapsed = collapseStars(pattern);
|
|
460
|
+
for (let i = 0; i < collapsed.length; i++) {
|
|
461
|
+
const ch = collapsed[i];
|
|
462
|
+
if (ch === "\\") {
|
|
463
|
+
const next = collapsed[i + 1] ?? "\\";
|
|
464
|
+
out += next.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
465
|
+
if (collapsed[i + 1] !== void 0) i++;
|
|
466
|
+
} else if (ch === "*") out += inBracket ? "[^\\]]*" : "[^.[/]*";
|
|
467
|
+
else if (ch === "?") out += inBracket ? "[^\\]]" : "[^.[/]";
|
|
468
|
+
else {
|
|
469
|
+
if (ch === "[") inBracket = true;
|
|
470
|
+
else if (ch === "]") inBracket = false;
|
|
471
|
+
out += ch.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
472
|
+
}
|
|
425
473
|
}
|
|
426
474
|
out += "$";
|
|
427
475
|
return new RegExp(out).test(target);
|
|
@@ -546,12 +594,23 @@ function validateIgnoreEntry(entry, index) {
|
|
|
546
594
|
*/
|
|
547
595
|
function ignoreRuleFor(finding, stackName = "", accountId = "", region = "") {
|
|
548
596
|
const id = finding.constructPath && finding.tier !== "added" ? withinStackPath(finding.constructPath, stackName) : finding.logicalId;
|
|
549
|
-
const rule = { path: finding.path ? `${id}.${finding.path}` : id };
|
|
597
|
+
const rule = { path: escapeGlobLiterals(finding.path ? `${id}.${finding.path}` : id) };
|
|
550
598
|
if (stackName) rule.stack = stackName;
|
|
551
599
|
if (accountId) rule.account = accountId;
|
|
552
600
|
if (region) rule.region = region;
|
|
553
601
|
return rule;
|
|
554
602
|
}
|
|
603
|
+
/**
|
|
604
|
+
* Backslash-escape the glob metacharacters (`\`, `*`, `?`) in a literal path so the glob
|
|
605
|
+
* matcher treats them as literals, not wildcards. The inverse of the `\`-escape grammar in
|
|
606
|
+
* glob-match.ts. `\` is escaped FIRST so the `*` / `?` escapes we add are not re-escaped
|
|
607
|
+
* (otherwise `\*` would become `\\*` = a literal `\` + a wildcard). Structural separators
|
|
608
|
+
* (`.` `[` `]` `/`) are intentionally left alone — they are the rule's segment grammar, not
|
|
609
|
+
* data. Exported for tests.
|
|
610
|
+
*/
|
|
611
|
+
function escapeGlobLiterals(literal) {
|
|
612
|
+
return literal.replace(/\\/g, "\\\\").replace(/[*?]/g, "\\$&");
|
|
613
|
+
}
|
|
555
614
|
/** Canonical identity of a rule (path + the three optional scopes), for dedupe. */
|
|
556
615
|
function ruleKey(r) {
|
|
557
616
|
return JSON.stringify([
|
|
@@ -744,6 +803,9 @@ function planIoMessage(msg) {
|
|
|
744
803
|
return { action: "drop" };
|
|
745
804
|
}
|
|
746
805
|
var QuietIoHost = class extends NonInteractiveIoHost {
|
|
806
|
+
constructor() {
|
|
807
|
+
super({ isCI: false });
|
|
808
|
+
}
|
|
747
809
|
async notify(msg) {
|
|
748
810
|
const plan = planIoMessage(msg);
|
|
749
811
|
if (plan.action === "drop") return;
|
|
@@ -2519,7 +2581,8 @@ const VALUE_INDEPENDENT_DEFAULT_TOPLEVEL_PATHS = {
|
|
|
2519
2581
|
"AWS::AppSync::ApiKey": new Set(["Expires"]),
|
|
2520
2582
|
"AWS::AppConfig::ExtensionAssociation": new Set(["ExtensionVersionNumber"]),
|
|
2521
2583
|
"AWS::StepFunctions::StateMachineVersion": new Set(["StateMachineRevisionId"]),
|
|
2522
|
-
"AWS::StepFunctions::StateMachineAlias": new Set(["StateMachineArn"])
|
|
2584
|
+
"AWS::StepFunctions::StateMachineAlias": new Set(["StateMachineArn"]),
|
|
2585
|
+
"AWS::AutoScaling::ScheduledAction": new Set(["StartTime", "EndTime"])
|
|
2523
2586
|
};
|
|
2524
2587
|
function isPhysicalIdSegment(value, physicalId) {
|
|
2525
2588
|
if (typeof value !== "string" || physicalId === void 0) return false;
|
|
@@ -10001,12 +10064,13 @@ const writeEventBusPolicy = async (ctx) => {
|
|
|
10001
10064
|
const action = ctx.declared["Action"];
|
|
10002
10065
|
const principal = str(ctx.declared["Principal"]);
|
|
10003
10066
|
if (action === void 0 || principal === void 0) throw new Error("EventBusPolicy revert needs a Statement (or Action + Principal)");
|
|
10067
|
+
const { partition } = partitionForRegion(ctx.region);
|
|
10004
10068
|
desiredStatement = {
|
|
10005
10069
|
Sid: statementId,
|
|
10006
10070
|
Effect: "Allow",
|
|
10007
|
-
Principal: principal === "*" ? "*" : { AWS: `arn:
|
|
10071
|
+
Principal: principal === "*" ? "*" : { AWS: `arn:${partition}:iam::${principal}:root` },
|
|
10008
10072
|
Action: action,
|
|
10009
|
-
Resource: `arn:
|
|
10073
|
+
Resource: `arn:${partition}:events:${ctx.region}:${ctx.accountId}:event-bus/${eventBusName}`,
|
|
10010
10074
|
...ctx.declared["Condition"] !== void 0 ? { Condition: ctx.declared["Condition"] } : {}
|
|
10011
10075
|
};
|
|
10012
10076
|
}
|
|
@@ -13048,6 +13112,14 @@ function groupReasons(items) {
|
|
|
13048
13112
|
}
|
|
13049
13113
|
return [...counts.entries()].sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1)).map(([k, c]) => `${k} ${c}`).join(", ");
|
|
13050
13114
|
}
|
|
13115
|
+
function deletedStackReport(label) {
|
|
13116
|
+
return {
|
|
13117
|
+
stack: label,
|
|
13118
|
+
drifted: 1,
|
|
13119
|
+
findings: [],
|
|
13120
|
+
stackDeleted: true
|
|
13121
|
+
};
|
|
13122
|
+
}
|
|
13051
13123
|
function buildStackJson(rawFindings, header) {
|
|
13052
13124
|
const findings = annotateHints(rawFindings);
|
|
13053
13125
|
const isDriftHere = (f) => DRIFT_TIERS.includes(f.tier) && !f.unrecorded;
|
|
@@ -13764,11 +13836,15 @@ function hasBaselineForStack(stackName) {
|
|
|
13764
13836
|
async function runCheck(args) {
|
|
13765
13837
|
const a = parseCommonArgs(args, "check");
|
|
13766
13838
|
if (a.profile) process.env.AWS_PROFILE = a.profile;
|
|
13839
|
+
const emitEmptyJsonOnError = () => {
|
|
13840
|
+
if (a.json) console.log("[]");
|
|
13841
|
+
};
|
|
13767
13842
|
let config;
|
|
13768
13843
|
try {
|
|
13769
13844
|
config = await loadConfig();
|
|
13770
13845
|
} catch (e) {
|
|
13771
13846
|
console.error(`error: ${e.message}`);
|
|
13847
|
+
emitEmptyJsonOnError();
|
|
13772
13848
|
return 2;
|
|
13773
13849
|
}
|
|
13774
13850
|
let stacks;
|
|
@@ -13776,6 +13852,7 @@ async function runCheck(args) {
|
|
|
13776
13852
|
stacks = await resolveStacks(a);
|
|
13777
13853
|
} catch (e) {
|
|
13778
13854
|
console.error(`error: ${e.message}`);
|
|
13855
|
+
emitEmptyJsonOnError();
|
|
13779
13856
|
return 2;
|
|
13780
13857
|
}
|
|
13781
13858
|
if (stacks.length === 0) {
|
|
@@ -13792,6 +13869,7 @@ async function runCheck(args) {
|
|
|
13792
13869
|
const app = resolveApp(a.app);
|
|
13793
13870
|
if (!app) {
|
|
13794
13871
|
console.error("error: --pre-deploy needs a CDK app (--app or a cdk.json in the cwd)");
|
|
13872
|
+
emitEmptyJsonOnError();
|
|
13795
13873
|
return 2;
|
|
13796
13874
|
}
|
|
13797
13875
|
const synthed = await synthApp(app, {
|
|
@@ -13885,9 +13963,7 @@ async function runCheck(args) {
|
|
|
13885
13963
|
constructPathByLogical: constructPathsByLogical(desired.resources),
|
|
13886
13964
|
physicalIdByLogical: physicalIdsByLogical(desired.resources),
|
|
13887
13965
|
allLogicalIds: desired.resources.map((r) => r.logicalId),
|
|
13888
|
-
warn: (s) =>
|
|
13889
|
-
if (!a.json) console.error(s);
|
|
13890
|
-
}
|
|
13966
|
+
warn: (s) => console.error(s)
|
|
13891
13967
|
}
|
|
13892
13968
|
}), {
|
|
13893
13969
|
stackName,
|
|
@@ -13930,8 +14006,10 @@ async function runCheck(args) {
|
|
|
13930
14006
|
if (isStackNotDeployed(e)) {
|
|
13931
14007
|
if (hasBaselineForStack(stackName)) {
|
|
13932
14008
|
const msg = "deployed baseline exists but the stack is gone — deleted out of band";
|
|
13933
|
-
|
|
13934
|
-
|
|
14009
|
+
const label = `${stackName} (${region})`;
|
|
14010
|
+
console.error(`[Drift] ${label}: ${msg}`);
|
|
14011
|
+
if (a.json) jsonReports.push(deletedStackReport(label));
|
|
14012
|
+
else console.log(`${style.resultLabel("result:")} ${style.drift("1 drift(s)")} — ${label}: stack deleted out of band`);
|
|
13935
14013
|
worst = Math.max(worst, finalCheckExit(1, a.fail), a.strict ? 1 : 0);
|
|
13936
14014
|
anyDrift = true;
|
|
13937
14015
|
continue;
|