cdk-real-drift 0.4.28 → 0.4.30
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 +4 -0
- package/dist/cli.js +42 -5
- package/dist/cli.js.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -711,6 +711,10 @@ covers them. **If you never run `revert`, cdkrd needs no write permissions at al
|
|
|
711
711
|
`DescribeType`; `DescribeStackResources` (the sibling-ownership check for the
|
|
712
712
|
`added` tier — see the `added`-tier entry below); `ListExports` (only for
|
|
713
713
|
templates using `Fn::ImportValue`)
|
|
714
|
+
- `sts:GetCallerIdentity` (resolves the current account so `check` can tell a stack
|
|
715
|
+
never deployed in THIS account from one deleted out of band, under the
|
|
716
|
+
multi-account baseline pattern — allowed for any valid credentials, so no policy
|
|
717
|
+
statement is normally required)
|
|
714
718
|
- `cloudcontrol:GetResource`: Cloud Control invokes each type's own read handler,
|
|
715
719
|
so it needs that type's read permissions (this is why `ReadOnlyAccess` is the
|
|
716
720
|
simple answer). `revert` additionally uses `cloudcontrol:UpdateResource` /
|
package/dist/cli.js
CHANGED
|
@@ -57,6 +57,7 @@ import { DescribeSignalingChannelCommand, DescribeStreamCommand, KinesisVideoCli
|
|
|
57
57
|
import { DescribeDomainConfigCommand, OpenSearchClient, UpdateDomainConfigCommand } from "@aws-sdk/client-opensearch";
|
|
58
58
|
import { GetWebACLCommand, UpdateWebACLCommand, WAFV2Client } from "@aws-sdk/client-wafv2";
|
|
59
59
|
import { ConfigServiceClient, DescribeConfigRulesCommand, PutConfigRuleCommand } from "@aws-sdk/client-config-service";
|
|
60
|
+
import { GetCallerIdentityCommand, STSClient } from "@aws-sdk/client-sts";
|
|
60
61
|
|
|
61
62
|
//#region src/exit.ts
|
|
62
63
|
function drain(stream) {
|
|
@@ -10148,8 +10149,10 @@ async function loadBaseline(stackName, accountId, region) {
|
|
|
10148
10149
|
let parsed;
|
|
10149
10150
|
try {
|
|
10150
10151
|
parsed = JSON.parse(raw);
|
|
10151
|
-
} catch {
|
|
10152
|
-
|
|
10152
|
+
} catch (e) {
|
|
10153
|
+
const detail = e.message;
|
|
10154
|
+
const conflict = /^(<{7}|={7}|>{7})/m.test(raw) ? " — looks like an unresolved git merge conflict (resolve the <<<<<<< / ======= / >>>>>>> markers)" : "";
|
|
10155
|
+
throw new Error(`baseline file ${path} is not valid JSON (corrupt or partially written): ${detail}${conflict} (delete or \`git restore\` the file to reset, then re-run \`cdkrd record\`)`);
|
|
10153
10156
|
}
|
|
10154
10157
|
if (parsed === null || typeof parsed !== "object") throw new Error(`baseline file ${path} is malformed: root is not an object`);
|
|
10155
10158
|
if (parsed.stackName && parsed.stackName !== stackName) throw new Error(`baseline file ${path} was captured for stack ${parsed.stackName}, but it was loaded as stack ${stackName} (the file was likely copied or renamed to the wrong path, or a case-insensitive filesystem collided two stacks onto one file). Baselines are per-stack — run \`cdkrd record\` to write this stack's own baseline file, or restore the correct file from git.`);
|
|
@@ -15100,10 +15103,19 @@ function finalCheckExit(code, fail) {
|
|
|
15100
15103
|
* A case-sensitive `readdirSync` prefix would MISS a baseline committed as `mystack.….json`
|
|
15101
15104
|
* when checking `MyStack`, silently downgrading a genuinely deleted stack to a benign skip.
|
|
15102
15105
|
*
|
|
15106
|
+
* #1046: when the CURRENT account is known (resolved via `resolveCallerAccount`), PIN the
|
|
15107
|
+
* filename's account segment too — else a same-named stack that lives in ANOTHER account
|
|
15108
|
+
* (the common `env: { account: PERSONAL || SHARED }` CDK pattern, which the baseline filename
|
|
15109
|
+
* design explicitly serves) but was never deployed in THIS account is falsely reported
|
|
15110
|
+
* "deleted out of band" (multi-account CI goes permanently red the moment the other account's
|
|
15111
|
+
* baseline is committed). The account is only wildcarded when it genuinely cannot be resolved
|
|
15112
|
+
* (an STS failure), preserving today's behavior as a fallback — the account axis twin of the
|
|
15113
|
+
* region pin the #942 fix applied.
|
|
15114
|
+
*
|
|
15103
15115
|
* The baselines directory is derived from `baselinePath` so the layout stays single-sourced.
|
|
15104
15116
|
* Pure (filesystem-only, no AWS) + exported for unit tests. Missing dir → false.
|
|
15105
15117
|
*/
|
|
15106
|
-
function hasBaselineForStack(stackName, region) {
|
|
15118
|
+
function hasBaselineForStack(stackName, region, accountId) {
|
|
15107
15119
|
const dir = dirname(baselinePath(stackName, "a", "r"));
|
|
15108
15120
|
let entries;
|
|
15109
15121
|
try {
|
|
@@ -15111,13 +15123,32 @@ function hasBaselineForStack(stackName, region) {
|
|
|
15111
15123
|
} catch {
|
|
15112
15124
|
return false;
|
|
15113
15125
|
}
|
|
15114
|
-
const prefix = `${stackName}
|
|
15126
|
+
const prefix = (accountId ? `${stackName}.${accountId}.` : `${stackName}.`).toLowerCase();
|
|
15115
15127
|
const suffix = `.${region}.json`.toLowerCase();
|
|
15116
15128
|
return entries.some((f) => {
|
|
15117
15129
|
const lower = f.toLowerCase();
|
|
15118
15130
|
return lower.startsWith(prefix) && lower.endsWith(suffix);
|
|
15119
15131
|
});
|
|
15120
15132
|
}
|
|
15133
|
+
/**
|
|
15134
|
+
* #1046: resolve the CURRENT account (region-free `sts:GetCallerIdentity`, a zero-permission
|
|
15135
|
+
* call) so `hasBaselineForStack` can pin the baseline filename's account segment. Returns
|
|
15136
|
+
* `undefined` on ANY failure (expired creds, blocked STS, network) so the caller falls back
|
|
15137
|
+
* to today's account-wildcard rather than erroring — a `check` that reached the not-deployed
|
|
15138
|
+
* catch already has working creds, so the STS call almost always succeeds. `--profile` is
|
|
15139
|
+
* already in `process.env.AWS_PROFILE` (set by the verb entry points), so the default
|
|
15140
|
+
* credential chain resolves it. Exported for unit tests.
|
|
15141
|
+
*/
|
|
15142
|
+
async function resolveCallerAccount(region) {
|
|
15143
|
+
try {
|
|
15144
|
+
return (await new STSClient({
|
|
15145
|
+
region,
|
|
15146
|
+
...CLIENT_TIMEOUTS
|
|
15147
|
+
}).send(new GetCallerIdentityCommand({}))).Account;
|
|
15148
|
+
} catch {
|
|
15149
|
+
return;
|
|
15150
|
+
}
|
|
15151
|
+
}
|
|
15121
15152
|
function safeStringifyJson(value) {
|
|
15122
15153
|
const seen = /* @__PURE__ */ new WeakSet();
|
|
15123
15154
|
const replacer = (_key, v) => {
|
|
@@ -15203,6 +15234,8 @@ async function runCheck(args) {
|
|
|
15203
15234
|
};
|
|
15204
15235
|
const separate = stackSeparator();
|
|
15205
15236
|
const showProgress = !a.json && isInteractive();
|
|
15237
|
+
let callerAccount;
|
|
15238
|
+
let callerAccountResolved = false;
|
|
15206
15239
|
for (const [idx, { stackName, region, template }] of stacks.entries()) {
|
|
15207
15240
|
if (!region) {
|
|
15208
15241
|
const msg = "no region — set env on the stack, pass --region, or set a region for the AWS profile";
|
|
@@ -15318,7 +15351,11 @@ async function runCheck(args) {
|
|
|
15318
15351
|
worst = Math.max(worst, strictCoverageExit(a.strict, gathered.findings, desired.resources));
|
|
15319
15352
|
} catch (e) {
|
|
15320
15353
|
if (isStackNotDeployed(e)) {
|
|
15321
|
-
if (
|
|
15354
|
+
if (!callerAccountResolved) {
|
|
15355
|
+
callerAccount = await resolveCallerAccount(region);
|
|
15356
|
+
callerAccountResolved = true;
|
|
15357
|
+
}
|
|
15358
|
+
if (hasBaselineForStack(stackName, region, callerAccount)) {
|
|
15322
15359
|
const msg = "deployed baseline exists but the stack is gone — deleted out of band";
|
|
15323
15360
|
const label = `${stackName} (${region})`;
|
|
15324
15361
|
console.error(`[Drift] ${label}: ${msg}`);
|