cdk-real-drift 0.4.29 → 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 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) {
@@ -15102,10 +15103,19 @@ function finalCheckExit(code, fail) {
15102
15103
  * A case-sensitive `readdirSync` prefix would MISS a baseline committed as `mystack.….json`
15103
15104
  * when checking `MyStack`, silently downgrading a genuinely deleted stack to a benign skip.
15104
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
+ *
15105
15115
  * The baselines directory is derived from `baselinePath` so the layout stays single-sourced.
15106
15116
  * Pure (filesystem-only, no AWS) + exported for unit tests. Missing dir → false.
15107
15117
  */
15108
- function hasBaselineForStack(stackName, region) {
15118
+ function hasBaselineForStack(stackName, region, accountId) {
15109
15119
  const dir = dirname(baselinePath(stackName, "a", "r"));
15110
15120
  let entries;
15111
15121
  try {
@@ -15113,13 +15123,32 @@ function hasBaselineForStack(stackName, region) {
15113
15123
  } catch {
15114
15124
  return false;
15115
15125
  }
15116
- const prefix = `${stackName}.`.toLowerCase();
15126
+ const prefix = (accountId ? `${stackName}.${accountId}.` : `${stackName}.`).toLowerCase();
15117
15127
  const suffix = `.${region}.json`.toLowerCase();
15118
15128
  return entries.some((f) => {
15119
15129
  const lower = f.toLowerCase();
15120
15130
  return lower.startsWith(prefix) && lower.endsWith(suffix);
15121
15131
  });
15122
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
+ }
15123
15152
  function safeStringifyJson(value) {
15124
15153
  const seen = /* @__PURE__ */ new WeakSet();
15125
15154
  const replacer = (_key, v) => {
@@ -15205,6 +15234,8 @@ async function runCheck(args) {
15205
15234
  };
15206
15235
  const separate = stackSeparator();
15207
15236
  const showProgress = !a.json && isInteractive();
15237
+ let callerAccount;
15238
+ let callerAccountResolved = false;
15208
15239
  for (const [idx, { stackName, region, template }] of stacks.entries()) {
15209
15240
  if (!region) {
15210
15241
  const msg = "no region — set env on the stack, pass --region, or set a region for the AWS profile";
@@ -15320,7 +15351,11 @@ async function runCheck(args) {
15320
15351
  worst = Math.max(worst, strictCoverageExit(a.strict, gathered.findings, desired.resources));
15321
15352
  } catch (e) {
15322
15353
  if (isStackNotDeployed(e)) {
15323
- if (hasBaselineForStack(stackName, region)) {
15354
+ if (!callerAccountResolved) {
15355
+ callerAccount = await resolveCallerAccount(region);
15356
+ callerAccountResolved = true;
15357
+ }
15358
+ if (hasBaselineForStack(stackName, region, callerAccount)) {
15324
15359
  const msg = "deployed baseline exists but the stack is gone — deleted out of band";
15325
15360
  const label = `${stackName} (${region})`;
15326
15361
  console.error(`[Drift] ${label}: ${msg}`);