cdk-real-drift 0.4.39 → 0.4.40
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 +8 -0
- package/dist/cli.js +47 -0
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
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
|
@@ -13503,6 +13503,41 @@ function stackLabel$1(stackName, region) {
|
|
|
13503
13503
|
return `${stackName} (${region})`;
|
|
13504
13504
|
}
|
|
13505
13505
|
/**
|
|
13506
|
+
* Print the stack-state warning (#786) — a stack that is mid-operation (`*_IN_PROGRESS`)
|
|
13507
|
+
* or in a failed state (`*_FAILED`) carries a `stackStatusWarning` from `loadDesired`
|
|
13508
|
+
* (via `classifyStackStatus`). `check` prints it (`check.ts`), but the standalone
|
|
13509
|
+
* `record` / `ignore` / `revert` verbs never consumed it — so a `record` mid-`cdk deploy`
|
|
13510
|
+
* would snapshot transient values into the git baseline, and a `revert` would fight the
|
|
13511
|
+
* in-flight deploy, all silently. This centralizes the SAME wording/stderr routing check
|
|
13512
|
+
* uses so every verb surfaces the warning identically. No-op when the stack is stable.
|
|
13513
|
+
*/
|
|
13514
|
+
function warnStackStatus(stackName, warning) {
|
|
13515
|
+
if (warning) console.error(`warning: ${stackName}: ${warning}`);
|
|
13516
|
+
}
|
|
13517
|
+
/**
|
|
13518
|
+
* TOCTOU guard (#786): re-read the stack's live `StackStatus` immediately before a
|
|
13519
|
+
* revert's Cloud Control / SDK write and REFUSE when it is mid-operation
|
|
13520
|
+
* (`*_IN_PROGRESS`). A stack stable at gather time can enter a `cdk deploy` while the
|
|
13521
|
+
* revert confirm prompt sits open — writing OLD values onto an updating stack fights the
|
|
13522
|
+
* deploy. `revert` is the one AWS-mutating verb, so the gate must be right before the
|
|
13523
|
+
* write, not only at gather time. Returns a refusal reason string when the write must be
|
|
13524
|
+
* refused, or `undefined` when it is safe to proceed. A DescribeStacks read error is NOT
|
|
13525
|
+
* treated as a refusal (fail-open: the gather already succeeded, so a transient re-read
|
|
13526
|
+
* failure should not block a legitimate revert) — only a confirmed in-progress state does.
|
|
13527
|
+
*/
|
|
13528
|
+
async function stackInProgressRefusal(stackName, region) {
|
|
13529
|
+
let status;
|
|
13530
|
+
try {
|
|
13531
|
+
status = (await new CloudFormationClient({
|
|
13532
|
+
region,
|
|
13533
|
+
...CLIENT_TIMEOUTS
|
|
13534
|
+
}).send(new DescribeStacksCommand({ StackName: stackName }))).Stacks?.[0]?.StackStatus;
|
|
13535
|
+
} catch {
|
|
13536
|
+
return;
|
|
13537
|
+
}
|
|
13538
|
+
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.`;
|
|
13539
|
+
}
|
|
13540
|
+
/**
|
|
13506
13541
|
* The revert confirm message (R52). When NOT-revertable findings exist (e.g. a
|
|
13507
13542
|
* no-baseline first check with one declared drift and 100+ undeclared values),
|
|
13508
13543
|
* users read "This WRITES to AWS" as "everything I just saw gets written" —
|
|
@@ -13996,6 +14031,15 @@ async function revertStack(p) {
|
|
|
13996
14031
|
};
|
|
13997
14032
|
}
|
|
13998
14033
|
}
|
|
14034
|
+
const inProgress = await stackInProgressRefusal(stackName, region);
|
|
14035
|
+
if (inProgress) {
|
|
14036
|
+
console.error("\n" + inProgress);
|
|
14037
|
+
return {
|
|
14038
|
+
exit: 2,
|
|
14039
|
+
aborted: false,
|
|
14040
|
+
refusedReason: inProgress
|
|
14041
|
+
};
|
|
14042
|
+
}
|
|
13999
14043
|
const cc = new CloudControlClient({
|
|
14000
14044
|
region,
|
|
14001
14045
|
...CLIENT_TIMEOUTS
|
|
@@ -14218,6 +14262,7 @@ async function runRecord(args) {
|
|
|
14218
14262
|
}
|
|
14219
14263
|
try {
|
|
14220
14264
|
const { desired, findings } = await gatherWithProgress(showProgress, progressLabel(idx, stacks.length, stackName, region), () => gatherFindings(stackName, region, void 0, template));
|
|
14265
|
+
warnStackStatus(stackName, desired.stackStatusWarning);
|
|
14221
14266
|
const result = await recordStack({
|
|
14222
14267
|
stackName,
|
|
14223
14268
|
region,
|
|
@@ -14326,6 +14371,7 @@ async function runIgnore(args) {
|
|
|
14326
14371
|
}
|
|
14327
14372
|
try {
|
|
14328
14373
|
const { desired, findings } = await gatherWithProgress(showProgress, progressLabel(idx, stacks.length, stackName, region), () => gatherFindings(stackName, region, void 0, template));
|
|
14374
|
+
warnStackStatus(stackName, desired.stackStatusWarning);
|
|
14329
14375
|
const baseline = await loadBaseline(stackName, desired.accountId, region);
|
|
14330
14376
|
if (baseline) checkBaselineAccount(baseline, desired.accountId, stackName);
|
|
14331
14377
|
const result = await ignoreStack({
|
|
@@ -15643,6 +15689,7 @@ async function runRevert(args) {
|
|
|
15643
15689
|
const gathered = await gatherWithProgress(showProgress, progressLabel(idx, stacks.length, stackName, region), () => gatherFindings(stackName, region, void 0, template));
|
|
15644
15690
|
const baseline = await loadBaseline(stackName, gathered.desired.accountId, region);
|
|
15645
15691
|
if (baseline) checkBaselineAccount(baseline, gathered.desired.accountId, stackName);
|
|
15692
|
+
warnStackStatus(stackName, gathered.desired.stackStatusWarning);
|
|
15646
15693
|
const outcome = await revertStack({
|
|
15647
15694
|
stackName,
|
|
15648
15695
|
region,
|