cdk-real-drift 0.4.39 → 0.4.41

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
@@ -699,6 +699,14 @@ mode: a `record` / `ignore` that would need the selection prompt refuses without
699
699
 
700
700
  After publication this shape is a backward-compatible API.
701
701
 
702
+ `revert` also **refuses to write (exit 2) when the target stack is mid-operation**
703
+ (`*_IN_PROGRESS`): it re-reads the stack status immediately before applying, so a
704
+ revert can never fight an in-flight `cdk deploy` / update by writing stale values
705
+ onto an updating stack — wait for the stack to settle, then re-run. And
706
+ `record` / `ignore` / `revert` now surface the same stack-status warning `check`
707
+ prints when a stack is mid-operation or in a failed state (a `record` mid-update
708
+ would otherwise snapshot transient values into the committed baseline).
709
+
702
710
  ## IAM permissions
703
711
 
704
712
  `check` / `record` are **read-only**: the AWS managed `ReadOnlyAccess` policy
package/dist/cli.js CHANGED
@@ -10050,13 +10050,20 @@ async function classifyRead(cfn, r, read, schemas, classifyOpts) {
10050
10050
  path: "",
10051
10051
  note: read?.skippedReason ?? "not readable"
10052
10052
  }];
10053
- let schema = schemas.get(r.resourceType);
10054
- if (!schema) {
10053
+ const cachedSchema = schemas.get(r.resourceType);
10054
+ if (!cachedSchema) {
10055
10055
  const res = await getSchemaInfoResult(cfn, r.resourceType);
10056
- schema = res.info;
10057
- if (!res.failed) schemas.set(r.resourceType, schema);
10058
- }
10059
- return classifyResource(r, read.live, schema, classifyOpts);
10056
+ if (res.failed) return [{
10057
+ tier: "skipped",
10058
+ logicalId: r.logicalId,
10059
+ resourceType: r.resourceType,
10060
+ path: "",
10061
+ note: "schema unavailable (DescribeType failed) — coverage incomplete"
10062
+ }];
10063
+ schemas.set(r.resourceType, res.info);
10064
+ return classifyResource(r, read.live, res.info, classifyOpts);
10065
+ }
10066
+ return classifyResource(r, read.live, cachedSchema, classifyOpts);
10060
10067
  }
10061
10068
  async function gatherFindings(stackName, region, templateOverride, recoveryTemplate) {
10062
10069
  const cfn = new CloudFormationClient({
@@ -13503,6 +13510,41 @@ function stackLabel$1(stackName, region) {
13503
13510
  return `${stackName} (${region})`;
13504
13511
  }
13505
13512
  /**
13513
+ * Print the stack-state warning (#786) — a stack that is mid-operation (`*_IN_PROGRESS`)
13514
+ * or in a failed state (`*_FAILED`) carries a `stackStatusWarning` from `loadDesired`
13515
+ * (via `classifyStackStatus`). `check` prints it (`check.ts`), but the standalone
13516
+ * `record` / `ignore` / `revert` verbs never consumed it — so a `record` mid-`cdk deploy`
13517
+ * would snapshot transient values into the git baseline, and a `revert` would fight the
13518
+ * in-flight deploy, all silently. This centralizes the SAME wording/stderr routing check
13519
+ * uses so every verb surfaces the warning identically. No-op when the stack is stable.
13520
+ */
13521
+ function warnStackStatus(stackName, warning) {
13522
+ if (warning) console.error(`warning: ${stackName}: ${warning}`);
13523
+ }
13524
+ /**
13525
+ * TOCTOU guard (#786): re-read the stack's live `StackStatus` immediately before a
13526
+ * revert's Cloud Control / SDK write and REFUSE when it is mid-operation
13527
+ * (`*_IN_PROGRESS`). A stack stable at gather time can enter a `cdk deploy` while the
13528
+ * revert confirm prompt sits open — writing OLD values onto an updating stack fights the
13529
+ * deploy. `revert` is the one AWS-mutating verb, so the gate must be right before the
13530
+ * write, not only at gather time. Returns a refusal reason string when the write must be
13531
+ * refused, or `undefined` when it is safe to proceed. A DescribeStacks read error is NOT
13532
+ * treated as a refusal (fail-open: the gather already succeeded, so a transient re-read
13533
+ * failure should not block a legitimate revert) — only a confirmed in-progress state does.
13534
+ */
13535
+ async function stackInProgressRefusal(stackName, region) {
13536
+ let status;
13537
+ try {
13538
+ status = (await new CloudFormationClient({
13539
+ region,
13540
+ ...CLIENT_TIMEOUTS
13541
+ }).send(new DescribeStacksCommand({ StackName: stackName }))).Stacks?.[0]?.StackStatus;
13542
+ } catch {
13543
+ return;
13544
+ }
13545
+ if (status?.endsWith("_IN_PROGRESS")) return `refusing to write to AWS — ${stackName} is mid-operation (${status}). A revert now would fight the in-flight deploy/update. Wait for the stack to settle, then re-run.`;
13546
+ }
13547
+ /**
13506
13548
  * The revert confirm message (R52). When NOT-revertable findings exist (e.g. a
13507
13549
  * no-baseline first check with one declared drift and 100+ undeclared values),
13508
13550
  * users read "This WRITES to AWS" as "everything I just saw gets written" —
@@ -13996,6 +14038,15 @@ async function revertStack(p) {
13996
14038
  };
13997
14039
  }
13998
14040
  }
14041
+ const inProgress = await stackInProgressRefusal(stackName, region);
14042
+ if (inProgress) {
14043
+ console.error("\n" + inProgress);
14044
+ return {
14045
+ exit: 2,
14046
+ aborted: false,
14047
+ refusedReason: inProgress
14048
+ };
14049
+ }
13999
14050
  const cc = new CloudControlClient({
14000
14051
  region,
14001
14052
  ...CLIENT_TIMEOUTS
@@ -14218,6 +14269,7 @@ async function runRecord(args) {
14218
14269
  }
14219
14270
  try {
14220
14271
  const { desired, findings } = await gatherWithProgress(showProgress, progressLabel(idx, stacks.length, stackName, region), () => gatherFindings(stackName, region, void 0, template));
14272
+ warnStackStatus(stackName, desired.stackStatusWarning);
14221
14273
  const result = await recordStack({
14222
14274
  stackName,
14223
14275
  region,
@@ -14326,6 +14378,7 @@ async function runIgnore(args) {
14326
14378
  }
14327
14379
  try {
14328
14380
  const { desired, findings } = await gatherWithProgress(showProgress, progressLabel(idx, stacks.length, stackName, region), () => gatherFindings(stackName, region, void 0, template));
14381
+ warnStackStatus(stackName, desired.stackStatusWarning);
14329
14382
  const baseline = await loadBaseline(stackName, desired.accountId, region);
14330
14383
  if (baseline) checkBaselineAccount(baseline, desired.accountId, stackName);
14331
14384
  const result = await ignoreStack({
@@ -15643,6 +15696,7 @@ async function runRevert(args) {
15643
15696
  const gathered = await gatherWithProgress(showProgress, progressLabel(idx, stacks.length, stackName, region), () => gatherFindings(stackName, region, void 0, template));
15644
15697
  const baseline = await loadBaseline(stackName, gathered.desired.accountId, region);
15645
15698
  if (baseline) checkBaselineAccount(baseline, gathered.desired.accountId, stackName);
15699
+ warnStackStatus(stackName, gathered.desired.stackStatusWarning);
15646
15700
  const outcome = await revertStack({
15647
15701
  stackName,
15648
15702
  region,