cdk-real-drift 0.6.1 → 0.7.0
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/dist/cli.js +199 -138
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -9,8 +9,8 @@ import { homedir } from "node:os";
|
|
|
9
9
|
import { BaseCredentials, CdkAppMultiContext, NonInteractiveIoHost, StackSelectionStrategy, Toolkit } from "@aws-cdk/toolkit-lib";
|
|
10
10
|
import { CloudFormationClient, DescribeStackResourcesCommand, DescribeStacksCommand, DescribeTypeCommand, GetTemplateCommand, ListExportsCommand, ListStackResourcesCommand } from "@aws-sdk/client-cloudformation";
|
|
11
11
|
import jsonata from "jsonata";
|
|
12
|
-
import { createCredentialChain, fromEnv, fromNodeProviderChain } from "@aws-sdk/credential-providers";
|
|
13
12
|
import { KMSClient, ListAliasesCommand } from "@aws-sdk/client-kms";
|
|
13
|
+
import { createCredentialChain, fromEnv, fromNodeProviderChain } from "@aws-sdk/credential-providers";
|
|
14
14
|
import { APIGatewayClient, GetAuthorizersCommand, GetGatewayResponsesCommand, GetModelsCommand, GetRequestValidatorsCommand, GetResourcesCommand, GetStagesCommand, UpdateIntegrationCommand, UpdateIntegrationResponseCommand, UpdateMethodResponseCommand, UpdateRestApiCommand } from "@aws-sdk/client-api-gateway";
|
|
15
15
|
import { AppConfigClient, ListConfigurationProfilesCommand, ListEnvironmentsCommand } from "@aws-sdk/client-appconfig";
|
|
16
16
|
import { AppSyncClient, ListApiKeysCommand, ListDataSourcesCommand, ListFunctionsCommand, ListResolversCommand, ListTypesCommand } from "@aws-sdk/client-appsync";
|
|
@@ -33,7 +33,7 @@ import { CognitoSyncClient, GetCognitoEventsCommand, SetCognitoEventsCommand } f
|
|
|
33
33
|
import { BatchGetProjectsCommand, BatchGetReportGroupsCommand, CodeBuildClient, UpdateReportGroupCommand } from "@aws-sdk/client-codebuild";
|
|
34
34
|
import { DescribeDBClustersCommand as DescribeDBClustersCommand$1, DescribeDBInstancesCommand as DescribeDBInstancesCommand$1, DocDBClient, ModifyDBClusterCommand, ModifyDBInstanceCommand } from "@aws-sdk/client-docdb";
|
|
35
35
|
import { DAXClient, DescribeClustersCommand, DescribeParameterGroupsCommand, DescribeParametersCommand, DescribeSubnetGroupsCommand, UpdateClusterCommand, UpdateParameterGroupCommand } from "@aws-sdk/client-dax";
|
|
36
|
-
import { GetClassifierCommand, GetConnectionCommand, GetJobCommand, GetTableCommand, GetWorkflowCommand, GlueClient, UpdateClassifierCommand, UpdateConnectionCommand, UpdateJobCommand, UpdateTableCommand, UpdateWorkflowCommand } from "@aws-sdk/client-glue";
|
|
36
|
+
import { GetClassifierCommand, GetConnectionCommand, GetJobCommand, GetSecurityConfigurationCommand, GetTableCommand, GetWorkflowCommand, GlueClient, UpdateClassifierCommand, UpdateConnectionCommand, UpdateJobCommand, UpdateTableCommand, UpdateWorkflowCommand } from "@aws-sdk/client-glue";
|
|
37
37
|
import { AttachGroupPolicyCommand, AttachRolePolicyCommand, AttachUserPolicyCommand, CreatePolicyVersionCommand, DeletePolicyVersionCommand, DeleteRolePolicyCommand, DetachGroupPolicyCommand, DetachRolePolicyCommand, DetachUserPolicyCommand, GetGroupPolicyCommand, GetPolicyCommand as GetPolicyCommand$1, GetPolicyVersionCommand, GetRolePolicyCommand, GetUserPolicyCommand, IAMClient, ListAccessKeysCommand, ListEntitiesForPolicyCommand, ListPolicyVersionsCommand, PutGroupPolicyCommand, PutRolePolicyCommand, PutUserPolicyCommand } from "@aws-sdk/client-iam";
|
|
38
38
|
import { DeleteBucketPolicyCommand, GetBucketPolicyCommand, PutBucketPolicyCommand, S3Client } from "@aws-sdk/client-s3";
|
|
39
39
|
import { DescribeCacheClustersCommand, DescribeCacheParameterGroupsCommand, DescribeCacheParametersCommand, DescribeReplicationGroupsCommand, DescribeUsersCommand, ElastiCacheClient, ModifyCacheParameterGroupCommand, ResetCacheParameterGroupCommand } from "@aws-sdk/client-elasticache";
|
|
@@ -4244,11 +4244,11 @@ function arnMatchesName(arn, name, opts) {
|
|
|
4244
4244
|
return true;
|
|
4245
4245
|
}
|
|
4246
4246
|
const KMS_KEY_ARN_RE = /^arn:aws[a-z-]*:kms:[^:]*:\d*:key\//;
|
|
4247
|
-
const keyIdOf = (s) => s.slice(s.lastIndexOf("/") + 1);
|
|
4247
|
+
const keyIdOf$1 = (s) => s.slice(s.lastIndexOf("/") + 1);
|
|
4248
4248
|
function isManagedKmsAliasMatch(desired, actual, aliasTargets) {
|
|
4249
4249
|
if (typeof desired !== "string" || typeof actual !== "string" || !desired.startsWith("alias/aws/") || !KMS_KEY_ARN_RE.test(actual)) return false;
|
|
4250
4250
|
const target = aliasTargets?.[desired];
|
|
4251
|
-
if (target) return keyIdOf(actual) === keyIdOf(target);
|
|
4251
|
+
if (target) return keyIdOf$1(actual) === keyIdOf$1(target);
|
|
4252
4252
|
return true;
|
|
4253
4253
|
}
|
|
4254
4254
|
const LOG_GROUP_ARN_RE = /^arn:aws[a-z-]*:logs:[^:]*:\d*:log-group:/;
|
|
@@ -4312,6 +4312,165 @@ function stripWalk(value, freeForm) {
|
|
|
4312
4312
|
return value;
|
|
4313
4313
|
}
|
|
4314
4314
|
|
|
4315
|
+
//#endregion
|
|
4316
|
+
//#region src/read/client-config.ts
|
|
4317
|
+
/** Port of toolkit-lib awscli-compatible `shouldPrioritizeEnv()` (env creds win over profile). */
|
|
4318
|
+
function shouldPrioritizeEnv() {
|
|
4319
|
+
if (process.env.CDKRD_EXPLICIT_PROFILE) return false;
|
|
4320
|
+
const id = process.env.AWS_ACCESS_KEY_ID || process.env.AMAZON_ACCESS_KEY_ID;
|
|
4321
|
+
const key = process.env.AWS_SECRET_ACCESS_KEY || process.env.AMAZON_SECRET_ACCESS_KEY;
|
|
4322
|
+
return !!id && !!key;
|
|
4323
|
+
}
|
|
4324
|
+
const CLIENT_CREDENTIALS = (awsIdentityProperties) => (shouldPrioritizeEnv() ? createCredentialChain(fromEnv(), fromNodeProviderChain()) : fromNodeProviderChain())(awsIdentityProperties);
|
|
4325
|
+
const CLIENT_TIMEOUTS = {
|
|
4326
|
+
credentials: CLIENT_CREDENTIALS,
|
|
4327
|
+
requestHandler: {
|
|
4328
|
+
connectionTimeout: 6e3,
|
|
4329
|
+
requestTimeout: 6e4,
|
|
4330
|
+
throwOnRequestTimeout: true
|
|
4331
|
+
}
|
|
4332
|
+
};
|
|
4333
|
+
const READ_RETRY = {
|
|
4334
|
+
maxAttempts: 10,
|
|
4335
|
+
retryMode: "adaptive",
|
|
4336
|
+
...CLIENT_TIMEOUTS
|
|
4337
|
+
};
|
|
4338
|
+
|
|
4339
|
+
//#endregion
|
|
4340
|
+
//#region src/read/kms-aliases.ts
|
|
4341
|
+
const cache$1 = /* @__PURE__ */ new Map();
|
|
4342
|
+
/** True when the error is a DEFINITIVE access-denial (cacheable), NOT a transient blip.
|
|
4343
|
+
* Matches an AccessDenied(Exception) / UnauthorizedOperation by name or code, or the AWS
|
|
4344
|
+
* HTTP 403 status. Anything else (throttle, network, 5xx, timeout) is treated as
|
|
4345
|
+
* transient and must NOT be cached. */
|
|
4346
|
+
function isDefinitiveDenial(err) {
|
|
4347
|
+
const e = err;
|
|
4348
|
+
if (!e) return false;
|
|
4349
|
+
const definitive = /^(AccessDenied(Exception)?|UnauthorizedOperation)$/;
|
|
4350
|
+
if (e.name && definitive.test(e.name)) return true;
|
|
4351
|
+
if (e.code && definitive.test(e.code)) return true;
|
|
4352
|
+
return e.$metadata?.httpStatusCode === 403;
|
|
4353
|
+
}
|
|
4354
|
+
async function fetchManagedAliasTargets(region) {
|
|
4355
|
+
const cached = cache$1.get(region);
|
|
4356
|
+
if (cached) return cached;
|
|
4357
|
+
const targets = {};
|
|
4358
|
+
try {
|
|
4359
|
+
const c = new KMSClient({
|
|
4360
|
+
region,
|
|
4361
|
+
...READ_RETRY
|
|
4362
|
+
});
|
|
4363
|
+
let marker;
|
|
4364
|
+
do {
|
|
4365
|
+
const r = await c.send(new ListAliasesCommand({
|
|
4366
|
+
Marker: marker,
|
|
4367
|
+
Limit: 100
|
|
4368
|
+
}));
|
|
4369
|
+
for (const a of r.Aliases ?? []) if (a.AliasName?.startsWith("alias/aws/") && a.TargetKeyId) targets[a.AliasName] = a.TargetKeyId;
|
|
4370
|
+
marker = r.Truncated ? r.NextMarker : void 0;
|
|
4371
|
+
} while (marker);
|
|
4372
|
+
const result = {
|
|
4373
|
+
targets,
|
|
4374
|
+
denied: false
|
|
4375
|
+
};
|
|
4376
|
+
cache$1.set(region, result);
|
|
4377
|
+
return result;
|
|
4378
|
+
} catch (e) {
|
|
4379
|
+
if (isDefinitiveDenial(e)) {
|
|
4380
|
+
const result = {
|
|
4381
|
+
targets: {},
|
|
4382
|
+
denied: true
|
|
4383
|
+
};
|
|
4384
|
+
cache$1.set(region, result);
|
|
4385
|
+
return result;
|
|
4386
|
+
}
|
|
4387
|
+
return {
|
|
4388
|
+
targets: {},
|
|
4389
|
+
denied: true,
|
|
4390
|
+
transient: true
|
|
4391
|
+
};
|
|
4392
|
+
}
|
|
4393
|
+
}
|
|
4394
|
+
/** The one-line warning emitted when ListAliases is denied but the stack declares an
|
|
4395
|
+
* AWS-managed alias: the managed-vs-customer key check degrades to shape-only, which
|
|
4396
|
+
* is BLIND to a customer-managed key swapped in for an `alias/aws/*` default. Pure +
|
|
4397
|
+
* exported so the wording is unit-tested. */
|
|
4398
|
+
function kmsListAliasesDeniedWarning(region) {
|
|
4399
|
+
return `warning: ${region}: kms:ListAliases denied — managed-KMS-alias drift detection is degraded. A customer-managed key swapped in for an AWS-managed default (alias/aws/*) will NOT be detected (every alias/aws/* is treated as matching any live key). Grant kms:ListAliases for full coverage.`;
|
|
4400
|
+
}
|
|
4401
|
+
/** The one-line warning emitted when ListAliases fails TRANSIENTLY (throttle / network
|
|
4402
|
+
* blip / 5xx) for a stack that declares an AWS-managed alias: the managed-vs-customer
|
|
4403
|
+
* key check is degraded for THIS stack only — the error is NOT an IAM denial, and the
|
|
4404
|
+
* region is not poisoned, so the next stack retries. Pure + exported so the wording is
|
|
4405
|
+
* unit-tested. */
|
|
4406
|
+
function kmsListAliasesTransientWarning(region) {
|
|
4407
|
+
return `warning: ${region}: kms:ListAliases failed transiently (throttle/network) — managed-KMS-alias drift detection is degraded for THIS stack and will be retried for the next stack in the region. This is NOT an IAM permission problem; no action is needed.`;
|
|
4408
|
+
}
|
|
4409
|
+
/** Pure decision for the gather-time KMS warning: given a resolved ListAliases outcome
|
|
4410
|
+
* and the two per-region dedupe sets' membership, decide WHICH warning to emit (if any)
|
|
4411
|
+
* and WHICH set to stamp. The split is the #963 fix: a TRANSIENT failure must warn with
|
|
4412
|
+
* the transient message and stamp ONLY the transient set — it must NOT stamp the
|
|
4413
|
+
* permanent-denial set, or a later stack's GENUINE denial in the same region would be
|
|
4414
|
+
* silenced. Transient and denied dedupe independently (separate sets) so neither masks
|
|
4415
|
+
* the other. `warning` is null when nothing should print (not denied, or already warned
|
|
4416
|
+
* in that region). */
|
|
4417
|
+
function kmsWarnDecision(region, resolved, deniedWarned, transientWarned) {
|
|
4418
|
+
if (!resolved.denied) return {
|
|
4419
|
+
warning: null,
|
|
4420
|
+
stampDenied: false,
|
|
4421
|
+
stampTransient: false
|
|
4422
|
+
};
|
|
4423
|
+
if (resolved.transient) return {
|
|
4424
|
+
warning: transientWarned ? null : kmsListAliasesTransientWarning(region),
|
|
4425
|
+
stampDenied: false,
|
|
4426
|
+
stampTransient: !transientWarned
|
|
4427
|
+
};
|
|
4428
|
+
return {
|
|
4429
|
+
warning: deniedWarned ? null : kmsListAliasesDeniedWarning(region),
|
|
4430
|
+
stampDenied: !deniedWarned,
|
|
4431
|
+
stampTransient: false
|
|
4432
|
+
};
|
|
4433
|
+
}
|
|
4434
|
+
const MANAGED_KEY_ALIAS_PATHS = {
|
|
4435
|
+
"AWS::DynamoDB::Table": { "SSESpecification.KMSMasterKeyId": "alias/aws/dynamodb" },
|
|
4436
|
+
"AWS::DynamoDB::GlobalTable": { "Replicas.*.SSESpecification.KMSMasterKeyId": "alias/aws/dynamodb" },
|
|
4437
|
+
"AWS::OpenSearchService::Domain": { "EncryptionAtRestOptions.KmsKeyId": "alias/aws/es" }
|
|
4438
|
+
};
|
|
4439
|
+
const keyIdOf = (s) => s.slice(s.lastIndexOf("/") + 1);
|
|
4440
|
+
/** #704 fold decision for an UNDECLARED managed-service-key nested path (DynamoDB SSE,
|
|
4441
|
+
* OpenSearch EncryptionAtRest). Returns whether the value-independent fold should still
|
|
4442
|
+
* apply for this live value:
|
|
4443
|
+
* - `true` → FOLD (atDefault): the live key IS the account/region AWS-managed key, OR the
|
|
4444
|
+
* alias could not be resolved (fail OPEN — no ListAliases / denied / transient).
|
|
4445
|
+
* - `false` → SURFACE (undeclared): the live key is some OTHER key (a customer-managed key
|
|
4446
|
+
* swapped in out of band — a real, security-relevant drift).
|
|
4447
|
+
* Pure; `aliasTargets` is the resolved alias-name -> target-key-id map (empty when unresolved).*/
|
|
4448
|
+
function shouldFoldManagedServiceKey(resourceType, schemaPath, liveValue, aliasTargets) {
|
|
4449
|
+
const alias = MANAGED_KEY_ALIAS_PATHS[resourceType]?.[schemaPath];
|
|
4450
|
+
if (!alias) return false;
|
|
4451
|
+
const target = aliasTargets?.[alias];
|
|
4452
|
+
if (!target) return true;
|
|
4453
|
+
if (typeof liveValue !== "string") return true;
|
|
4454
|
+
return keyIdOf(liveValue) === keyIdOf(target);
|
|
4455
|
+
}
|
|
4456
|
+
/** #704: True when a resource TYPE has an UNDECLARED managed-service-key nested path
|
|
4457
|
+
* (DynamoDB SSE, OpenSearch EncryptionAtRest) whose value-independent fold must be gated
|
|
4458
|
+
* against the resolved AWS-managed key — so a ListAliases prefetch is worth doing even when
|
|
4459
|
+
* NO `alias/aws/*` is DECLARED. gather.ts's prefetch trigger should OR this in alongside the
|
|
4460
|
+
* declared-alias check (`usesManagedKmsAlias`) so the LIVE-only managed-key path is resolvable.
|
|
4461
|
+
*/
|
|
4462
|
+
function typeNeedsManagedKeyResolution(resourceType) {
|
|
4463
|
+
return resourceType in MANAGED_KEY_ALIAS_PATHS;
|
|
4464
|
+
}
|
|
4465
|
+
/** True when any resolved declared value in the stack references an AWS-managed KMS
|
|
4466
|
+
* alias, i.e. a ListAliases prefetch is worth doing. */
|
|
4467
|
+
function usesManagedKmsAlias(v) {
|
|
4468
|
+
if (typeof v === "string") return v.startsWith("alias/aws/");
|
|
4469
|
+
if (Array.isArray(v)) return v.some(usesManagedKmsAlias);
|
|
4470
|
+
if (v && typeof v === "object") return Object.values(v).some(usesManagedKmsAlias);
|
|
4471
|
+
return false;
|
|
4472
|
+
}
|
|
4473
|
+
|
|
4315
4474
|
//#endregion
|
|
4316
4475
|
//#region src/normalize/path-strip.ts
|
|
4317
4476
|
function deepStripPaths(obj, paths) {
|
|
@@ -5278,7 +5437,7 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
|
|
|
5278
5437
|
if (!isObjectForm || /tags$/i.test(parentKey)) return;
|
|
5279
5438
|
}
|
|
5280
5439
|
const schemaPath = path.replace(/\[[^\]]*\]/g, ".*");
|
|
5281
|
-
const tier = schemaPath in schema.defaultPaths && matchesKnownDefault(value, schema.defaultPaths[schemaPath]) || schemaPath in knownDefPaths && matchesKnownDefault(value, knownDefPaths[schemaPath]) || (KNOWN_DEFAULT_ONE_OF_PATHS[resourceType]?.[schemaPath]?.some((d) => matchesKnownDefault(value, d)) ?? false) || dynamoGsiWarmThroughputAtDefault(resourceType, path, value, live) ? "atDefault" : generatedPaths.includes(schemaPath) && isPhysicalIdSegment(value, physicalId) || generatedNestedPaths?.has(schemaPath) && !(schemaPath in knownDefPaths) ? "generated" : "undeclared";
|
|
5440
|
+
const tier = schemaPath in schema.defaultPaths && matchesKnownDefault(value, schema.defaultPaths[schemaPath]) || schemaPath in knownDefPaths && matchesKnownDefault(value, knownDefPaths[schemaPath]) || (KNOWN_DEFAULT_ONE_OF_PATHS[resourceType]?.[schemaPath]?.some((d) => matchesKnownDefault(value, d)) ?? false) || dynamoGsiWarmThroughputAtDefault(resourceType, path, value, live) ? "atDefault" : generatedPaths.includes(schemaPath) && isPhysicalIdSegment(value, physicalId) || generatedNestedPaths?.has(schemaPath) && !(schemaPath in knownDefPaths) && (!(schemaPath in (MANAGED_KEY_ALIAS_PATHS[resourceType] ?? {})) || shouldFoldManagedServiceKey(resourceType, schemaPath, value, opts.kmsAliasTargets)) ? "generated" : "undeclared";
|
|
5282
5441
|
const freeFormKey = tier === "undeclared" && underFreeFormMap(schemaPath);
|
|
5283
5442
|
findings.push({
|
|
5284
5443
|
tier,
|
|
@@ -5843,134 +6002,6 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
|
|
|
5843
6002
|
}));
|
|
5844
6003
|
}
|
|
5845
6004
|
|
|
5846
|
-
//#endregion
|
|
5847
|
-
//#region src/read/client-config.ts
|
|
5848
|
-
/** Port of toolkit-lib awscli-compatible `shouldPrioritizeEnv()` (env creds win over profile). */
|
|
5849
|
-
function shouldPrioritizeEnv() {
|
|
5850
|
-
if (process.env.CDKRD_EXPLICIT_PROFILE) return false;
|
|
5851
|
-
const id = process.env.AWS_ACCESS_KEY_ID || process.env.AMAZON_ACCESS_KEY_ID;
|
|
5852
|
-
const key = process.env.AWS_SECRET_ACCESS_KEY || process.env.AMAZON_SECRET_ACCESS_KEY;
|
|
5853
|
-
return !!id && !!key;
|
|
5854
|
-
}
|
|
5855
|
-
const CLIENT_CREDENTIALS = (awsIdentityProperties) => (shouldPrioritizeEnv() ? createCredentialChain(fromEnv(), fromNodeProviderChain()) : fromNodeProviderChain())(awsIdentityProperties);
|
|
5856
|
-
const CLIENT_TIMEOUTS = {
|
|
5857
|
-
credentials: CLIENT_CREDENTIALS,
|
|
5858
|
-
requestHandler: {
|
|
5859
|
-
connectionTimeout: 6e3,
|
|
5860
|
-
requestTimeout: 6e4,
|
|
5861
|
-
throwOnRequestTimeout: true
|
|
5862
|
-
}
|
|
5863
|
-
};
|
|
5864
|
-
const READ_RETRY = {
|
|
5865
|
-
maxAttempts: 10,
|
|
5866
|
-
retryMode: "adaptive",
|
|
5867
|
-
...CLIENT_TIMEOUTS
|
|
5868
|
-
};
|
|
5869
|
-
|
|
5870
|
-
//#endregion
|
|
5871
|
-
//#region src/read/kms-aliases.ts
|
|
5872
|
-
const cache$1 = /* @__PURE__ */ new Map();
|
|
5873
|
-
/** True when the error is a DEFINITIVE access-denial (cacheable), NOT a transient blip.
|
|
5874
|
-
* Matches an AccessDenied(Exception) / UnauthorizedOperation by name or code, or the AWS
|
|
5875
|
-
* HTTP 403 status. Anything else (throttle, network, 5xx, timeout) is treated as
|
|
5876
|
-
* transient and must NOT be cached. */
|
|
5877
|
-
function isDefinitiveDenial(err) {
|
|
5878
|
-
const e = err;
|
|
5879
|
-
if (!e) return false;
|
|
5880
|
-
const definitive = /^(AccessDenied(Exception)?|UnauthorizedOperation)$/;
|
|
5881
|
-
if (e.name && definitive.test(e.name)) return true;
|
|
5882
|
-
if (e.code && definitive.test(e.code)) return true;
|
|
5883
|
-
return e.$metadata?.httpStatusCode === 403;
|
|
5884
|
-
}
|
|
5885
|
-
async function fetchManagedAliasTargets(region) {
|
|
5886
|
-
const cached = cache$1.get(region);
|
|
5887
|
-
if (cached) return cached;
|
|
5888
|
-
const targets = {};
|
|
5889
|
-
try {
|
|
5890
|
-
const c = new KMSClient({
|
|
5891
|
-
region,
|
|
5892
|
-
...READ_RETRY
|
|
5893
|
-
});
|
|
5894
|
-
let marker;
|
|
5895
|
-
do {
|
|
5896
|
-
const r = await c.send(new ListAliasesCommand({
|
|
5897
|
-
Marker: marker,
|
|
5898
|
-
Limit: 100
|
|
5899
|
-
}));
|
|
5900
|
-
for (const a of r.Aliases ?? []) if (a.AliasName?.startsWith("alias/aws/") && a.TargetKeyId) targets[a.AliasName] = a.TargetKeyId;
|
|
5901
|
-
marker = r.Truncated ? r.NextMarker : void 0;
|
|
5902
|
-
} while (marker);
|
|
5903
|
-
const result = {
|
|
5904
|
-
targets,
|
|
5905
|
-
denied: false
|
|
5906
|
-
};
|
|
5907
|
-
cache$1.set(region, result);
|
|
5908
|
-
return result;
|
|
5909
|
-
} catch (e) {
|
|
5910
|
-
if (isDefinitiveDenial(e)) {
|
|
5911
|
-
const result = {
|
|
5912
|
-
targets: {},
|
|
5913
|
-
denied: true
|
|
5914
|
-
};
|
|
5915
|
-
cache$1.set(region, result);
|
|
5916
|
-
return result;
|
|
5917
|
-
}
|
|
5918
|
-
return {
|
|
5919
|
-
targets: {},
|
|
5920
|
-
denied: true,
|
|
5921
|
-
transient: true
|
|
5922
|
-
};
|
|
5923
|
-
}
|
|
5924
|
-
}
|
|
5925
|
-
/** The one-line warning emitted when ListAliases is denied but the stack declares an
|
|
5926
|
-
* AWS-managed alias: the managed-vs-customer key check degrades to shape-only, which
|
|
5927
|
-
* is BLIND to a customer-managed key swapped in for an `alias/aws/*` default. Pure +
|
|
5928
|
-
* exported so the wording is unit-tested. */
|
|
5929
|
-
function kmsListAliasesDeniedWarning(region) {
|
|
5930
|
-
return `warning: ${region}: kms:ListAliases denied — managed-KMS-alias drift detection is degraded. A customer-managed key swapped in for an AWS-managed default (alias/aws/*) will NOT be detected (every alias/aws/* is treated as matching any live key). Grant kms:ListAliases for full coverage.`;
|
|
5931
|
-
}
|
|
5932
|
-
/** The one-line warning emitted when ListAliases fails TRANSIENTLY (throttle / network
|
|
5933
|
-
* blip / 5xx) for a stack that declares an AWS-managed alias: the managed-vs-customer
|
|
5934
|
-
* key check is degraded for THIS stack only — the error is NOT an IAM denial, and the
|
|
5935
|
-
* region is not poisoned, so the next stack retries. Pure + exported so the wording is
|
|
5936
|
-
* unit-tested. */
|
|
5937
|
-
function kmsListAliasesTransientWarning(region) {
|
|
5938
|
-
return `warning: ${region}: kms:ListAliases failed transiently (throttle/network) — managed-KMS-alias drift detection is degraded for THIS stack and will be retried for the next stack in the region. This is NOT an IAM permission problem; no action is needed.`;
|
|
5939
|
-
}
|
|
5940
|
-
/** Pure decision for the gather-time KMS warning: given a resolved ListAliases outcome
|
|
5941
|
-
* and the two per-region dedupe sets' membership, decide WHICH warning to emit (if any)
|
|
5942
|
-
* and WHICH set to stamp. The split is the #963 fix: a TRANSIENT failure must warn with
|
|
5943
|
-
* the transient message and stamp ONLY the transient set — it must NOT stamp the
|
|
5944
|
-
* permanent-denial set, or a later stack's GENUINE denial in the same region would be
|
|
5945
|
-
* silenced. Transient and denied dedupe independently (separate sets) so neither masks
|
|
5946
|
-
* the other. `warning` is null when nothing should print (not denied, or already warned
|
|
5947
|
-
* in that region). */
|
|
5948
|
-
function kmsWarnDecision(region, resolved, deniedWarned, transientWarned) {
|
|
5949
|
-
if (!resolved.denied) return {
|
|
5950
|
-
warning: null,
|
|
5951
|
-
stampDenied: false,
|
|
5952
|
-
stampTransient: false
|
|
5953
|
-
};
|
|
5954
|
-
if (resolved.transient) return {
|
|
5955
|
-
warning: transientWarned ? null : kmsListAliasesTransientWarning(region),
|
|
5956
|
-
stampDenied: false,
|
|
5957
|
-
stampTransient: !transientWarned
|
|
5958
|
-
};
|
|
5959
|
-
return {
|
|
5960
|
-
warning: deniedWarned ? null : kmsListAliasesDeniedWarning(region),
|
|
5961
|
-
stampDenied: !deniedWarned,
|
|
5962
|
-
stampTransient: false
|
|
5963
|
-
};
|
|
5964
|
-
}
|
|
5965
|
-
/** True when any resolved declared value in the stack references an AWS-managed KMS
|
|
5966
|
-
* alias, i.e. a ListAliases prefetch is worth doing. */
|
|
5967
|
-
function usesManagedKmsAlias(v) {
|
|
5968
|
-
if (typeof v === "string") return v.startsWith("alias/aws/");
|
|
5969
|
-
if (Array.isArray(v)) return v.some(usesManagedKmsAlias);
|
|
5970
|
-
if (v && typeof v === "object") return Object.values(v).some(usesManagedKmsAlias);
|
|
5971
|
-
return false;
|
|
5972
|
-
}
|
|
5973
|
-
|
|
5974
6005
|
//#endregion
|
|
5975
6006
|
//#region src/read/child-enumerators.ts
|
|
5976
6007
|
function parentRefMatches(declaredValue, ...candidates) {
|
|
@@ -8655,6 +8686,23 @@ const readGlueConnection = async ({ physicalId, declared, region }) => {
|
|
|
8655
8686
|
if (catalogId) out.CatalogId = catalogId;
|
|
8656
8687
|
return out;
|
|
8657
8688
|
};
|
|
8689
|
+
const readGlueSecurityConfiguration = async ({ physicalId, declared, region }) => {
|
|
8690
|
+
const name = str$1(physicalId) ?? str$1(declared.Name);
|
|
8691
|
+
if (!name) return void 0;
|
|
8692
|
+
const sc = (await new GlueClient({
|
|
8693
|
+
region,
|
|
8694
|
+
...READ_RETRY
|
|
8695
|
+
}).send(new GetSecurityConfigurationCommand({ Name: name }))).SecurityConfiguration;
|
|
8696
|
+
if (!sc) throw new ResourceGoneError(`Glue SecurityConfiguration ${name} absent`);
|
|
8697
|
+
const enc = sc.EncryptionConfiguration;
|
|
8698
|
+
const ec = {};
|
|
8699
|
+
if (Array.isArray(enc?.S3Encryption) && enc.S3Encryption.length > 0) ec.S3Encryptions = enc.S3Encryption;
|
|
8700
|
+
if (enc?.CloudWatchEncryption !== void 0) ec.CloudWatchEncryption = enc.CloudWatchEncryption;
|
|
8701
|
+
if (enc?.JobBookmarksEncryption !== void 0) ec.JobBookmarksEncryption = enc.JobBookmarksEncryption;
|
|
8702
|
+
const model = { Name: sc.Name ?? name };
|
|
8703
|
+
if (Object.keys(ec).length > 0) model.EncryptionConfiguration = ec;
|
|
8704
|
+
return model;
|
|
8705
|
+
};
|
|
8658
8706
|
const readMetricFilter = async ({ physicalId, declared, region }) => {
|
|
8659
8707
|
const logGroup = str$1(declared.LogGroupName);
|
|
8660
8708
|
const filterName = str$1(physicalId) ?? str$1(declared.FilterName);
|
|
@@ -9112,6 +9160,7 @@ const SDK_OVERRIDES = {
|
|
|
9112
9160
|
"AWS::Glue::Classifier": readGlueClassifier,
|
|
9113
9161
|
"AWS::Glue::Workflow": readGlueWorkflow,
|
|
9114
9162
|
"AWS::Glue::Connection": readGlueConnection,
|
|
9163
|
+
"AWS::Glue::SecurityConfiguration": readGlueSecurityConfiguration,
|
|
9115
9164
|
"AWS::Logs::MetricFilter": readMetricFilter,
|
|
9116
9165
|
"AWS::Scheduler::Schedule": readSchedulerSchedule
|
|
9117
9166
|
};
|
|
@@ -10302,7 +10351,7 @@ async function gatherFindings(stackName, region, templateOverride, recoveryTempl
|
|
|
10302
10351
|
}
|
|
10303
10352
|
}
|
|
10304
10353
|
let kmsAliasTargets = {};
|
|
10305
|
-
if (desired.resources.some((r) => usesManagedKmsAlias(r.declared))) {
|
|
10354
|
+
if (desired.resources.some((r) => usesManagedKmsAlias(r.declared) || typeNeedsManagedKeyResolution(r.resourceType))) {
|
|
10306
10355
|
const resolved = await fetchManagedAliasTargets(region);
|
|
10307
10356
|
kmsAliasTargets = resolved.targets;
|
|
10308
10357
|
const decision = kmsWarnDecision(region, resolved, kmsDeniedWarned.has(region), kmsTransientWarned.has(region));
|
|
@@ -10366,7 +10415,7 @@ async function regatherTouched(gathered, touched, region) {
|
|
|
10366
10415
|
const reads = /* @__PURE__ */ new Map();
|
|
10367
10416
|
await readAll(cc, targets.filter((r) => r.physicalId), region, desired, reads);
|
|
10368
10417
|
for (const r of targets) if (r.declaredRaw) r.declared = resolveProperties(r.declaredRaw, desired.ctx);
|
|
10369
|
-
const kmsAliasTargets = targets.some((r) => usesManagedKmsAlias(r.declared)) ? (await fetchManagedAliasTargets(region)).targets : {};
|
|
10418
|
+
const kmsAliasTargets = targets.some((r) => usesManagedKmsAlias(r.declared) || typeNeedsManagedKeyResolution(r.resourceType)) ? (await fetchManagedAliasTargets(region)).targets : {};
|
|
10370
10419
|
const oaiCanonicalIds = buildOaiCanonicalIds(desired);
|
|
10371
10420
|
const classifyOpts = {
|
|
10372
10421
|
accountId: desired.accountId,
|
|
@@ -13302,6 +13351,15 @@ function buildRevertPlan(findings, baseline, opts = {}) {
|
|
|
13302
13351
|
});
|
|
13303
13352
|
continue;
|
|
13304
13353
|
}
|
|
13354
|
+
if (f.desired !== void 0 && !opts.removeUnrecorded) {
|
|
13355
|
+
notRevertable.push({
|
|
13356
|
+
displayId,
|
|
13357
|
+
resourceType: f.resourceType,
|
|
13358
|
+
path: f.path,
|
|
13359
|
+
reason: "recorded added resource changed since record — reverting DELETES the whole resource; re-record if the change is right, or --remove-unrecorded to delete it"
|
|
13360
|
+
});
|
|
13361
|
+
continue;
|
|
13362
|
+
}
|
|
13305
13363
|
if (!f.physicalId) {
|
|
13306
13364
|
notRevertable.push({
|
|
13307
13365
|
displayId,
|
|
@@ -13900,9 +13958,10 @@ async function stackInProgressRefusal(stackName, region) {
|
|
|
13900
13958
|
* state explicitly that ONLY the listed op(s) are written and the rest is
|
|
13901
13959
|
* untouched. Pure + exported so the wording is unit-tested.
|
|
13902
13960
|
*/
|
|
13903
|
-
function revertConfirmMessage(stackName, region, opCount, notRevertableCount) {
|
|
13961
|
+
function revertConfirmMessage(stackName, region, opCount, notRevertableCount, deleteCount = 0) {
|
|
13904
13962
|
const scope = notRevertableCount > 0 ? ` Only the ${opCount} selected op(s) are written — the ${notRevertableCount} NOT-revertable finding(s) are untouched.` : "";
|
|
13905
|
-
|
|
13963
|
+
const del = deleteCount > 0 ? ` ${deleteCount} of these DELETE(S) a whole out-of-band resource.` : "";
|
|
13964
|
+
return `Apply ${opCount} revert op(s) to ${stackLabel$1(stackName, region)}? This WRITES to AWS.${del}${scope}`;
|
|
13906
13965
|
}
|
|
13907
13966
|
/**
|
|
13908
13967
|
* The post-revert surviving-drift pointer list (R46), capped (R52): after a
|
|
@@ -14455,8 +14514,10 @@ async function revertStack(p) {
|
|
|
14455
14514
|
};
|
|
14456
14515
|
}
|
|
14457
14516
|
}
|
|
14517
|
+
const opCount = plan.items.reduce((n, i) => n + i.ops.length, 0);
|
|
14518
|
+
const deleteCount = plan.items.filter((i) => i.kind === "delete").length;
|
|
14458
14519
|
const ok = await confirm({
|
|
14459
|
-
message: revertConfirmMessage(stackName, region,
|
|
14520
|
+
message: revertConfirmMessage(stackName, region, opCount, plan.notRevertable.length, deleteCount),
|
|
14460
14521
|
initialValue: false
|
|
14461
14522
|
});
|
|
14462
14523
|
if (isCancel(ok) || !ok) {
|