cdk-real-drift 0.12.54 → 0.12.56
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 +5 -4
- package/dist/cli.js +214 -83
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -786,10 +786,11 @@ covers them. **If you never run `revert`, cdkrd needs no write permissions at al
|
|
|
786
786
|
`DescribeType`; `DescribeStackResources` (the sibling-ownership check for the
|
|
787
787
|
`added` tier — see the `added`-tier entry below); `ListExports` (only for
|
|
788
788
|
templates using `Fn::ImportValue`)
|
|
789
|
-
- `sts:GetCallerIdentity` (resolves the current account so
|
|
790
|
-
never deployed in THIS account from one deleted out of band, under the
|
|
791
|
-
multi-account baseline pattern —
|
|
792
|
-
|
|
789
|
+
- `sts:GetCallerIdentity` (resolves the current account so every verb can tell a
|
|
790
|
+
stack never deployed in THIS account from one deleted out of band, under the
|
|
791
|
+
multi-account baseline pattern — `check`/`record`/`ignore` skip a stack pinned
|
|
792
|
+
to a different account and `revert` refuses to write to it; allowed for any
|
|
793
|
+
valid credentials, so no policy statement is normally required)
|
|
793
794
|
- `cloudcontrol:GetResource`: Cloud Control invokes each type's own read handler,
|
|
794
795
|
so it needs that type's read permissions (this is why `ReadOnlyAccess` is the
|
|
795
796
|
simple answer). `revert` additionally uses `cloudcontrol:UpdateResource` /
|
package/dist/cli.js
CHANGED
|
@@ -4,6 +4,8 @@ import { mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
|
|
|
4
4
|
import { dirname, join, resolve } from "node:path";
|
|
5
5
|
import { pid } from "node:process";
|
|
6
6
|
import { YAMLSeq, isSeq, parse, parseDocument } from "yaml";
|
|
7
|
+
import { GetCallerIdentityCommand, STSClient } from "@aws-sdk/client-sts";
|
|
8
|
+
import { createCredentialChain, fromEnv, fromNodeProviderChain } from "@aws-sdk/credential-providers";
|
|
7
9
|
import { CloudControlClient, DeleteResourceCommand, GetResourceCommand, GetResourceRequestStatusCommand, UpdateResourceCommand } from "@aws-sdk/client-cloudcontrol";
|
|
8
10
|
import { homedir } from "node:os";
|
|
9
11
|
import { BaseCredentials, CdkAppMultiContext, NonInteractiveIoHost, StackSelectionStrategy, Toolkit } from "@aws-cdk/toolkit-lib";
|
|
@@ -11,7 +13,6 @@ import { CloudFormationClient, DescribeStackResourcesCommand, DescribeStacksComm
|
|
|
11
13
|
import { DescribeAddressesCommand, DescribeClientVpnAuthorizationRulesCommand, DescribeClientVpnEndpointsCommand, DescribeClientVpnTargetNetworksCommand, DescribeInternetGatewaysCommand, DescribeLaunchTemplateVersionsCommand, DescribeNetworkAclsCommand, DescribeRouteTablesCommand, DescribeSecurityGroupsCommand, DescribeSubnetsCommand, DescribeVpcEndpointsCommand, DescribeVpcsCommand, EC2Client, ModifyClientVpnEndpointCommand } from "@aws-sdk/client-ec2";
|
|
12
14
|
import { DescribeDBClustersCommand, DescribeDBInstancesCommand, DescribeOptionGroupOptionsCommand, RDSClient } from "@aws-sdk/client-rds";
|
|
13
15
|
import { DescribeParametersCommand, GetParametersCommand, SSMClient } from "@aws-sdk/client-ssm";
|
|
14
|
-
import { createCredentialChain, fromEnv, fromNodeProviderChain } from "@aws-sdk/credential-providers";
|
|
15
16
|
import jsonata from "jsonata";
|
|
16
17
|
import { KMSClient, ListAliasesCommand } from "@aws-sdk/client-kms";
|
|
17
18
|
import { APIGatewayClient, GetAuthorizersCommand, GetGatewayResponsesCommand, GetModelsCommand, GetRequestValidatorsCommand, GetResourcesCommand, GetStagesCommand, UpdateIntegrationCommand, UpdateIntegrationResponseCommand, UpdateMethodResponseCommand, UpdateRestApiCommand } from "@aws-sdk/client-api-gateway";
|
|
@@ -61,7 +62,6 @@ import { CloudFrontClient, GetDistributionConfigCommand, UpdateDistributionComma
|
|
|
61
62
|
import { DescribeSignalingChannelCommand, DescribeStreamCommand, KinesisVideoClient, UpdateDataRetentionCommand, UpdateSignalingChannelCommand, UpdateStreamStorageConfigurationCommand } from "@aws-sdk/client-kinesis-video";
|
|
62
63
|
import { GetWebACLCommand, UpdateWebACLCommand, WAFV2Client } from "@aws-sdk/client-wafv2";
|
|
63
64
|
import { ConfigServiceClient, DescribeConfigRulesCommand, PutConfigRuleCommand } from "@aws-sdk/client-config-service";
|
|
64
|
-
import { GetCallerIdentityCommand, STSClient } from "@aws-sdk/client-sts";
|
|
65
65
|
|
|
66
66
|
//#region src/exit.ts
|
|
67
67
|
function drain(stream) {
|
|
@@ -932,6 +932,135 @@ function applyIgnores(findings, scope, config) {
|
|
|
932
932
|
});
|
|
933
933
|
}
|
|
934
934
|
|
|
935
|
+
//#endregion
|
|
936
|
+
//#region src/read/client-config.ts
|
|
937
|
+
/** Port of toolkit-lib awscli-compatible `shouldPrioritizeEnv()` (env creds win over profile). */
|
|
938
|
+
function shouldPrioritizeEnv() {
|
|
939
|
+
if (process.env.CDKRD_EXPLICIT_PROFILE) return false;
|
|
940
|
+
const id = process.env.AWS_ACCESS_KEY_ID || process.env.AMAZON_ACCESS_KEY_ID;
|
|
941
|
+
const key = process.env.AWS_SECRET_ACCESS_KEY || process.env.AMAZON_SECRET_ACCESS_KEY;
|
|
942
|
+
return !!id && !!key;
|
|
943
|
+
}
|
|
944
|
+
const CLIENT_REQUEST_HANDLER = {
|
|
945
|
+
connectionTimeout: 6e3,
|
|
946
|
+
requestTimeout: 6e4,
|
|
947
|
+
throwOnRequestTimeout: true
|
|
948
|
+
};
|
|
949
|
+
const CLIENT_CREDENTIALS = (awsIdentityProperties) => (shouldPrioritizeEnv() ? createCredentialChain(fromEnv(), fromNodeProviderChain({ clientConfig: { requestHandler: CLIENT_REQUEST_HANDLER } })) : fromNodeProviderChain({ clientConfig: { requestHandler: CLIENT_REQUEST_HANDLER } }))(awsIdentityProperties);
|
|
950
|
+
const CLIENT_TIMEOUTS = {
|
|
951
|
+
credentials: CLIENT_CREDENTIALS,
|
|
952
|
+
requestHandler: CLIENT_REQUEST_HANDLER
|
|
953
|
+
};
|
|
954
|
+
const READ_RETRY = {
|
|
955
|
+
maxAttempts: 10,
|
|
956
|
+
retryMode: "adaptive",
|
|
957
|
+
...CLIENT_TIMEOUTS
|
|
958
|
+
};
|
|
959
|
+
|
|
960
|
+
//#endregion
|
|
961
|
+
//#region src/commands/account-gate.ts
|
|
962
|
+
function mismatchTail(declaredAccount, verb) {
|
|
963
|
+
return verb === "revert" ? `refusing to revert (run with account-${declaredAccount} credentials to revert it)` : `skipped (run with account-${declaredAccount} credentials to ${verb} it)`;
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* #1046: resolve the CURRENT account (region-free `sts:GetCallerIdentity`, a zero-permission
|
|
967
|
+
* call) so `hasBaselineForStack` can pin the baseline filename's account segment. Returns
|
|
968
|
+
* `undefined` on ANY failure (expired creds, blocked STS, network) so the caller falls back
|
|
969
|
+
* to today's account-wildcard rather than erroring — a `check` that reached the not-deployed
|
|
970
|
+
* catch already has working creds, so the STS call almost always succeeds. `--profile` is
|
|
971
|
+
* already in `process.env.AWS_PROFILE` (set by the verb entry points), so the default
|
|
972
|
+
* credential chain resolves it. Exported for unit tests (moved here from check.ts, #1309).
|
|
973
|
+
*/
|
|
974
|
+
async function resolveCallerAccount(region) {
|
|
975
|
+
try {
|
|
976
|
+
return (await new STSClient({
|
|
977
|
+
region,
|
|
978
|
+
...CLIENT_TIMEOUTS
|
|
979
|
+
}).send(new GetCallerIdentityCommand({}))).Account;
|
|
980
|
+
} catch {
|
|
981
|
+
return;
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
/**
|
|
985
|
+
* #740: decide whether a stack must be SKIPPED because it is pinned (via `env.account`) to a
|
|
986
|
+
* different AWS account than the active credentials are for.
|
|
987
|
+
*
|
|
988
|
+
* A CDK app with dev+prod stacks in DIFFERENT accounts (the CDK Pipelines / multi-env staple)
|
|
989
|
+
* is checked one account at a time — the caller runs `check --all` per account with that
|
|
990
|
+
* account's credentials. A stack whose `env.account` names an OTHER account cannot be read
|
|
991
|
+
* with the current creds: `DescribeStacks` throws "does not exist" (the stack IS deployed, just
|
|
992
|
+
* in its own account), which `isStackNotDeployed` mistakes for "never deployed yet — skipped"
|
|
993
|
+
* — a misleading green pass that hides an UNCHECKED stack. Worse, if a SAME-NAMED stack happens
|
|
994
|
+
* to exist in the reachable account, cdkrd would silently compare intent against the WRONG
|
|
995
|
+
* account's live resources. Detecting the mismatch UP FRONT lets each verb act accurately
|
|
996
|
+
* without reading the wrong account.
|
|
997
|
+
*
|
|
998
|
+
* Rule: skip ONLY when BOTH accounts are known (concrete) AND they differ — a proven mismatch.
|
|
999
|
+
* When either is undefined (an env-agnostic stack with no account pin, or STS could not resolve
|
|
1000
|
+
* the caller) we CANNOT prove a mismatch, so we do NOT skip — behavior is identical to today
|
|
1001
|
+
* (the stack is read; a real "not deployed" still surfaces as before). `verb` only shapes the
|
|
1002
|
+
* message tail (#1309); the default keeps check's message byte-identical. Pure (no AWS) +
|
|
1003
|
+
* exported for unit tests (moved here from check.ts, #1309).
|
|
1004
|
+
*/
|
|
1005
|
+
function classifyAccountMismatch(declaredAccount, callerAccount, verb = "check") {
|
|
1006
|
+
if (declaredAccount && callerAccount && declaredAccount !== callerAccount) return {
|
|
1007
|
+
skip: true,
|
|
1008
|
+
message: `stack is pinned to account ${declaredAccount} but the active credentials are for account ${callerAccount} — ${mismatchTail(declaredAccount, verb)}`
|
|
1009
|
+
};
|
|
1010
|
+
return {
|
|
1011
|
+
skip: false,
|
|
1012
|
+
message: ""
|
|
1013
|
+
};
|
|
1014
|
+
}
|
|
1015
|
+
/**
|
|
1016
|
+
* #740 (belt-and-suspenders for case 2): the pre-read gate above skips a proven
|
|
1017
|
+
* cross-account mismatch, but if the caller account could not be resolved (STS blocked)
|
|
1018
|
+
* it lets the read proceed — and a SAME-NAMED stack in the reachable account would then
|
|
1019
|
+
* be compared against the WRONG account. After the read the deployed stack's account IS
|
|
1020
|
+
* known (`desired.accountId`); if this stack is pinned to a concrete account that differs,
|
|
1021
|
+
* the live state just read is the wrong account's — the verb must not trust it (report /
|
|
1022
|
+
* record / ignore / write against it). Defense-in-depth; the pre-read gate covers the
|
|
1023
|
+
* common case where the caller account IS known. Extracted from check.ts's inline guard
|
|
1024
|
+
* (#1309) so record/ignore/revert apply the identical rule; the default `verb` keeps
|
|
1025
|
+
* check's message byte-identical. Pure (no AWS) + exported for unit tests.
|
|
1026
|
+
*/
|
|
1027
|
+
function classifyReadAccountMismatch(declaredAccount, readAccountId, verb = "check") {
|
|
1028
|
+
if (declaredAccount && readAccountId !== declaredAccount) return {
|
|
1029
|
+
skip: true,
|
|
1030
|
+
message: `compared against account ${readAccountId} but the stack is pinned to ${declaredAccount} — ${mismatchTail(declaredAccount, verb)}`
|
|
1031
|
+
};
|
|
1032
|
+
return {
|
|
1033
|
+
skip: false,
|
|
1034
|
+
message: ""
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1037
|
+
/**
|
|
1038
|
+
* #1309: one per-run gate instance for a verb's stack loop. Mirrors check.ts's one-shot
|
|
1039
|
+
* caller-account resolution (`sts:GetCallerIdentity` is region-free — the account is the
|
|
1040
|
+
* same across regions — so the first answer is cached for every subsequent stack), but
|
|
1041
|
+
* LAZILY: the STS call only happens for a stack that actually carries an `env.account`
|
|
1042
|
+
* pin. An `undefined` cached answer (STS failed) is remembered too — the post-read guard
|
|
1043
|
+
* is the backstop for that case, exactly as in check.
|
|
1044
|
+
*/
|
|
1045
|
+
function createAccountGate(verb) {
|
|
1046
|
+
let callerAccount;
|
|
1047
|
+
let callerAccountResolved = false;
|
|
1048
|
+
return {
|
|
1049
|
+
preRead: async (declaredAccount, region) => {
|
|
1050
|
+
if (!declaredAccount) return {
|
|
1051
|
+
skip: false,
|
|
1052
|
+
message: ""
|
|
1053
|
+
};
|
|
1054
|
+
if (!callerAccountResolved) {
|
|
1055
|
+
callerAccount = await resolveCallerAccount(region);
|
|
1056
|
+
callerAccountResolved = true;
|
|
1057
|
+
}
|
|
1058
|
+
return classifyAccountMismatch(declaredAccount, callerAccount, verb);
|
|
1059
|
+
},
|
|
1060
|
+
postRead: (declaredAccount, readAccountId) => classifyReadAccountMismatch(declaredAccount, readAccountId, verb)
|
|
1061
|
+
};
|
|
1062
|
+
}
|
|
1063
|
+
|
|
935
1064
|
//#endregion
|
|
936
1065
|
//#region src/synth/resolve-app.ts
|
|
937
1066
|
function decodeCdkJson(buf) {
|
|
@@ -1833,31 +1962,6 @@ async function recordCorpusCase(dir, c) {
|
|
|
1833
1962
|
return p;
|
|
1834
1963
|
}
|
|
1835
1964
|
|
|
1836
|
-
//#endregion
|
|
1837
|
-
//#region src/read/client-config.ts
|
|
1838
|
-
/** Port of toolkit-lib awscli-compatible `shouldPrioritizeEnv()` (env creds win over profile). */
|
|
1839
|
-
function shouldPrioritizeEnv() {
|
|
1840
|
-
if (process.env.CDKRD_EXPLICIT_PROFILE) return false;
|
|
1841
|
-
const id = process.env.AWS_ACCESS_KEY_ID || process.env.AMAZON_ACCESS_KEY_ID;
|
|
1842
|
-
const key = process.env.AWS_SECRET_ACCESS_KEY || process.env.AMAZON_SECRET_ACCESS_KEY;
|
|
1843
|
-
return !!id && !!key;
|
|
1844
|
-
}
|
|
1845
|
-
const CLIENT_REQUEST_HANDLER = {
|
|
1846
|
-
connectionTimeout: 6e3,
|
|
1847
|
-
requestTimeout: 6e4,
|
|
1848
|
-
throwOnRequestTimeout: true
|
|
1849
|
-
};
|
|
1850
|
-
const CLIENT_CREDENTIALS = (awsIdentityProperties) => (shouldPrioritizeEnv() ? createCredentialChain(fromEnv(), fromNodeProviderChain({ clientConfig: { requestHandler: CLIENT_REQUEST_HANDLER } })) : fromNodeProviderChain({ clientConfig: { requestHandler: CLIENT_REQUEST_HANDLER } }))(awsIdentityProperties);
|
|
1851
|
-
const CLIENT_TIMEOUTS = {
|
|
1852
|
-
credentials: CLIENT_CREDENTIALS,
|
|
1853
|
-
requestHandler: CLIENT_REQUEST_HANDLER
|
|
1854
|
-
};
|
|
1855
|
-
const READ_RETRY = {
|
|
1856
|
-
maxAttempts: 10,
|
|
1857
|
-
retryMode: "adaptive",
|
|
1858
|
-
...CLIENT_TIMEOUTS
|
|
1859
|
-
};
|
|
1860
|
-
|
|
1861
1965
|
//#endregion
|
|
1862
1966
|
//#region src/normalize/cc-api-strip.ts
|
|
1863
1967
|
const ALWAYS_STRIPPED = new Set([
|
|
@@ -16080,6 +16184,7 @@ const REVERT_SET_DEFAULT_PATHS = new Set([
|
|
|
16080
16184
|
"AWS::EC2::Instance\0InstanceInitiatedShutdownBehavior",
|
|
16081
16185
|
"AWS::EC2::ClientVpnEndpoint\0VpnPort",
|
|
16082
16186
|
"AWS::EC2::ClientVpnEndpoint\0DisconnectOnSessionTimeout",
|
|
16187
|
+
"AWS::EC2::ClientVpnEndpoint\0SessionTimeoutHours",
|
|
16083
16188
|
"AWS::EC2::ClientVpnEndpoint\0SplitTunnel",
|
|
16084
16189
|
"AWS::DocDB::DBCluster\0Port",
|
|
16085
16190
|
"AWS::DocDB::DBCluster\0BackupRetentionPeriod",
|
|
@@ -17833,7 +17938,8 @@ async function runRecord(args) {
|
|
|
17833
17938
|
let worst = 0;
|
|
17834
17939
|
let wroteAny = false;
|
|
17835
17940
|
const showProgress = !a.json && isInteractive();
|
|
17836
|
-
|
|
17941
|
+
const accountGate = createAccountGate("record");
|
|
17942
|
+
for (const [idx, { stackName, region, account, template }] of stacks.entries()) {
|
|
17837
17943
|
if (!region) {
|
|
17838
17944
|
const msg = "no region — set env on the stack, pass --region, or set a region for the AWS profile";
|
|
17839
17945
|
console.error(`error: ${stackName}: ${msg}`);
|
|
@@ -17847,7 +17953,29 @@ async function runRecord(args) {
|
|
|
17847
17953
|
continue;
|
|
17848
17954
|
}
|
|
17849
17955
|
try {
|
|
17956
|
+
const mismatch = await accountGate.preRead(account, region);
|
|
17957
|
+
if (mismatch.skip) {
|
|
17958
|
+
console.error(`note: ${stackName}: ${mismatch.message}`);
|
|
17959
|
+
if (a.json) jsonReports.push({
|
|
17960
|
+
stack: stackLabel(stackName, region),
|
|
17961
|
+
recorded: 0,
|
|
17962
|
+
wrote: false,
|
|
17963
|
+
error: mismatch.message
|
|
17964
|
+
});
|
|
17965
|
+
continue;
|
|
17966
|
+
}
|
|
17850
17967
|
const { desired, findings } = await gatherWithProgress(showProgress, progressLabel(idx, stacks.length, stackName, region), () => gatherFindings(stackName, region, void 0, template));
|
|
17968
|
+
const readMismatch = accountGate.postRead(account, desired.accountId);
|
|
17969
|
+
if (readMismatch.skip) {
|
|
17970
|
+
console.error(`note: ${stackName}: ${readMismatch.message}`);
|
|
17971
|
+
if (a.json) jsonReports.push({
|
|
17972
|
+
stack: stackLabel(stackName, region),
|
|
17973
|
+
recorded: 0,
|
|
17974
|
+
wrote: false,
|
|
17975
|
+
error: readMismatch.message
|
|
17976
|
+
});
|
|
17977
|
+
continue;
|
|
17978
|
+
}
|
|
17851
17979
|
warnStackStatus(stackName, desired.stackStatusWarning);
|
|
17852
17980
|
const result = await recordStack({
|
|
17853
17981
|
stackName,
|
|
@@ -17951,7 +18079,8 @@ async function runIgnore(args) {
|
|
|
17951
18079
|
let worst = 0;
|
|
17952
18080
|
let wroteAny = false;
|
|
17953
18081
|
const showProgress = !a.json && isInteractive();
|
|
17954
|
-
|
|
18082
|
+
const accountGate = createAccountGate("ignore");
|
|
18083
|
+
for (const [idx, { stackName, region, account, template }] of stacks.entries()) {
|
|
17955
18084
|
if (!region) {
|
|
17956
18085
|
const msg = "no region — set env on the stack, pass --region, or set a region for the AWS profile";
|
|
17957
18086
|
console.error(`error: ${stackName}: ${msg}`);
|
|
@@ -17965,7 +18094,29 @@ async function runIgnore(args) {
|
|
|
17965
18094
|
continue;
|
|
17966
18095
|
}
|
|
17967
18096
|
try {
|
|
18097
|
+
const mismatch = await accountGate.preRead(account, region);
|
|
18098
|
+
if (mismatch.skip) {
|
|
18099
|
+
console.error(`note: ${stackName}: ${mismatch.message}`);
|
|
18100
|
+
if (a.json) jsonReports.push({
|
|
18101
|
+
stack: stackLabel(stackName, region),
|
|
18102
|
+
added: 0,
|
|
18103
|
+
wrote: false,
|
|
18104
|
+
error: mismatch.message
|
|
18105
|
+
});
|
|
18106
|
+
continue;
|
|
18107
|
+
}
|
|
17968
18108
|
const { desired, findings } = await gatherWithProgress(showProgress, progressLabel(idx, stacks.length, stackName, region), () => gatherFindings(stackName, region, void 0, template));
|
|
18109
|
+
const readMismatch = accountGate.postRead(account, desired.accountId);
|
|
18110
|
+
if (readMismatch.skip) {
|
|
18111
|
+
console.error(`note: ${stackName}: ${readMismatch.message}`);
|
|
18112
|
+
if (a.json) jsonReports.push({
|
|
18113
|
+
stack: stackLabel(stackName, region),
|
|
18114
|
+
added: 0,
|
|
18115
|
+
wrote: false,
|
|
18116
|
+
error: readMismatch.message
|
|
18117
|
+
});
|
|
18118
|
+
continue;
|
|
18119
|
+
}
|
|
17969
18120
|
warnStackStatus(stackName, desired.stackStatusWarning);
|
|
17970
18121
|
const baseline = await loadBaseline(stackName, desired.accountId, region);
|
|
17971
18122
|
if (baseline) checkBaselineAccount(baseline, desired.accountId, stackName);
|
|
@@ -18666,55 +18817,6 @@ function hasBaselineForStack(stackName, region, accountId) {
|
|
|
18666
18817
|
return lower.startsWith(prefix) && lower.endsWith(suffix);
|
|
18667
18818
|
});
|
|
18668
18819
|
}
|
|
18669
|
-
/**
|
|
18670
|
-
* #1046: resolve the CURRENT account (region-free `sts:GetCallerIdentity`, a zero-permission
|
|
18671
|
-
* call) so `hasBaselineForStack` can pin the baseline filename's account segment. Returns
|
|
18672
|
-
* `undefined` on ANY failure (expired creds, blocked STS, network) so the caller falls back
|
|
18673
|
-
* to today's account-wildcard rather than erroring — a `check` that reached the not-deployed
|
|
18674
|
-
* catch already has working creds, so the STS call almost always succeeds. `--profile` is
|
|
18675
|
-
* already in `process.env.AWS_PROFILE` (set by the verb entry points), so the default
|
|
18676
|
-
* credential chain resolves it. Exported for unit tests.
|
|
18677
|
-
*/
|
|
18678
|
-
async function resolveCallerAccount(region) {
|
|
18679
|
-
try {
|
|
18680
|
-
return (await new STSClient({
|
|
18681
|
-
region,
|
|
18682
|
-
...CLIENT_TIMEOUTS
|
|
18683
|
-
}).send(new GetCallerIdentityCommand({}))).Account;
|
|
18684
|
-
} catch {
|
|
18685
|
-
return;
|
|
18686
|
-
}
|
|
18687
|
-
}
|
|
18688
|
-
/**
|
|
18689
|
-
* #740: decide whether a stack must be SKIPPED because it is pinned (via `env.account`) to a
|
|
18690
|
-
* different AWS account than the active credentials are for.
|
|
18691
|
-
*
|
|
18692
|
-
* A CDK app with dev+prod stacks in DIFFERENT accounts (the CDK Pipelines / multi-env staple)
|
|
18693
|
-
* is checked one account at a time — the caller runs `check --all` per account with that
|
|
18694
|
-
* account's credentials. A stack whose `env.account` names an OTHER account cannot be read
|
|
18695
|
-
* with the current creds: `DescribeStacks` throws "does not exist" (the stack IS deployed, just
|
|
18696
|
-
* in its own account), which `isStackNotDeployed` mistakes for "never deployed yet — skipped"
|
|
18697
|
-
* — a misleading green pass that hides an UNCHECKED stack. Worse, if a SAME-NAMED stack happens
|
|
18698
|
-
* to exist in the reachable account, cdkrd would silently compare intent against the WRONG
|
|
18699
|
-
* account's live resources. Detecting the mismatch UP FRONT lets check skip accurately without
|
|
18700
|
-
* reading the wrong account.
|
|
18701
|
-
*
|
|
18702
|
-
* Rule: skip ONLY when BOTH accounts are known (concrete) AND they differ — a proven mismatch.
|
|
18703
|
-
* When either is undefined (an env-agnostic stack with no account pin, or STS could not resolve
|
|
18704
|
-
* the caller) we CANNOT prove a mismatch, so we do NOT skip — behavior is identical to today
|
|
18705
|
-
* (the stack is read; a real "not deployed" still surfaces as before). Pure (no AWS) + exported
|
|
18706
|
-
* for unit tests.
|
|
18707
|
-
*/
|
|
18708
|
-
function classifyAccountMismatch(declaredAccount, callerAccount) {
|
|
18709
|
-
if (declaredAccount && callerAccount && declaredAccount !== callerAccount) return {
|
|
18710
|
-
skip: true,
|
|
18711
|
-
message: `stack is pinned to account ${declaredAccount} but the active credentials are for account ${callerAccount} — skipped (run with account-${declaredAccount} credentials to check it)`
|
|
18712
|
-
};
|
|
18713
|
-
return {
|
|
18714
|
-
skip: false,
|
|
18715
|
-
message: ""
|
|
18716
|
-
};
|
|
18717
|
-
}
|
|
18718
18820
|
function safeStringifyJson(value) {
|
|
18719
18821
|
const seen = /* @__PURE__ */ new WeakSet();
|
|
18720
18822
|
const replacer = (_key, v) => {
|
|
@@ -18838,10 +18940,10 @@ async function runCheck(args) {
|
|
|
18838
18940
|
const gathered = await gatherWithProgress(showProgress, progressLabel(idx, stacks.length, stackName, region), () => gatherFindings(stackName, region, synthTemplates?.get(sKey), template));
|
|
18839
18941
|
const { desired, schemas, liveByLogical } = gathered;
|
|
18840
18942
|
let findings = gathered.findings;
|
|
18841
|
-
|
|
18842
|
-
|
|
18843
|
-
console.error(`note: ${stackName}: ${
|
|
18844
|
-
jsonError(stackName, region,
|
|
18943
|
+
const readMismatch = classifyReadAccountMismatch(account, desired.accountId);
|
|
18944
|
+
if (readMismatch.skip) {
|
|
18945
|
+
console.error(`note: ${stackName}: ${readMismatch.message}`);
|
|
18946
|
+
jsonError(stackName, region, readMismatch.message);
|
|
18845
18947
|
worst = Math.max(worst, a.strict ? 1 : 0);
|
|
18846
18948
|
continue;
|
|
18847
18949
|
}
|
|
@@ -19006,7 +19108,8 @@ async function runRevert(args) {
|
|
|
19006
19108
|
const jsonReports = [];
|
|
19007
19109
|
let worst = 0;
|
|
19008
19110
|
const showProgress = !a.json && isInteractive();
|
|
19009
|
-
|
|
19111
|
+
const accountGate = createAccountGate("revert");
|
|
19112
|
+
for (const [idx, { stackName, region, account, template }] of stacks.entries()) {
|
|
19010
19113
|
if (!region) {
|
|
19011
19114
|
const msg = "no region — set env on the stack, pass --region, or set a region for the AWS profile";
|
|
19012
19115
|
console.error(`error: ${stackName}: ${msg}`);
|
|
@@ -19022,7 +19125,35 @@ async function runRevert(args) {
|
|
|
19022
19125
|
continue;
|
|
19023
19126
|
}
|
|
19024
19127
|
try {
|
|
19128
|
+
const mismatch = await accountGate.preRead(account, region);
|
|
19129
|
+
if (mismatch.skip) {
|
|
19130
|
+
console.error(`error: ${stackName}: ${mismatch.message}`);
|
|
19131
|
+
if (a.json) jsonReports.push({
|
|
19132
|
+
stack: stackLabel(stackName, region),
|
|
19133
|
+
reverted: 0,
|
|
19134
|
+
failed: 0,
|
|
19135
|
+
aborted: false,
|
|
19136
|
+
exit: 2,
|
|
19137
|
+
error: mismatch.message
|
|
19138
|
+
});
|
|
19139
|
+
worst = Math.max(worst, 2);
|
|
19140
|
+
continue;
|
|
19141
|
+
}
|
|
19025
19142
|
const gathered = await gatherWithProgress(showProgress, progressLabel(idx, stacks.length, stackName, region), () => gatherFindings(stackName, region, void 0, template));
|
|
19143
|
+
const readMismatch = accountGate.postRead(account, gathered.desired.accountId);
|
|
19144
|
+
if (readMismatch.skip) {
|
|
19145
|
+
console.error(`error: ${stackName}: ${readMismatch.message}`);
|
|
19146
|
+
if (a.json) jsonReports.push({
|
|
19147
|
+
stack: stackLabel(stackName, region),
|
|
19148
|
+
reverted: 0,
|
|
19149
|
+
failed: 0,
|
|
19150
|
+
aborted: false,
|
|
19151
|
+
exit: 2,
|
|
19152
|
+
error: readMismatch.message
|
|
19153
|
+
});
|
|
19154
|
+
worst = Math.max(worst, 2);
|
|
19155
|
+
continue;
|
|
19156
|
+
}
|
|
19026
19157
|
const baseline = await loadBaseline(stackName, gathered.desired.accountId, region);
|
|
19027
19158
|
if (baseline) checkBaselineAccount(baseline, gathered.desired.accountId, stackName);
|
|
19028
19159
|
warnStackStatus(stackName, gathered.desired.stackStatusWarning);
|