cdk-real-drift 0.6.0 → 0.6.2

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 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";
@@ -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,
@@ -5297,6 +5456,14 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
5297
5456
  const schemaPath = basePath.replace(/\[[^\]]*\]/g, ".*");
5298
5457
  return schemaPath in schema.defaultPaths && matchesKnownDefault(value, schema.defaultPaths[schemaPath]) || schemaPath in knownDefPaths && matchesKnownDefault(value, knownDefPaths[schemaPath]);
5299
5458
  };
5459
+ const supplementReadGap = new Set(opts.supplementReadGapPaths ?? []);
5460
+ for (const p of supplementReadGap) if (!(p in declared) && !(p in live)) findings.push({
5461
+ tier: "readGap",
5462
+ logicalId,
5463
+ resourceType,
5464
+ path: p,
5465
+ note: "supplement read failed — property unverifiable (grant the missing read permission)"
5466
+ });
5300
5467
  for (const [k, v] of Object.entries(declared)) {
5301
5468
  if (v === UNRESOLVED || hasUnresolved(v)) {
5302
5469
  findings.push({
@@ -5307,6 +5474,16 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
5307
5474
  });
5308
5475
  if (v === UNRESOLVED || !(k in live)) continue;
5309
5476
  } else if (!(k in live)) {
5477
+ if (supplementReadGap.has(k)) {
5478
+ findings.push({
5479
+ tier: "readGap",
5480
+ logicalId,
5481
+ resourceType,
5482
+ path: k,
5483
+ note: "supplement read failed — property unverifiable (grant the missing read permission)"
5484
+ });
5485
+ continue;
5486
+ }
5310
5487
  const isNonEmptyCollection = Array.isArray(v) && v.length > 0 || v !== null && typeof v === "object" && Object.keys(v).length > 0;
5311
5488
  const isClearedAllowlistedScalar = SCALAR_RETURNED_WHEN_SET[resourceType]?.has(k) === true && (typeof v === "string" && v.length > 0 || typeof v === "number" || typeof v === "boolean");
5312
5489
  if (isNonEmptyCollection && !READGAP_COLLECTION_PATHS[resourceType]?.has(k) || isClearedAllowlistedScalar) findings.push({
@@ -5825,134 +6002,6 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
5825
6002
  }));
5826
6003
  }
5827
6004
 
