cdk-real-drift 0.12.53 → 0.12.55
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 +13 -8
- package/dist/cli.js +258 -85
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -267,8 +267,10 @@ of an undeclared property, and is reconciled the same way against your baseline:
|
|
|
267
267
|
`cdk drift` / CFn drift detection compare only template-declared resources, so an
|
|
268
268
|
out-of-band addition is invisible to them. Decide it like any finding: `record`
|
|
269
269
|
snapshots its full live model and watches it, `ignore` accepts it, or `revert`
|
|
270
|
-
**deletes** it (Cloud Control `DeleteResource
|
|
271
|
-
|
|
270
|
+
**deletes** it (Cloud Control `DeleteResource` — or a type-specific SDK delete
|
|
271
|
+
where Cloud Control does not support the type's DELETE action, e.g. an AppSync
|
|
272
|
+
api key — behind the usual confirm / `--dry-run` / picker; an unrecorded one
|
|
273
|
+
needs `--remove-unrecorded`).
|
|
272
274
|
|
|
273
275
|
<details>
|
|
274
276
|
<summary>Covered parent types (the <code>CHILD_ENUMERATORS</code> registry, growing per type)</summary>
|
|
@@ -784,10 +786,11 @@ covers them. **If you never run `revert`, cdkrd needs no write permissions at al
|
|
|
784
786
|
`DescribeType`; `DescribeStackResources` (the sibling-ownership check for the
|
|
785
787
|
`added` tier — see the `added`-tier entry below); `ListExports` (only for
|
|
786
788
|
templates using `Fn::ImportValue`)
|
|
787
|
-
- `sts:GetCallerIdentity` (resolves the current account so
|
|
788
|
-
never deployed in THIS account from one deleted out of band, under the
|
|
789
|
-
multi-account baseline pattern —
|
|
790
|
-
|
|
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)
|
|
791
794
|
- `cloudcontrol:GetResource`: Cloud Control invokes each type's own read handler,
|
|
792
795
|
so it needs that type's read permissions (this is why `ReadOnlyAccess` is the
|
|
793
796
|
simple answer). `revert` additionally uses `cloudcontrol:UpdateResource` /
|
|
@@ -974,7 +977,7 @@ covers them. **If you never run `revert`, cdkrd needs no write permissions at al
|
|
|
974
977
|
`es:ListDomainNames`, `es:DescribeDomains` — a caller lacking these degrades
|
|
975
978
|
fail-safe (the service client is treated as corroborated, never falsely flagged)
|
|
976
979
|
- `AWS::AppSync::GraphQLApi`: `appsync:ListDataSources`, `appsync:ListResolvers`,
|
|
977
|
-
`appsync:ListFunctions`, `appsync:ListTypes`
|
|
980
|
+
`appsync:ListFunctions`, `appsync:ListTypes`, `appsync:ListApiKeys`
|
|
978
981
|
- `AWS::Logs::LogGroup`: `logs:DescribeSubscriptionFilters` (plus
|
|
979
982
|
`logs:DescribeMetricFilters`, already listed above)
|
|
980
983
|
- `AWS::ElasticLoadBalancingV2::LoadBalancer` + `::Listener`:
|
|
@@ -1008,7 +1011,9 @@ covers them. **If you never run `revert`, cdkrd needs no write permissions at al
|
|
|
1008
1011
|
|
|
1009
1012
|
`cloudcontrol:UpdateResource` (which resolves to each type's own update
|
|
1010
1013
|
permissions), `cloudcontrol:DeleteResource` (to delete an out-of-band `added`
|
|
1011
|
-
resource
|
|
1014
|
+
resource; a type Cloud Control cannot delete goes through its own SDK action
|
|
1015
|
+
instead — `appsync:DeleteApiKey` for an out-of-band `AWS::AppSync::ApiKey`), and
|
|
1016
|
+
`cloudcontrol:GetResourceRequestStatus` (to poll the async Cloud
|
|
1012
1017
|
Control request to completion). Plus, for the SDK-written types:
|
|
1013
1018
|
`s3:PutBucketPolicy` /
|
|
1014
1019
|
`s3:DeleteBucketPolicy`, `sns:SetTopicAttributes`, `sqs:SetQueueAttributes`,
|
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,12 +13,11 @@ 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";
|
|
18
19
|
import { AppConfigClient, ListConfigurationProfilesCommand, ListEnvironmentsCommand } from "@aws-sdk/client-appconfig";
|
|
19
|
-
import { AppSyncClient, ListApiKeysCommand, ListDataSourcesCommand, ListFunctionsCommand, ListResolversCommand, ListTypesCommand } from "@aws-sdk/client-appsync";
|
|
20
|
+
import { AppSyncClient, DeleteApiKeyCommand, ListApiKeysCommand, ListDataSourcesCommand, ListFunctionsCommand, ListResolversCommand, ListTypesCommand } from "@aws-sdk/client-appsync";
|
|
20
21
|
import { ApiGatewayV2Client, DeleteAccessLogSettingsCommand, DeleteRouteSettingsCommand, GetAuthorizersCommand as GetAuthorizersCommand$1, GetIntegrationsCommand, GetRoutesCommand, GetStagesCommand as GetStagesCommand$1, UpdateStageCommand } from "@aws-sdk/client-apigatewayv2";
|
|
21
22
|
import { CloudWatchLogsClient, DescribeMetricFiltersCommand, DescribeSubscriptionFiltersCommand, PutBearerTokenAuthenticationCommand, PutMetricFilterCommand } from "@aws-sdk/client-cloudwatch-logs";
|
|
22
23
|
import { CognitoIdentityProviderClient, ListGroupsCommand, ListIdentityProvidersCommand, ListResourceServersCommand, ListUserPoolClientsCommand } from "@aws-sdk/client-cognito-identity-provider";
|
|
@@ -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([
|
|
@@ -16018,6 +16122,19 @@ function resolveSdkWriter(resourceType, ops) {
|
|
|
16018
16122
|
const nested = SDK_NESTED_WRITERS[resourceType];
|
|
16019
16123
|
if (nested && ops[0] && nested.match(pointerToDotted(ops[0].path))) return nested.writer;
|
|
16020
16124
|
}
|
|
16125
|
+
const deleteAppSyncApiKey = async (ctx) => {
|
|
16126
|
+
const parent = ctx.parentPhysicalId;
|
|
16127
|
+
if (!parent) throw new Error("cannot resolve the parent GraphQLApi id for the AppSync ApiKey delete");
|
|
16128
|
+
const apiId = parent.includes("/") ? parent.slice(parent.lastIndexOf("/") + 1) : parent;
|
|
16129
|
+
await new AppSyncClient({
|
|
16130
|
+
region: ctx.region,
|
|
16131
|
+
...CLIENT_TIMEOUTS
|
|
16132
|
+
}).send(new DeleteApiKeyCommand({
|
|
16133
|
+
apiId,
|
|
16134
|
+
id: ctx.physicalId
|
|
16135
|
+
}));
|
|
16136
|
+
};
|
|
16137
|
+
const SDK_DELETERS = { "AWS::AppSync::ApiKey": deleteAppSyncApiKey };
|
|
16021
16138
|
|
|
16022
16139
|
//#endregion
|
|
16023
16140
|
//#region src/revert/plan.ts
|
|
@@ -16832,6 +16949,9 @@ async function applyRevertDelete(cc, item, identifier = item.physicalId, retry =
|
|
|
16832
16949
|
};
|
|
16833
16950
|
}
|
|
16834
16951
|
};
|
|
16952
|
+
return retryDeleteDeferringDependencies(oneDelete, retry);
|
|
16953
|
+
}
|
|
16954
|
+
async function retryDeleteDeferringDependencies(oneDelete, retry) {
|
|
16835
16955
|
let deferredDepError;
|
|
16836
16956
|
const guardedDelete = async () => {
|
|
16837
16957
|
const r = await oneDelete();
|
|
@@ -16851,6 +16971,21 @@ async function applyRevertDelete(cc, item, identifier = item.physicalId, retry =
|
|
|
16851
16971
|
};
|
|
16852
16972
|
return r;
|
|
16853
16973
|
}
|
|
16974
|
+
async function applyRevertDeleteSdk(doDelete, retry = {}) {
|
|
16975
|
+
const oneDelete = async () => {
|
|
16976
|
+
try {
|
|
16977
|
+
await doDelete();
|
|
16978
|
+
return { ok: true };
|
|
16979
|
+
} catch (e) {
|
|
16980
|
+
if (isAlreadyGone(e)) return { ok: true };
|
|
16981
|
+
return {
|
|
16982
|
+
ok: false,
|
|
16983
|
+
error: errorText(e)
|
|
16984
|
+
};
|
|
16985
|
+
}
|
|
16986
|
+
};
|
|
16987
|
+
return retryDeleteDeferringDependencies(oneDelete, retry);
|
|
16988
|
+
}
|
|
16854
16989
|
|
|
16855
16990
|
//#endregion
|
|
16856
16991
|
//#region src/commands/stack-actions.ts
|
|
@@ -17655,7 +17790,19 @@ async function revertStack(p) {
|
|
|
17655
17790
|
streamResultLine(item.logicalId);
|
|
17656
17791
|
}
|
|
17657
17792
|
const deleteDeadlineMs = waitMs !== void 0 ? clock() + waitMs : void 0;
|
|
17658
|
-
const deleteOutcomes = await applyRevertDeletes(deleteItems, (item) =>
|
|
17793
|
+
const deleteOutcomes = await applyRevertDeletes(deleteItems, (item) => {
|
|
17794
|
+
const sdkDeleter = SDK_DELETERS[item.resourceType];
|
|
17795
|
+
if (sdkDeleter) {
|
|
17796
|
+
const parentLogicalId = item.logicalId.split("/", 1)[0] ?? item.logicalId;
|
|
17797
|
+
const parentPhysicalId = resByLogical.get(parentLogicalId)?.physicalId;
|
|
17798
|
+
return applyRevertDeleteSdk(() => sdkDeleter({
|
|
17799
|
+
physicalId: item.physicalId,
|
|
17800
|
+
parentPhysicalId,
|
|
17801
|
+
region
|
|
17802
|
+
}), buildRetryOpts(item.displayId, deleteDeadlineMs));
|
|
17803
|
+
}
|
|
17804
|
+
return applyRevertDelete(cc, item, item.physicalId, buildRetryOpts(item.displayId, deleteDeadlineMs));
|
|
17805
|
+
});
|
|
17659
17806
|
for (const { item, result: r } of deleteOutcomes) {
|
|
17660
17807
|
if (!r.ok) failedDeleteIds.add(item.logicalId);
|
|
17661
17808
|
applied.push({
|
|
@@ -17790,7 +17937,8 @@ async function runRecord(args) {
|
|
|
17790
17937
|
let worst = 0;
|
|
17791
17938
|
let wroteAny = false;
|
|
17792
17939
|
const showProgress = !a.json && isInteractive();
|
|
17793
|
-
|
|
17940
|
+
const accountGate = createAccountGate("record");
|
|
17941
|
+
for (const [idx, { stackName, region, account, template }] of stacks.entries()) {
|
|
17794
17942
|
if (!region) {
|
|
17795
17943
|
const msg = "no region — set env on the stack, pass --region, or set a region for the AWS profile";
|
|
17796
17944
|
console.error(`error: ${stackName}: ${msg}`);
|
|
@@ -17804,7 +17952,29 @@ async function runRecord(args) {
|
|
|
17804
17952
|
continue;
|
|
17805
17953
|
}
|
|
17806
17954
|
try {
|
|
17955
|
+
const mismatch = await accountGate.preRead(account, region);
|
|
17956
|
+
if (mismatch.skip) {
|
|
17957
|
+
console.error(`note: ${stackName}: ${mismatch.message}`);
|
|
17958
|
+
if (a.json) jsonReports.push({
|
|
17959
|
+
stack: stackLabel(stackName, region),
|
|
17960
|
+
recorded: 0,
|
|
17961
|
+
wrote: false,
|
|
17962
|
+
error: mismatch.message
|
|
17963
|
+
});
|
|
17964
|
+
continue;
|
|
17965
|
+
}
|
|
17807
17966
|
const { desired, findings } = await gatherWithProgress(showProgress, progressLabel(idx, stacks.length, stackName, region), () => gatherFindings(stackName, region, void 0, template));
|
|
17967
|
+
const readMismatch = accountGate.postRead(account, desired.accountId);
|
|
17968
|
+
if (readMismatch.skip) {
|
|
17969
|
+
console.error(`note: ${stackName}: ${readMismatch.message}`);
|
|
17970
|
+
if (a.json) jsonReports.push({
|
|
17971
|
+
stack: stackLabel(stackName, region),
|
|
17972
|
+
recorded: 0,
|
|
17973
|
+
wrote: false,
|
|
17974
|
+
error: readMismatch.message
|
|
17975
|
+
});
|
|
17976
|
+
continue;
|
|
17977
|
+
}
|
|
17808
17978
|
warnStackStatus(stackName, desired.stackStatusWarning);
|
|
17809
17979
|
const result = await recordStack({
|
|
17810
17980
|
stackName,
|
|
@@ -17908,7 +18078,8 @@ async function runIgnore(args) {
|
|
|
17908
18078
|
let worst = 0;
|
|
17909
18079
|
let wroteAny = false;
|
|
17910
18080
|
const showProgress = !a.json && isInteractive();
|
|
17911
|
-
|
|
18081
|
+
const accountGate = createAccountGate("ignore");
|
|
18082
|
+
for (const [idx, { stackName, region, account, template }] of stacks.entries()) {
|
|
17912
18083
|
if (!region) {
|
|
17913
18084
|
const msg = "no region — set env on the stack, pass --region, or set a region for the AWS profile";
|
|
17914
18085
|
console.error(`error: ${stackName}: ${msg}`);
|
|
@@ -17922,7 +18093,29 @@ async function runIgnore(args) {
|
|
|
17922
18093
|
continue;
|
|
17923
18094
|
}
|
|
17924
18095
|
try {
|
|
18096
|
+
const mismatch = await accountGate.preRead(account, region);
|
|
18097
|
+
if (mismatch.skip) {
|
|
18098
|
+
console.error(`note: ${stackName}: ${mismatch.message}`);
|
|
18099
|
+
if (a.json) jsonReports.push({
|
|
18100
|
+
stack: stackLabel(stackName, region),
|
|
18101
|
+
added: 0,
|
|
18102
|
+
wrote: false,
|
|
18103
|
+
error: mismatch.message
|
|
18104
|
+
});
|
|
18105
|
+
continue;
|
|
18106
|
+
}
|
|
17925
18107
|
const { desired, findings } = await gatherWithProgress(showProgress, progressLabel(idx, stacks.length, stackName, region), () => gatherFindings(stackName, region, void 0, template));
|
|
18108
|
+
const readMismatch = accountGate.postRead(account, desired.accountId);
|
|
18109
|
+
if (readMismatch.skip) {
|
|
18110
|
+
console.error(`note: ${stackName}: ${readMismatch.message}`);
|
|
18111
|
+
if (a.json) jsonReports.push({
|
|
18112
|
+
stack: stackLabel(stackName, region),
|
|
18113
|
+
added: 0,
|
|
18114
|
+
wrote: false,
|
|
18115
|
+
error: readMismatch.message
|
|
18116
|
+
});
|
|
18117
|
+
continue;
|
|
18118
|
+
}
|
|
17926
18119
|
warnStackStatus(stackName, desired.stackStatusWarning);
|
|
17927
18120
|
const baseline = await loadBaseline(stackName, desired.accountId, region);
|
|
17928
18121
|
if (baseline) checkBaselineAccount(baseline, desired.accountId, stackName);
|
|
@@ -18623,55 +18816,6 @@ function hasBaselineForStack(stackName, region, accountId) {
|
|
|
18623
18816
|
return lower.startsWith(prefix) && lower.endsWith(suffix);
|
|
18624
18817
|
});
|
|
18625
18818
|
}
|
|
18626
|
-
/**
|
|
18627
|
-
* #1046: resolve the CURRENT account (region-free `sts:GetCallerIdentity`, a zero-permission
|
|
18628
|
-
* call) so `hasBaselineForStack` can pin the baseline filename's account segment. Returns
|
|
18629
|
-
* `undefined` on ANY failure (expired creds, blocked STS, network) so the caller falls back
|
|
18630
|
-
* to today's account-wildcard rather than erroring — a `check` that reached the not-deployed
|
|
18631
|
-
* catch already has working creds, so the STS call almost always succeeds. `--profile` is
|
|
18632
|
-
* already in `process.env.AWS_PROFILE` (set by the verb entry points), so the default
|
|
18633
|
-
* credential chain resolves it. Exported for unit tests.
|
|
18634
|
-
*/
|
|
18635
|
-
async function resolveCallerAccount(region) {
|
|
18636
|
-
try {
|
|
18637
|
-
return (await new STSClient({
|
|
18638
|
-
region,
|
|
18639
|
-
...CLIENT_TIMEOUTS
|
|
18640
|
-
}).send(new GetCallerIdentityCommand({}))).Account;
|
|
18641
|
-
} catch {
|
|
18642
|
-
return;
|
|
18643
|
-
}
|
|
18644
|
-
}
|
|
18645
|
-
/**
|
|
18646
|
-
* #740: decide whether a stack must be SKIPPED because it is pinned (via `env.account`) to a
|
|
18647
|
-
* different AWS account than the active credentials are for.
|
|
18648
|
-
*
|
|
18649
|
-
* A CDK app with dev+prod stacks in DIFFERENT accounts (the CDK Pipelines / multi-env staple)
|
|
18650
|
-
* is checked one account at a time — the caller runs `check --all` per account with that
|
|
18651
|
-
* account's credentials. A stack whose `env.account` names an OTHER account cannot be read
|
|
18652
|
-
* with the current creds: `DescribeStacks` throws "does not exist" (the stack IS deployed, just
|
|
18653
|
-
* in its own account), which `isStackNotDeployed` mistakes for "never deployed yet — skipped"
|
|
18654
|
-
* — a misleading green pass that hides an UNCHECKED stack. Worse, if a SAME-NAMED stack happens
|
|
18655
|
-
* to exist in the reachable account, cdkrd would silently compare intent against the WRONG
|
|
18656
|
-
* account's live resources. Detecting the mismatch UP FRONT lets check skip accurately without
|
|
18657
|
-
* reading the wrong account.
|
|
18658
|
-
*
|
|
18659
|
-
* Rule: skip ONLY when BOTH accounts are known (concrete) AND they differ — a proven mismatch.
|
|
18660
|
-
* When either is undefined (an env-agnostic stack with no account pin, or STS could not resolve
|
|
18661
|
-
* the caller) we CANNOT prove a mismatch, so we do NOT skip — behavior is identical to today
|
|
18662
|
-
* (the stack is read; a real "not deployed" still surfaces as before). Pure (no AWS) + exported
|
|
18663
|
-
* for unit tests.
|
|
18664
|
-
*/
|
|
18665
|
-
function classifyAccountMismatch(declaredAccount, callerAccount) {
|
|
18666
|
-
if (declaredAccount && callerAccount && declaredAccount !== callerAccount) return {
|
|
18667
|
-
skip: true,
|
|
18668
|
-
message: `stack is pinned to account ${declaredAccount} but the active credentials are for account ${callerAccount} — skipped (run with account-${declaredAccount} credentials to check it)`
|
|
18669
|
-
};
|
|
18670
|
-
return {
|
|
18671
|
-
skip: false,
|
|
18672
|
-
message: ""
|
|
18673
|
-
};
|
|
18674
|
-
}
|
|
18675
18819
|
function safeStringifyJson(value) {
|
|
18676
18820
|
const seen = /* @__PURE__ */ new WeakSet();
|
|
18677
18821
|
const replacer = (_key, v) => {
|
|
@@ -18795,10 +18939,10 @@ async function runCheck(args) {
|
|
|
18795
18939
|
const gathered = await gatherWithProgress(showProgress, progressLabel(idx, stacks.length, stackName, region), () => gatherFindings(stackName, region, synthTemplates?.get(sKey), template));
|
|
18796
18940
|
const { desired, schemas, liveByLogical } = gathered;
|
|
18797
18941
|
let findings = gathered.findings;
|
|
18798
|
-
|
|
18799
|
-
|
|
18800
|
-
console.error(`note: ${stackName}: ${
|
|
18801
|
-
jsonError(stackName, region,
|
|
18942
|
+
const readMismatch = classifyReadAccountMismatch(account, desired.accountId);
|
|
18943
|
+
if (readMismatch.skip) {
|
|
18944
|
+
console.error(`note: ${stackName}: ${readMismatch.message}`);
|
|
18945
|
+
jsonError(stackName, region, readMismatch.message);
|
|
18802
18946
|
worst = Math.max(worst, a.strict ? 1 : 0);
|
|
18803
18947
|
continue;
|
|
18804
18948
|
}
|
|
@@ -18963,7 +19107,8 @@ async function runRevert(args) {
|
|
|
18963
19107
|
const jsonReports = [];
|
|
18964
19108
|
let worst = 0;
|
|
18965
19109
|
const showProgress = !a.json && isInteractive();
|
|
18966
|
-
|
|
19110
|
+
const accountGate = createAccountGate("revert");
|
|
19111
|
+
for (const [idx, { stackName, region, account, template }] of stacks.entries()) {
|
|
18967
19112
|
if (!region) {
|
|
18968
19113
|
const msg = "no region — set env on the stack, pass --region, or set a region for the AWS profile";
|
|
18969
19114
|
console.error(`error: ${stackName}: ${msg}`);
|
|
@@ -18979,7 +19124,35 @@ async function runRevert(args) {
|
|
|
18979
19124
|
continue;
|
|
18980
19125
|
}
|
|
18981
19126
|
try {
|
|
19127
|
+
const mismatch = await accountGate.preRead(account, region);
|
|
19128
|
+
if (mismatch.skip) {
|
|
19129
|
+
console.error(`error: ${stackName}: ${mismatch.message}`);
|
|
19130
|
+
if (a.json) jsonReports.push({
|
|
19131
|
+
stack: stackLabel(stackName, region),
|
|
19132
|
+
reverted: 0,
|
|
19133
|
+
failed: 0,
|
|
19134
|
+
aborted: false,
|
|
19135
|
+
exit: 2,
|
|
19136
|
+
error: mismatch.message
|
|
19137
|
+
});
|
|
19138
|
+
worst = Math.max(worst, 2);
|
|
19139
|
+
continue;
|
|
19140
|
+
}
|
|
18982
19141
|
const gathered = await gatherWithProgress(showProgress, progressLabel(idx, stacks.length, stackName, region), () => gatherFindings(stackName, region, void 0, template));
|
|
19142
|
+
const readMismatch = accountGate.postRead(account, gathered.desired.accountId);
|
|
19143
|
+
if (readMismatch.skip) {
|
|
19144
|
+
console.error(`error: ${stackName}: ${readMismatch.message}`);
|
|
19145
|
+
if (a.json) jsonReports.push({
|
|
19146
|
+
stack: stackLabel(stackName, region),
|
|
19147
|
+
reverted: 0,
|
|
19148
|
+
failed: 0,
|
|
19149
|
+
aborted: false,
|
|
19150
|
+
exit: 2,
|
|
19151
|
+
error: readMismatch.message
|
|
19152
|
+
});
|
|
19153
|
+
worst = Math.max(worst, 2);
|
|
19154
|
+
continue;
|
|
19155
|
+
}
|
|
18983
19156
|
const baseline = await loadBaseline(stackName, gathered.desired.accountId, region);
|
|
18984
19157
|
if (baseline) checkBaselineAccount(baseline, gathered.desired.accountId, stackName);
|
|
18985
19158
|
warnStackStatus(stackName, gathered.desired.stackStatusWarning);
|