cdk-real-drift 0.9.14 → 0.10.1

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
@@ -376,25 +376,26 @@ CI (with `--yes`).
376
376
  leave cells natural-width. Don't chase pixel alignment at the cost of a
377
377
  readable diff. -->
378
378
 
379
- | option | meaning |
380
- | -------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
381
- | `--region <r>` | a stack's own `env.region` ALWAYS wins; for an env-AGNOSTIC stack (no `env`) it falls back to `--region` (or `$AWS_REGION` / `$AWS_DEFAULT_REGION`), else the AWS-CLI/cdk region chain — the active profile's region, then the `[default]` profile's region, then EC2 IMDS |
382
- | `--profile <p>` | AWS profile (else `$AWS_PROFILE`, else `$AWS_DEFAULT_PROFILE` — same order `aws` and `cdk` use) |
383
- | `-a, --app <cmd\|cdk.out>` | CDK app command or pre-synthesized assembly dir (or `$CDKRD_APP` / cdk.json `"app"`); stack auto-discovery + construct paths |
384
- | `-c, --context key=value` | context for synth (repeatable; cdk.json is the base layer) |
385
- | `--all` | target every stack the app defines (the default when no `<stack>` is named; overrides any positional names) |
386
- | `--json` | machine-readable output (see [JSON contract](#json-output-contract)) |
387
- | `--fail` | (check) exit 1 on drift and never prompt; for scripts/CI. Without it, check reports drift but exits 0 |
388
- | `--strict` | (check) exit 1 when coverage is incomplete. A coverage gap is always surfaced loudly; `--strict` makes it CI-failing. Orthogonal to `--fail` |
389
- | `--show-all` | (check) inventory mode: show all current undeclared state, ignoring the baseline |
390
- | `--verbose` / `-v` | (check) expand the `info:` footer tiers / (revert) expand the not-revertable summary to full lists; (record) itemizes nested sub-keys in the multiselect. `-v` means `--verbose` **inside a verb** (`check -v`); a bare `cdkrd -v` (no verb) prints the version |
391
- | `--pre-deploy` | (check) compare live vs the LOCAL synth template: the declared drift your next `cdk deploy` would silently overwrite |
392
- | `--undeclared-only` | (check) undeclared drift only: pair cdkrd with `cdk drift` for the declared side |
393
- | `--declared-only` | (check) declared drift vs the deployed template only (undeclared tier skipped; baseline untouched). Not `--pre-deploy` |
394
- | `--dry-run` | (revert) print the plan; make no changes |
395
- | `--wait[=DURATION]` | (revert) on a transient "resource is mid-update" error (e.g. Route53Resolver `RSLVR-00705`) keep retrying until it settles, up to DURATION (default `10m`; e.g. `--wait=5m`, `--wait=90s`). The DURATION is **inline-only** (`--wait=5m`); a separate `--wait 5m` is not read |
396
- | `--remove-unrecorded` | (revert, and check for its inline revert) REMOVE unrecorded values + DELETE unrecorded added resources in a no-prompt run (`--yes`/CI); an interactive revert already lists them |
397
- | `--yes` / `-y` | skip confirmations (revert apply; record records all without the multiselect) |
379
+ | option | meaning |
380
+ | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
381
+ | `--region <r>` | a stack's own `env.region` ALWAYS wins; for an env-AGNOSTIC stack (no `env`) it falls back to `--region` (or `$AWS_REGION` / `$AWS_DEFAULT_REGION`), else the AWS-CLI/cdk region chain — the active profile's region, then the `[default]` profile's region, then EC2 IMDS |
382
+ | `--profile <p>` | AWS profile (else `$AWS_PROFILE`, else `$AWS_DEFAULT_PROFILE` — same order `aws` and `cdk` use) |
383
+ | `-a, --app <cmd\|cdk.out>` | CDK app command or pre-synthesized assembly dir (or `$CDKRD_APP` / cdk.json `"app"`); stack auto-discovery + construct paths |
384
+ | `-c, --context key=value` | context for synth (repeatable; cdk.json is the base layer) |
385
+ | `--all` | target every stack the app defines (the default when no `<stack>` is named; overrides any positional names) |
386
+ | `--json` | machine-readable output (see [JSON contract](#json-output-contract)) |
387
+ | `--fail` | (check) exit 1 on drift and never prompt; for scripts/CI. Without it, check reports drift but exits 0 |
388
+ | `--strict` | (check) exit 1 when coverage is incomplete. A coverage gap is always surfaced loudly; `--strict` makes it CI-failing. Orthogonal to `--fail` |
389
+ | `--show-all` | (check) inventory mode: show all current undeclared state, ignoring the baseline |
390
+ | `--verbose` / `-v` | (check) expand the `info:` footer tiers / (revert) expand the not-revertable summary to full lists; (record) itemizes nested sub-keys in the multiselect. `-v` means `--verbose` **inside a verb** (`check -v`); a bare `cdkrd -v` (no verb) prints the version |
391
+ | `--pre-deploy` | (check) compare live vs the LOCAL synth template: the declared drift your next `cdk deploy` would silently overwrite |
392
+ | `--undeclared-only` | (check) undeclared drift only: pair cdkrd with `cdk drift` for the declared side |
393
+ | `--declared-only` | (check) declared drift vs the deployed template only (undeclared tier skipped; baseline untouched). Not `--pre-deploy` |
394
+ | `--dry-run` | (revert) print the plan; make no changes |
395
+ | `--wait[=DURATION]` | (revert) on a transient "resource is mid-update" error (e.g. Route53Resolver `RSLVR-00705`) keep retrying until it settles, up to DURATION (default `10m`; e.g. `--wait=5m`, `--wait=90s`). The DURATION is **inline-only** (`--wait=5m`); a separate `--wait 5m` is not read |
396
+ | `--remove-unrecorded` | (revert, and check for its inline revert) REMOVE unrecorded values + DELETE unrecorded added resources in a no-prompt run (`--yes`/CI); an interactive revert already lists them |
397
+ | `--force` | (revert) proceed even when the stack is **mid-operation** (`*_IN_PROGRESS`). By default revert re-reads the stack right before the write and refuses (to avoid fighting an in-flight deploy); `--force` overrides that for a knowingly-wedged stack. The mid-operation warning still prints; `--force` does **not** skip the confirm (that is `--yes`) |
398
+ | `--yes` / `-y` | skip confirmations (revert apply; record records all without the multiselect) |
398
399
 
399
400
  Unknown options (`--apq`) and options missing their value (`--app` at the end of
400
401
  the line) are errors (exit `2`): a typo'd flag never silently becomes a stack name.
@@ -630,6 +631,14 @@ builds printed one pretty-printed `{...}` per stack back-to-back, which was neit
630
631
  valid JSON value nor JSONL; multi-stack `--json` was unparseable — issue #755.) All
631
632
  `note` / `warning` / progress lines go to **stderr**, so stdout stays pure JSON.
632
633
 
634
+ **Secret redaction.** Values on known secret-bearing properties — Lambda
635
+ `Environment.Variables`, CodeBuild `Environment.EnvironmentVariables[].Value`,
636
+ Elastic Beanstalk env-namespace `OptionSettings`, EC2 LaunchTemplate `UserData` —
637
+ are masked as `<redacted:NN chars>` in both text and `--json` output, so a rotated
638
+ secret surfacing as drift does not leak its plaintext into CI logs. The finding
639
+ still surfaces (detection is preserved) and the property/key name stays visible —
640
+ only the value is hidden (#798).
641
+
633
642
  A **stack that errored or was skipped** before it could be checked still appears as an
634
643
  element so a consumer sees which stacks ran: it carries `"error": "<reason>"` alongside
635
644
  `"drifted": 0` and an empty `"findings": []`. (`error` is absent on a
@@ -729,7 +738,10 @@ After publication this shape is a backward-compatible API.
729
738
  `revert` also **refuses to write (exit 2) when the target stack is mid-operation**
730
739
  (`*_IN_PROGRESS`): it re-reads the stack status immediately before applying, so a
731
740
  revert can never fight an in-flight `cdk deploy` / update by writing stale values
732
- onto an updating stack — wait for the stack to settle, then re-run. And
741
+ onto an updating stack — wait for the stack to settle, then re-run. For a stack
742
+ that is **wedged** in an `*_IN_PROGRESS` state that will never settle, pass
743
+ `--force` to override the refusal (the mid-operation warning still prints; `--force`
744
+ only skips this in-progress refusal — not the confirm, which is `--yes`). And
733
745
  `record` / `ignore` / `revert` now surface the same stack-status warning `check`
734
746
  prints when a stack is mid-operation or in a failed state (a `record` mid-update
735
747
  would otherwise snapshot transient values into the committed baseline).
package/dist/cli.js CHANGED
@@ -293,6 +293,7 @@ const BOOLEAN_FLAGS = new Set([
293
293
  "--declared-only",
294
294
  "--dry-run",
295
295
  "--remove-unrecorded",
296
+ "--force",
296
297
  "--verbose",
297
298
  "-v",
298
299
  "--strict",
@@ -333,7 +334,8 @@ const ALLOWED_FLAGS_BY_VERB = {
333
334
  "--verbose",
334
335
  "--remove-unrecorded",
335
336
  "--dry-run",
336
- "--wait"
337
+ "--wait",
338
+ "--force"
337
339
  ])
338
340
  };
339
341
  /**
@@ -428,6 +430,7 @@ function parseCommonArgs(args, verb) {
428
430
  undeclaredOnly: has("--undeclared-only"),
429
431
  declaredOnly: has("--declared-only"),
430
432
  removeUnrecorded: has("--remove-unrecorded"),
433
+ force: has("--force"),
431
434
  verbose: has("--verbose") || has("-v"),
432
435
  waitMs
433
436
  };
@@ -15264,7 +15267,7 @@ function augmentRevertPlan(plan, schemas, liveByLogical, declaredByLogical) {
15264
15267
  };
15265
15268
  }
15266
15269
  async function revertStack(p) {
15267
- const { stackName, region, gathered, baseline, config, dryRun, yes, removeUnrecorded, verbose, interactive, autoSelectAll, selectedFindingKeys, waitMs, waitNow, waitSleep } = p;
15270
+ const { stackName, region, gathered, baseline, config, dryRun, yes, removeUnrecorded, force, verbose, interactive, autoSelectAll, selectedFindingKeys, waitMs, waitNow, waitSleep } = p;
15268
15271
  const out = p.json ? () => {} : console.log;
15269
15272
  let worst = 0;
15270
15273
  const includeRemovals = includeUnrecordedRemovals(removeUnrecorded, interactive, yes);
@@ -15371,7 +15374,8 @@ async function revertStack(p) {
15371
15374
  }
15372
15375
  plan = augment(plan);
15373
15376
  const inProgress = await stackInProgressRefusal(stackName, region);
15374
- if (inProgress) {
15377
+ if (inProgress) if (force) console.error("\nwarning: " + inProgress + " Proceeding anyway (--force).");
15378
+ else {
15375
15379
  console.error("\n" + inProgress);
15376
15380
  return {
15377
15381
  exit: 2,
@@ -15833,6 +15837,87 @@ function annotateHints(findings) {
15833
15837
  });
15834
15838
  }
15835
15839
 
15840
+ //#endregion
15841
+ //#region src/report/redact.ts
15842
+ function maskPlaceholder(value) {
15843
+ if (typeof value === "string") return `<redacted:${value.length} chars>`;
15844
+ return "<redacted>";
15845
+ }
15846
+ const maskWhole = (value) => maskPlaceholder(value);
15847
+ const maskEntryValueField = (value) => {
15848
+ if (value && typeof value === "object" && !Array.isArray(value) && "Value" in value) return {
15849
+ ...value,
15850
+ Value: maskPlaceholder(value.Value)
15851
+ };
15852
+ return maskPlaceholder(value);
15853
+ };
15854
+ const maskMapValues = (value) => {
15855
+ if (value && typeof value === "object" && !Array.isArray(value)) {
15856
+ const out = {};
15857
+ for (const [k, v] of Object.entries(value)) out[k] = maskPlaceholder(v);
15858
+ return out;
15859
+ }
15860
+ return maskPlaceholder(value);
15861
+ };
15862
+ const REDACTED_VALUE_PATHS = {
15863
+ "AWS::Lambda::Function": [{
15864
+ pathRe: /(^|\.)Environment\.Variables\./,
15865
+ redact: maskWhole
15866
+ }, {
15867
+ pathRe: /(^|\.)Environment\.Variables$/,
15868
+ redact: maskMapValues
15869
+ }],
15870
+ "AWS::CodeBuild::Project": [{
15871
+ pathRe: /(^|\.)Environment\.EnvironmentVariables\.\d+\.Value$/,
15872
+ redact: maskWhole
15873
+ }],
15874
+ "AWS::EC2::LaunchTemplate": [{
15875
+ pathRe: /(^|\.)LaunchTemplateData\.UserData$/,
15876
+ redact: maskWhole
15877
+ }],
15878
+ "AWS::ElasticBeanstalk::Environment": [{
15879
+ pathRe: /(^|\.)OptionSettings\[aws:elasticbeanstalk:application:environment\|/,
15880
+ redact: maskEntryValueField
15881
+ }]
15882
+ };
15883
+ function redactValue(resourceType, path, value) {
15884
+ const matchers = REDACTED_VALUE_PATHS[resourceType];
15885
+ if (!matchers) return value;
15886
+ for (const m of matchers) if (m.pathRe.test(path)) return m.redact(value);
15887
+ return value;
15888
+ }
15889
+ function isRedactedPath(resourceType, path) {
15890
+ const matchers = REDACTED_VALUE_PATHS[resourceType];
15891
+ return !!matchers && matchers.some((m) => m.pathRe.test(path));
15892
+ }
15893
+ function redactFinding(f) {
15894
+ if (!isRedactedPath(f.resourceType, f.path)) return f;
15895
+ const out = { ...f };
15896
+ if ("desired" in f && f.desired !== void 0) out.desired = redactValue(f.resourceType, f.path, f.desired);
15897
+ if ("actual" in f && f.actual !== void 0) out.actual = redactValue(f.resourceType, f.path, f.actual);
15898
+ if (f.arrayDelta && typeof f.arrayDelta === "object") out.arrayDelta = redactArrayDelta(f.resourceType, f.path, f.arrayDelta);
15899
+ return out;
15900
+ }
15901
+ function redactArrayDelta(resourceType, path, d) {
15902
+ const mv = (v) => redactValue(resourceType, path, v);
15903
+ return {
15904
+ identityField: d.identityField,
15905
+ added: d.added.map((a) => ({
15906
+ id: a.id,
15907
+ value: mv(a.value)
15908
+ })),
15909
+ removed: d.removed.map((r) => ({
15910
+ id: r.id,
15911
+ value: mv(r.value)
15912
+ })),
15913
+ changed: d.changed.map((c) => ({
15914
+ id: c.id,
15915
+ recorded: mv(c.recorded),
15916
+ actual: mv(c.actual)
15917
+ }))
15918
+ };
15919
+ }
15920
+
15836
15921
  //#endregion
15837
15922
  //#region src/report/report.ts
15838
15923
  function stackNameFromHeader(header) {
@@ -15885,42 +15970,45 @@ function formatFinding(f, stackName = "") {
15885
15970
  const pathDisplay = f.attributeKey ? `${f.path}[${sanitizeForTerminal(f.attributeKey)}]` : f.path;
15886
15971
  let s = `${pathDisplay ? `${id}.${pathDisplay}` : id} (${f.resourceType})`;
15887
15972
  if (f.note) s += ` — ${sanitizeForTerminal(f.note)}`;
15888
- if (f.tier === "declared") if (isRecord(f.desired) && isRecord(f.actual)) s += formatMapDelta(f.desired, f.actual, false);
15973
+ const rt = f.resourceType;
15974
+ const rd = (v) => redactValue(rt, f.path, v);
15975
+ if (f.tier === "declared") if (isRecord(f.desired) && isRecord(f.actual)) s += formatMapDelta(f.desired, f.actual, false, rt, f.path);
15889
15976
  else {
15890
- const { a: d, b: act } = jPair(f.desired, f.actual);
15977
+ const { a: d, b: act } = jPair(rd(f.desired), rd(f.actual));
15891
15978
  s += `\n desired=${style.desired(d)}\n actual =${style.actual(act)}`;
15892
15979
  }
15893
- else if (f.tier === "added" && f.desired !== void 0) if (isRecord(f.desired) && isRecord(f.actual)) s += formatMapDelta(f.desired, f.actual, true);
15980
+ else if (f.tier === "added" && f.desired !== void 0) if (isRecord(f.desired) && isRecord(f.actual)) s += formatMapDelta(f.desired, f.actual, true, rt, f.path);
15894
15981
  else {
15895
- const { a: base, b: act } = jPair(f.desired, f.actual);
15982
+ const { a: base, b: act } = jPair(rd(f.desired), rd(f.actual));
15896
15983
  s += `\n baseline=${style.desired(base)}\n actual =${style.actual(act)}`;
15897
15984
  }
15898
- else if (f.tier === "added" && f.actual !== void 0) s += `\n actual =${style.actual(j(f.actual))}`;
15899
- else if (f.tier === "undeclared" && f.arrayDelta) s += formatArrayDelta(f.arrayDelta);
15900
- else if (f.tier === "undeclared" && f.desired !== void 0) if (isRecord(f.desired) && isRecord(f.actual)) s += formatMapDelta(f.desired, f.actual, true);
15985
+ else if (f.tier === "added" && f.actual !== void 0) s += `\n actual =${style.actual(j(rd(f.actual)))}`;
15986
+ else if (f.tier === "undeclared" && f.arrayDelta) s += formatArrayDelta(f.arrayDelta, rt, f.path);
15987
+ else if (f.tier === "undeclared" && f.desired !== void 0) if (isRecord(f.desired) && isRecord(f.actual)) s += formatMapDelta(f.desired, f.actual, true, rt, f.path);
15901
15988
  else {
15902
- const { a: base, b: act } = jPair(f.desired, f.actual);
15989
+ const { a: base, b: act } = jPair(rd(f.desired), rd(f.actual));
15903
15990
  s += `\n baseline=${style.desired(base)}\n actual =${style.actual(act)}`;
15904
15991
  }
15905
- else if (f.tier === "undeclared" || f.tier === "atDefault" || f.tier === "generated") s += `\n actual =${style.actual(j(f.actual))}`;
15992
+ else if (f.tier === "undeclared" || f.tier === "atDefault" || f.tier === "generated") s += `\n actual =${style.actual(j(rd(f.actual)))}`;
15906
15993
  if (f.hint) s += `\n ${style.note(`↳ ${sanitizeForTerminal(f.hint)}`)}`;
15907
15994
  return s;
15908
15995
  }
15909
15996
  const isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
15910
- function formatMapDelta(desired, actual, baselineLabels) {
15997
+ function formatMapDelta(desired, actual, baselineLabels, resourceType, basePath) {
15911
15998
  const lhs = baselineLabels ? "baseline" : "desired";
15912
15999
  const rhs = baselineLabels ? "actual " : "actual ";
15913
16000
  const keys = [...new Set([...Object.keys(desired), ...Object.keys(actual)])].sort();
16001
+ const rd = (k, v) => resourceType !== void 0 && basePath !== void 0 ? redactValue(resourceType, `${basePath}.${k}`, v) : v;
15914
16002
  let s = "";
15915
16003
  for (const k of keys) {
15916
16004
  const inD = Object.hasOwn(desired, k);
15917
16005
  if (inD && Object.hasOwn(actual, k)) {
15918
16006
  if (deepEqual(desired[k], actual[k])) continue;
15919
- const { a, b } = jPair(desired[k], actual[k]);
16007
+ const { a, b } = jPair(rd(k, desired[k]), rd(k, actual[k]));
15920
16008
  const sk = sanitizeForTerminal(k);
15921
16009
  s += `\n ~ ${sk}\n ${lhs}=${style.desired(a)}\n ${rhs}=${style.actual(b)}`;
15922
- } else if (inD) s += `\n - ${sanitizeForTerminal(k)} (in ${baselineLabels ? "baseline" : "template"}, absent in live)\n ${lhs}=${style.desired(j(desired[k]))}`;
15923
- else s += `\n + ${sanitizeForTerminal(k)} (in live, not in ${baselineLabels ? "baseline" : "template"})\n ${rhs}=${style.actual(j(actual[k]))}`;
16010
+ } else if (inD) s += `\n - ${sanitizeForTerminal(k)} (in ${baselineLabels ? "baseline" : "template"}, absent in live)\n ${lhs}=${style.desired(j(rd(k, desired[k])))}`;
16011
+ else s += `\n + ${sanitizeForTerminal(k)} (in live, not in ${baselineLabels ? "baseline" : "template"})\n ${rhs}=${style.actual(j(rd(k, actual[k])))}`;
15924
16012
  }
15925
16013
  if (s === "") {
15926
16014
  const { a, b } = jPair(desired, actual);
@@ -15928,13 +16016,14 @@ function formatMapDelta(desired, actual, baselineLabels) {
15928
16016
  }
15929
16017
  return s;
15930
16018
  }
15931
- function formatArrayDelta(d) {
15932
- const baseline = (v) => `\n baseline=${style.desired(j(v))}`;
15933
- const actual = (v) => `\n actual =${style.actual(j(v))}`;
16019
+ function formatArrayDelta(d, resourceType, path) {
16020
+ const rd = (v) => resourceType !== void 0 && path !== void 0 ? redactValue(resourceType, path, v) : v;
16021
+ const baseline = (v) => `\n baseline=${style.desired(j(rd(v)))}`;
16022
+ const actual = (v) => `\n actual =${style.actual(j(rd(v)))}`;
15934
16023
  let s = ` — ${sanitizeForTerminal(d.identityField)}-keyed element(s) changed vs .cdkrd baseline:`;
15935
16024
  for (const a of d.added) s += `\n + [${sanitizeForTerminal(a.id)}]${actual(a.value)}`;
15936
16025
  for (const c of d.changed) {
15937
- const { a: base, b: act } = jPair(c.recorded, c.actual);
16026
+ const { a: base, b: act } = jPair(rd(c.recorded), rd(c.actual));
15938
16027
  s += `\n ~ [${sanitizeForTerminal(c.id)}]\n baseline=${style.desired(base)}\n actual =${style.actual(act)}`;
15939
16028
  }
15940
16029
  for (const r of d.removed) s += `\n - [${sanitizeForTerminal(r.id)}]${baseline(r.value)}`;
@@ -15979,7 +16068,7 @@ function buildStackJson(rawFindings, header, hasBaseline) {
15979
16068
  json: {
15980
16069
  stack: header,
15981
16070
  drifted,
15982
- findings,
16071
+ findings: findings.map((f) => redactFinding(f)),
15983
16072
  baseline: hasBaseline === true
15984
16073
  },
15985
16074
  code: drifted === 0 ? 0 : 1
@@ -17147,6 +17236,7 @@ async function runRevert(args) {
17147
17236
  dryRun,
17148
17237
  yes: a.yes,
17149
17238
  removeUnrecorded: a.removeUnrecorded,
17239
+ force: a.force,
17150
17240
  verbose: a.verbose,
17151
17241
  interactive: a.json ? false : isInteractive(),
17152
17242
  ...a.waitMs !== void 0 && { waitMs: a.waitMs },
@@ -17273,6 +17363,12 @@ OPTIONS
17273
17363
  --remove-unrecorded (revert, and check for its inline revert) REMOVE unrecorded
17274
17364
  values + DELETE unrecorded added resources (never recorded;
17275
17365
  default: refuse — record the ones that are right)
17366
+ --force (revert) proceed even when the stack is mid-operation
17367
+ (*_IN_PROGRESS). By default revert re-reads the stack right
17368
+ before the write and REFUSES, to avoid fighting an in-flight
17369
+ deploy; --force overrides that for a knowingly-wedged stack
17370
+ (the mid-operation warning still prints; --force does NOT
17371
+ skip the confirm — that is --yes)
17276
17372
  --yes, -y skip the write confirm AND the op multiselect — apply the
17277
17373
  FULL plan (revert) / skip the selection multiselect +
17278
17374
  overwrite notice, record ALL (record) / ignore ALL shown