5828
- //#endregion
5829
- //#region src/read/client-config.ts
5830
- /** Port of toolkit-lib awscli-compatible `shouldPrioritizeEnv()` (env creds win over profile). */
5831
- function shouldPrioritizeEnv() {
5832
- if (process.env.CDKRD_EXPLICIT_PROFILE) return false;
5833
- const id = process.env.AWS_ACCESS_KEY_ID || process.env.AMAZON_ACCESS_KEY_ID;
5834
- const key = process.env.AWS_SECRET_ACCESS_KEY || process.env.AMAZON_SECRET_ACCESS_KEY;
5835
- return !!id && !!key;
5836
- }
5837
- const CLIENT_CREDENTIALS = (awsIdentityProperties) => (shouldPrioritizeEnv() ? createCredentialChain(fromEnv(), fromNodeProviderChain()) : fromNodeProviderChain())(awsIdentityProperties);
5838
- const CLIENT_TIMEOUTS = {
5839
- credentials: CLIENT_CREDENTIALS,
5840
- requestHandler: {
5841
- connectionTimeout: 6e3,
5842
- requestTimeout: 6e4,
5843
- throwOnRequestTimeout: true
5844
- }
5845
- };
5846
- const READ_RETRY = {
5847
- maxAttempts: 10,
5848
- retryMode: "adaptive",
5849
- ...CLIENT_TIMEOUTS
5850
- };
5851
-
5852
- //#endregion
5853
- //#region src/read/kms-aliases.ts
5854
- const cache$1 = /* @__PURE__ */ new Map();
5855
- /** True when the error is a DEFINITIVE access-denial (cacheable), NOT a transient blip.
5856
- * Matches an AccessDenied(Exception) / UnauthorizedOperation by name or code, or the AWS
5857
- * HTTP 403 status. Anything else (throttle, network, 5xx, timeout) is treated as
5858
- * transient and must NOT be cached. */
5859
- function isDefinitiveDenial(err) {
5860
- const e = err;
5861
- if (!e) return false;
5862
- const definitive = /^(AccessDenied(Exception)?|UnauthorizedOperation)$/;
5863
- if (e.name && definitive.test(e.name)) return true;
5864
- if (e.code && definitive.test(e.code)) return true;
5865
- return e.$metadata?.httpStatusCode === 403;
5866
- }
5867
- async function fetchManagedAliasTargets(region) {
5868
- const cached = cache$1.get(region);
5869
- if (cached) return cached;
5870
- const targets = {};
5871
- try {
5872
- const c = new KMSClient({
5873
- region,
5874
- ...READ_RETRY
5875
- });
5876
- let marker;
5877
- do {
5878
- const r = await c.send(new ListAliasesCommand({
5879
- Marker: marker,
5880
- Limit: 100
5881
- }));
5882
- for (const a of r.Aliases ?? []) if (a.AliasName?.startsWith("alias/aws/") && a.TargetKeyId) targets[a.AliasName] = a.TargetKeyId;
5883
- marker = r.Truncated ? r.NextMarker : void 0;
5884
- } while (marker);
5885
- const result = {
5886
- targets,
5887
- denied: false
5888
- };
5889
- cache$1.set(region, result);
5890
- return result;
5891
- } catch (e) {
5892
- if (isDefinitiveDenial(e)) {
5893
- const result = {
5894
- targets: {},
5895
- denied: true
5896
- };
5897
- cache$1.set(region, result);
5898
- return result;
5899
- }
5900
- return {
5901
- targets: {},
5902
- denied: true,
5903
- transient: true
5904
- };
5905
- }
5906
- }
5907
- /** The one-line warning emitted when ListAliases is denied but the stack declares an
5908
- * AWS-managed alias: the managed-vs-customer key check degrades to shape-only, which
5909
- * is BLIND to a customer-managed key swapped in for an `alias/aws/*` default. Pure +
5910
- * exported so the wording is unit-tested. */
5911
- function kmsListAliasesDeniedWarning(region) {
5912
- 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.`;
5913
- }
5914
- /** The one-line warning emitted when ListAliases fails TRANSIENTLY (throttle / network
5915
- * blip / 5xx) for a stack that declares an AWS-managed alias: the managed-vs-customer
5916
- * key check is degraded for THIS stack only — the error is NOT an IAM denial, and the
5917
- * region is not poisoned, so the next stack retries. Pure + exported so the wording is
5918
- * unit-tested. */
5919
- function kmsListAliasesTransientWarning(region) {
5920
- 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.`;
5921
- }
5922
- /** Pure decision for the gather-time KMS warning: given a resolved ListAliases outcome
5923
- * and the two per-region dedupe sets' membership, decide WHICH warning to emit (if any)
5924
- * and WHICH set to stamp. The split is the #963 fix: a TRANSIENT failure must warn with
5925
- * the transient message and stamp ONLY the transient set — it must NOT stamp the
5926
- * permanent-denial set, or a later stack's GENUINE denial in the same region would be
5927
- * silenced. Transient and denied dedupe independently (separate sets) so neither masks
5928
- * the other. `warning` is null when nothing should print (not denied, or already warned
5929
- * in that region). */
5930
- function kmsWarnDecision(region, resolved, deniedWarned, transientWarned) {
5931
- if (!resolved.denied) return {
5932
- warning: null,
5933
- stampDenied: false,
5934
- stampTransient: false
5935
- };
5936
- if (resolved.transient) return {
5937
- warning: transientWarned ? null : kmsListAliasesTransientWarning(region),
5938
- stampDenied: false,
5939
- stampTransient: !transientWarned
5940
- };
5941
- return {
5942
- warning: deniedWarned ? null : kmsListAliasesDeniedWarning(region),
5943
- stampDenied: !deniedWarned,
5944
- stampTransient: false
5945
- };
5946
- }
5947
- /** True when any resolved declared value in the stack references an AWS-managed KMS
5948
- * alias, i.e. a ListAliases prefetch is worth doing. */
5949
- function usesManagedKmsAlias(v) {
5950
- if (typeof v === "string") return v.startsWith("alias/aws/");
5951
- if (Array.isArray(v)) return v.some(usesManagedKmsAlias);
5952
- if (v && typeof v === "object") return Object.values(v).some(usesManagedKmsAlias);
5953
- return false;
5954
- }
5955
-
5956
6005
  //#endregion
5957
6006
  //#region src/read/child-enumerators.ts
5958
6007
  function parentRefMatches(declaredValue, ...candidates) {
@@ -7335,8 +7384,13 @@ function diffRouteTableChildren(input) {
7335
7384
  async function describeRouteTable(client, routeTableId) {
7336
7385
  return (await client.send(new DescribeRouteTablesCommand({ RouteTableIds: [routeTableId] }))).RouteTables?.[0]?.Routes ?? [];
7337
7386
  }
7387
+ function routeDestination(route) {
7388
+ if (typeof route.DestinationCidrBlock === "string") return route.DestinationCidrBlock;
7389
+ if (typeof route.DestinationIpv6CidrBlock === "string") return route.DestinationIpv6CidrBlock;
7390
+ if (typeof route.DestinationPrefixListId === "string") return route.DestinationPrefixListId;
7391
+ }
7338
7392
  function isEnumerableRoute(route) {
7339
- return typeof route.DestinationCidrBlock === "string" && route.Origin !== "CreateRouteTable" && route.Origin !== "EnableVgwRoutePropagation" && route.GatewayId !== "local";
7393
+ return routeDestination(route) !== void 0 && route.Origin !== "CreateRouteTable" && route.Origin !== "EnableVgwRoutePropagation" && route.GatewayId !== "local";
7340
7394
  }
7341
7395
  async function enumerateRouteTableChildren(ctx) {
7342
7396
  const { parent, desired, region } = ctx;
@@ -7346,7 +7400,7 @@ async function enumerateRouteTableChildren(ctx) {
7346
7400
  let hasUnresolvedDeclaredRoute = false;
7347
7401
  for (const r of desired.resources) {
7348
7402
  if (r.resourceType !== "AWS::EC2::Route" || !parentRefMatches(r.declared.RouteTableId, routeTableId)) continue;
7349
- const cidr = r.declared.DestinationCidrBlock;
7403
+ const cidr = r.declared.DestinationCidrBlock ?? r.declared.DestinationIpv6CidrBlock ?? r.declared.DestinationPrefixListId;
7350
7404
  if (typeof cidr === "string") declaredCidrs.push(cidr);
7351
7405
  else if (cidr === UNRESOLVED || hasUnresolved(cidr)) hasUnresolvedDeclaredRoute = true;
7352
7406
  }
@@ -7356,7 +7410,7 @@ async function enumerateRouteTableChildren(ctx) {
7356
7410
  liveRoutes: (await describeRouteTable(new EC2Client({
7357
7411
  region,
7358
7412
  ...READ_RETRY
7359
- }), routeTableId)).filter(isEnumerableRoute).map((route) => ({ cidr: route.DestinationCidrBlock })),
7413
+ }), routeTableId)).filter(isEnumerableRoute).map((route) => ({ cidr: routeDestination(route) })),
7360
7414
  hasUnresolvedDeclaredRoute
7361
7415
  });
7362
7416
  }
@@ -9945,17 +9999,14 @@ function compositeWith(parentKey) {
9945
9999
  return typeof parent === "string" && parent.length > 0 ? `${parent}|${pid}` : void 0;
9946
10000
  };
9947
10001
  }
9948
- function restoreSupplementReadGaps(resourceType, declared, live, error) {
10002
+ function collectSupplementReadGaps(resourceType, live, error) {
9949
10003
  const exempt = OVERRIDE_READABLE_WRITEONLY[resourceType];
9950
- const restored = [];
9951
- for (const path of exempt ?? []) if (path in declared && !(path in live)) {
9952
- const value = declared[path];
9953
- if (Array.isArray(value) && value.length > 0 || value !== null && typeof value === "object" && Object.keys(value).length > 0) live[path] = value;
9954
- restored.push(path);
9955
- }
10004
+ const gaps = [];
10005
+ for (const path of exempt ?? []) if (!(path in live)) gaps.push(path);
9956
10006
  const call = error?.name || "unknown error";
9957
- const gap = restored.length ? ` — treating ${restored.join(", ")} as an unverifiable read-gap (grant the missing read permission to detect out-of-band drift on it)` : "";
10007
+ const gap = gaps.length ? ` — treating ${gaps.join(", ")} as an unverifiable read-gap (grant the missing read permission to detect out-of-band drift on it)` : "";
9958
10008
  process.stderr.write(`[cdkrd] warning: supplement read for ${resourceType} failed (${call})${gap}\n`);
10009
+ return gaps;
9959
10010
  }
9960
10011
  async function readLive(cc, resource, region, accountId) {
9961
10012
  const { resourceType, physicalId, declared } = resource;
@@ -9990,7 +10041,10 @@ async function readLive(cc, resource, region, accountId) {
9990
10041
  });
9991
10042
  if (extra) Object.assign(live, extra);
9992
10043
  } catch (e) {
9993
- restoreSupplementReadGaps(resourceType, declared, live, e);
10044
+ return {
10045
+ live,
10046
+ readGapPaths: collectSupplementReadGaps(resourceType, live, e)
10047
+ };
9994
10048
  }
9995
10049
  return { live };
9996
10050
  } catch (e) {
@@ -10207,9 +10261,15 @@ async function classifyRead(cfn, r, read, schemas, classifyOpts) {
10207
10261
  note: "schema unavailable (DescribeType failed) — coverage incomplete"
10208
10262
  }];
10209
10263
  schemas.set(r.resourceType, res.info);
10210
- return classifyResource(r, read.live, res.info, classifyOpts);
10264
+ return classifyResource(r, read.live, res.info, {
10265
+ ...classifyOpts,
10266
+ supplementReadGapPaths: read.readGapPaths
10267
+ });
10211
10268
  }
10212
- return classifyResource(r, read.live, cachedSchema, classifyOpts);
10269
+ return classifyResource(r, read.live, cachedSchema, {
10270
+ ...classifyOpts,
10271
+ supplementReadGapPaths: read.readGapPaths
10272
+ });
10213
10273
  }
10214
10274
  async function gatherFindings(stackName, region, templateOverride, recoveryTemplate) {
10215
10275
  const cfn = new CloudFormationClient({
@@ -10273,7 +10333,7 @@ async function gatherFindings(stackName, region, templateOverride, recoveryTempl
10273
10333
  }
10274
10334
  }
10275
10335
  let kmsAliasTargets = {};
10276
- if (desired.resources.some((r) => usesManagedKmsAlias(r.declared))) {
10336
+ if (desired.resources.some((r) => usesManagedKmsAlias(r.declared) || typeNeedsManagedKeyResolution(r.resourceType))) {
10277
10337
  const resolved = await fetchManagedAliasTargets(region);
10278
10338
  kmsAliasTargets = resolved.targets;
10279
10339
  const decision = kmsWarnDecision(region, resolved, kmsDeniedWarned.has(region), kmsTransientWarned.has(region));
@@ -10337,7 +10397,7 @@ async function regatherTouched(gathered, touched, region) {
10337
10397
  const reads = /* @__PURE__ */ new Map();
10338
10398
  await readAll(cc, targets.filter((r) => r.physicalId), region, desired, reads);
10339
10399
  for (const r of targets) if (r.declaredRaw) r.declared = resolveProperties(r.declaredRaw, desired.ctx);
10340
- const kmsAliasTargets = targets.some((r) => usesManagedKmsAlias(r.declared)) ? (await fetchManagedAliasTargets(region)).targets : {};
10400
+ const kmsAliasTargets = targets.some((r) => usesManagedKmsAlias(r.declared) || typeNeedsManagedKeyResolution(r.resourceType)) ? (await fetchManagedAliasTargets(region)).targets : {};
10341
10401
  const oaiCanonicalIds = buildOaiCanonicalIds(desired);
10342
10402
  const classifyOpts = {
10343
10403
  accountId: desired.accountId,
@@ -13273,6 +13333,15 @@ function buildRevertPlan(findings, baseline, opts = {}) {
13273
13333
  });
13274
13334
  continue;
13275
13335
  }
13336
+ if (f.desired !== void 0 && !opts.removeUnrecorded) {
13337
+ notRevertable.push({
13338
+ displayId,
13339
+ resourceType: f.resourceType,
13340
+ path: f.path,
13341
+ 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"
13342
+ });
13343
+ continue;
13344
+ }
13276
13345
  if (!f.physicalId) {
13277
13346
  notRevertable.push({
13278
13347
  displayId,
@@ -13871,9 +13940,10 @@ async function stackInProgressRefusal(stackName, region) {
13871
13940
  * state explicitly that ONLY the listed op(s) are written and the rest is
13872
13941
  * untouched. Pure + exported so the wording is unit-tested.
13873
13942
  */
13874
- function revertConfirmMessage(stackName, region, opCount, notRevertableCount) {
13943
+ function revertConfirmMessage(stackName, region, opCount, notRevertableCount, deleteCount = 0) {
13875
13944
  const scope = notRevertableCount > 0 ? ` Only the ${opCount} selected op(s) are written — the ${notRevertableCount} NOT-revertable finding(s) are untouched.` : "";
13876
- return `Apply ${opCount} revert op(s) to ${stackLabel$1(stackName, region)}? This WRITES to AWS.${scope}`;
13945
+ const del = deleteCount > 0 ? ` ${deleteCount} of these DELETE(S) a whole out-of-band resource.` : "";
13946
+ return `Apply ${opCount} revert op(s) to ${stackLabel$1(stackName, region)}? This WRITES to AWS.${del}${scope}`;
13877
13947
  }
13878
13948
  /**
13879
13949
  * The post-revert surviving-drift pointer list (R46), capped (R52): after a
@@ -14426,8 +14496,10 @@ async function revertStack(p) {
14426
14496
  };
14427
14497
  }
14428
14498
  }
14499
+ const opCount = plan.items.reduce((n, i) => n + i.ops.length, 0);
14500
+ const deleteCount = plan.items.filter((i) => i.kind === "delete").length;
14429
14501
  const ok = await confirm({
14430
- message: revertConfirmMessage(stackName, region, plan.items.reduce((n, i) => n + i.ops.length, 0), plan.notRevertable.length),
14502
+ message: revertConfirmMessage(stackName, region, opCount, plan.notRevertable.length, deleteCount),
14431
14503
  initialValue: false
14432
14504
  });
14433
14505
  if (isCancel(ok) || !ok) {