cdk-real-drift 0.12.42 → 0.12.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -964,7 +964,11 @@ covers them. **If you never run `revert`, cdkrd needs no write permissions at al
964
964
  - `AWS::ElasticLoadBalancingV2::LoadBalancer` + `::Listener`:
965
965
  `elasticloadbalancing:DescribeListeners`, `elasticloadbalancing:DescribeRules`
966
966
  - `AWS::EC2::VPC` + `AWS::EC2::RouteTable`: `ec2:DescribeSubnets`,
967
- `ec2:DescribeRouteTables`
967
+ `ec2:DescribeRouteTables` (plus `ec2:DescribeInternetGateways` and
968
+ `ec2:DescribeVpcs` for the VPC's out-of-band IGW attachment and secondary
969
+ CIDR sub-resources)
970
+ - `AWS::EC2::NetworkAcl`: `ec2:DescribeNetworkAcls` (enumerates a declared
971
+ NACL's out-of-band entries — a rogue `AWS::EC2::NetworkAclEntry`)
968
972
  - `AWS::ECS::Cluster`: `ecs:ListServices` (distinct from the
969
973
  `ecs:DescribeServices` override reader listed above)
970
974
  - `AWS::KMS::Key`: `kms:ListAliases` (the same action listed as optional
package/dist/cli.js CHANGED
@@ -8,7 +8,7 @@ import { CloudControlClient, DeleteResourceCommand, GetResourceCommand, GetResou
8
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
- import { DescribeAddressesCommand, DescribeClientVpnAuthorizationRulesCommand, DescribeClientVpnEndpointsCommand, DescribeClientVpnTargetNetworksCommand, DescribeLaunchTemplateVersionsCommand, DescribeNetworkAclsCommand, DescribeRouteTablesCommand, DescribeSecurityGroupsCommand, DescribeSubnetsCommand, DescribeVpcEndpointsCommand, EC2Client, ModifyClientVpnEndpointCommand } from "@aws-sdk/client-ec2";
11
+ import { DescribeAddressesCommand, DescribeClientVpnAuthorizationRulesCommand, DescribeClientVpnEndpointsCommand, DescribeClientVpnTargetNetworksCommand, DescribeInternetGatewaysCommand, DescribeLaunchTemplateVersionsCommand, DescribeNetworkAclsCommand, DescribeRouteTablesCommand, DescribeSecurityGroupsCommand, DescribeSubnetsCommand, DescribeVpcEndpointsCommand, DescribeVpcsCommand, EC2Client, ModifyClientVpnEndpointCommand } from "@aws-sdk/client-ec2";
12
12
  import { DescribeDBClustersCommand, DescribeDBInstancesCommand, DescribeOptionGroupOptionsCommand, RDSClient } from "@aws-sdk/client-rds";
13
13
  import { DescribeParametersCommand, GetParametersCommand, SSMClient } from "@aws-sdk/client-ssm";
14
14
  import { createCredentialChain, fromEnv, fromNodeProviderChain } from "@aws-sdk/credential-providers";
@@ -5763,12 +5763,7 @@ function compileTransform(expr) {
5763
5763
  return compiled;
5764
5764
  }
5765
5765
  function matchesPropertyTransform(transformExpr, declaredValue, parentObject, rootObject, liveValue, leafName) {
5766
- const scopes = [
5767
- parentObject,
5768
- rootObject,
5769
- { [leafName]: declaredValue },
5770
- declaredValue
5771
- ];
5766
+ const scopes = buildTransformScopes(declaredValue, parentObject, rootObject, leafName);
5772
5767
  for (const alt of transformExpr.split(" $OR ")) {
5773
5768
  const expr = alt.trim();
5774
5769
  if (!expr) continue;
@@ -5781,6 +5776,39 @@ function matchesPropertyTransform(transformExpr, declaredValue, parentObject, ro
5781
5776
  }
5782
5777
  return false;
5783
5778
  }
5779
+ function buildTransformScopes(declaredValue, parentObject, rootObject, leafName) {
5780
+ const scopes = [
5781
+ parentObject,
5782
+ rootObject,
5783
+ { [leafName]: declaredValue },
5784
+ declaredValue
5785
+ ];
5786
+ const coerced = coerceNumericLeaf(declaredValue);
5787
+ if (coerced === void 0) return scopes;
5788
+ const coercedParent = substituteLeaf(parentObject, leafName, coerced);
5789
+ const coercedRoot = substituteLeaf(rootObject, leafName, coerced);
5790
+ if (coercedParent !== void 0) scopes.push(coercedParent);
5791
+ if (coercedRoot !== void 0 && coercedRoot !== coercedParent) scopes.push(coercedRoot);
5792
+ scopes.push({ [leafName]: coerced }, coerced);
5793
+ return scopes;
5794
+ }
5795
+ function coerceNumericLeaf(value) {
5796
+ if (typeof value === "string") {
5797
+ if (value.trim() === "") return void 0;
5798
+ const n = Number(value);
5799
+ return Number.isNaN(n) ? void 0 : n;
5800
+ }
5801
+ if (typeof value === "number") return String(value);
5802
+ }
5803
+ function substituteLeaf(obj, leafName, coerced) {
5804
+ if (obj == null || typeof obj !== "object" || Array.isArray(obj)) return void 0;
5805
+ const rec = obj;
5806
+ if (!(leafName in rec)) return void 0;
5807
+ return {
5808
+ ...rec,
5809
+ [leafName]: coerced
5810
+ };
5811
+ }
5784
5812
  function resolveParentObject(root, dottedPath) {
5785
5813
  const segs = dottedPath.split(".");
5786
5814
  if (segs.length <= 1) return root;
@@ -6865,6 +6893,7 @@ const CHILD_ENUMERATORS = {
6865
6893
  "AWS::ElasticLoadBalancingV2::Listener": enumerateListenerChildren,
6866
6894
  "AWS::EC2::VPC": enumerateVpcChildren,
6867
6895
  "AWS::EC2::RouteTable": enumerateRouteTableChildren,
6896
+ "AWS::EC2::NetworkAcl": enumerateNetworkAclChildren,
6868
6897
  "AWS::ECS::Cluster": enumerateEcsClusterChildren,
6869
6898
  "AWS::KMS::Key": enumerateKmsKeyChildren,
6870
6899
  "AWS::AppConfig::Application": enumerateAppConfigApplicationChildren,
@@ -8359,6 +8388,56 @@ function diffVpcNaclChildren(input) {
8359
8388
  }
8360
8389
  return added;
8361
8390
  }
8391
+ function diffSubnetRouteTableAssociationChildren(input) {
8392
+ const declared = new Set(input.declaredAssociationIds);
8393
+ const added = [];
8394
+ for (const a of input.liveAssociations) {
8395
+ if (declared.has(a.id)) continue;
8396
+ added.push({
8397
+ resourceType: "AWS::EC2::SubnetRouteTableAssociation",
8398
+ identifier: a.id,
8399
+ label: a.subnetId ? `${a.subnetId} -> ${a.routeTableId ?? "?"}` : a.id,
8400
+ live: {
8401
+ Id: a.id,
8402
+ SubnetId: a.subnetId,
8403
+ RouteTableId: a.routeTableId
8404
+ }
8405
+ });
8406
+ }
8407
+ return added;
8408
+ }
8409
+ function diffVpcGatewayAttachmentChildren(input) {
8410
+ const { vpcId, hasDeclaredIgwAttachment, liveInternetGatewayId } = input;
8411
+ if (!liveInternetGatewayId || hasDeclaredIgwAttachment) return [];
8412
+ return [{
8413
+ resourceType: "AWS::EC2::VPCGatewayAttachment",
8414
+ identifier: `IGW|${vpcId}`,
8415
+ label: `${liveInternetGatewayId} -> ${vpcId}`,
8416
+ live: {
8417
+ AttachmentType: "IGW",
8418
+ InternetGatewayId: liveInternetGatewayId,
8419
+ VpcId: vpcId
8420
+ }
8421
+ }];
8422
+ }
8423
+ function diffVpcCidrBlockChildren(input) {
8424
+ const declared = new Set(input.declaredCidrs);
8425
+ const added = [];
8426
+ for (const b of input.liveCidrBlocks) {
8427
+ if (declared.has(b.cidr)) continue;
8428
+ added.push({
8429
+ resourceType: "AWS::EC2::VPCCidrBlock",
8430
+ identifier: `${b.associationId}|${input.vpcId}`,
8431
+ label: b.cidr,
8432
+ live: {
8433
+ Id: b.associationId,
8434
+ VpcId: input.vpcId,
8435
+ CidrBlock: b.cidr
8436
+ }
8437
+ });
8438
+ }
8439
+ return added;
8440
+ }
8362
8441
  async function pageSubnets(client, vpcId) {
8363
8442
  const out = [];
8364
8443
  let next;
@@ -8423,6 +8502,25 @@ async function pageNetworkAcls(client, vpcId) {
8423
8502
  } while (next);
8424
8503
  return out;
8425
8504
  }
8505
+ async function pageInternetGateways(client, vpcId) {
8506
+ const out = [];
8507
+ let next;
8508
+ do {
8509
+ const res = await client.send(new DescribeInternetGatewaysCommand({
8510
+ Filters: [{
8511
+ Name: "attachment.vpc-id",
8512
+ Values: [vpcId]
8513
+ }],
8514
+ NextToken: next
8515
+ }));
8516
+ out.push(...res.InternetGateways ?? []);
8517
+ next = res.NextToken;
8518
+ } while (next);
8519
+ return out;
8520
+ }
8521
+ async function describeVpc(client, vpcId) {
8522
+ return (await client.send(new DescribeVpcsCommand({ VpcIds: [vpcId] }))).Vpcs?.[0];
8523
+ }
8426
8524
  async function enumerateVpcChildren(ctx) {
8427
8525
  const { parent, desired, region } = ctx;
8428
8526
  const vpcId = parent.physicalId;
@@ -8438,6 +8536,16 @@ async function enumerateVpcChildren(ctx) {
8438
8536
  else if (r.resourceType === "AWS::EC2::RouteTable") declaredRouteTableIds.push(r.physicalId);
8439
8537
  else if (r.resourceType === "AWS::EC2::NetworkAcl") declaredNaclIds.push(r.physicalId);
8440
8538
  }
8539
+ const declaredAssociationIds = [];
8540
+ let hasDeclaredIgwAttachment = false;
8541
+ const declaredCidrs = [];
8542
+ for (const r of desired.resources) if (r.resourceType === "AWS::EC2::SubnetRouteTableAssociation") {
8543
+ if (r.physicalId) declaredAssociationIds.push(r.physicalId);
8544
+ } else if (r.resourceType === "AWS::EC2::VPCGatewayAttachment" && parentRefMatches(r.declared.VpcId, vpcId) && r.declared.InternetGatewayId != null) hasDeclaredIgwAttachment = true;
8545
+ else if (r.resourceType === "AWS::EC2::VPCCidrBlock" && parentRefMatches(r.declared.VpcId, vpcId)) {
8546
+ const cidr = r.declared.CidrBlock ?? r.declared.Ipv6CidrBlock;
8547
+ if (typeof cidr === "string") declaredCidrs.push(cidr);
8548
+ }
8441
8549
  const client = new EC2Client({
8442
8550
  region,
8443
8551
  ...READ_RETRY
@@ -8450,14 +8558,39 @@ async function enumerateVpcChildren(ctx) {
8450
8558
  id: e.VpcEndpointId,
8451
8559
  label: e.ServiceName ?? e.VpcEndpointId
8452
8560
  }));
8453
- const liveRouteTables = (await pageVpcRouteTables(client, vpcId)).filter((rt) => typeof rt.RouteTableId === "string").filter((rt) => !(rt.Associations ?? []).some((a) => a.Main === true)).map((rt) => ({
8561
+ const routeTables = await pageVpcRouteTables(client, vpcId);
8562
+ const liveRouteTables = routeTables.filter((rt) => typeof rt.RouteTableId === "string").filter((rt) => !(rt.Associations ?? []).some((a) => a.Main === true)).map((rt) => ({
8454
8563
  id: rt.RouteTableId,
8455
8564
  label: rt.RouteTableId
8456
8565
  }));
8566
+ const liveAssociations = routeTables.flatMap((rt) => rt.Associations ?? []).filter((a) => typeof a.RouteTableAssociationId === "string" && a.Main !== true && typeof a.SubnetId === "string").map((a) => ({
8567
+ id: a.RouteTableAssociationId,
8568
+ subnetId: a.SubnetId,
8569
+ routeTableId: a.RouteTableId
8570
+ }));
8457
8571
  const liveNacls = (await pageNetworkAcls(client, vpcId)).filter((n) => typeof n.NetworkAclId === "string").filter((n) => n.IsDefault !== true).map((n) => ({
8458
8572
  id: n.NetworkAclId,
8459
8573
  label: n.NetworkAclId
8460
8574
  }));
8575
+ const liveInternetGatewayId = (await pageInternetGateways(client, vpcId)).find((igw) => typeof igw.InternetGatewayId === "string")?.InternetGatewayId;
8576
+ const vpc = await describeVpc(client, vpcId);
8577
+ const primaryCidr = typeof vpc?.CidrBlock === "string" ? vpc.CidrBlock : void 0;
8578
+ const liveCidrBlocks = [];
8579
+ for (const b of vpc?.CidrBlockAssociationSet ?? []) {
8580
+ if (typeof b.AssociationId !== "string" || typeof b.CidrBlock !== "string") continue;
8581
+ if (b.CidrBlock === primaryCidr) continue;
8582
+ liveCidrBlocks.push({
8583
+ associationId: b.AssociationId,
8584
+ cidr: b.CidrBlock
8585
+ });
8586
+ }
8587
+ for (const b of vpc?.Ipv6CidrBlockAssociationSet ?? []) {
8588
+ if (typeof b.AssociationId !== "string" || typeof b.Ipv6CidrBlock !== "string") continue;
8589
+ liveCidrBlocks.push({
8590
+ associationId: b.AssociationId,
8591
+ cidr: b.Ipv6CidrBlock
8592
+ });
8593
+ }
8461
8594
  return [
8462
8595
  ...diffVpcChildren({
8463
8596
  declaredSubnetIds,
@@ -8474,9 +8607,76 @@ async function enumerateVpcChildren(ctx) {
8474
8607
  ...diffVpcNaclChildren({
8475
8608
  declaredNaclIds,
8476
8609
  liveNacls
8610
+ }),
8611
+ ...diffSubnetRouteTableAssociationChildren({
8612
+ declaredAssociationIds,
8613
+ liveAssociations
8614
+ }),
8615
+ ...diffVpcGatewayAttachmentChildren({
8616
+ vpcId,
8617
+ hasDeclaredIgwAttachment,
8618
+ liveInternetGatewayId
8619
+ }),
8620
+ ...diffVpcCidrBlockChildren({
8621
+ vpcId,
8622
+ declaredCidrs,
8623
+ liveCidrBlocks
8477
8624
  })
8478
8625
  ];
8479
8626
  }
8627
+ const NACL_DEFAULT_RULE_NUMBER = 32767;
8628
+ function diffNetworkAclEntryChildren(input) {
8629
+ const { naclId, declaredEntryKeys, liveEntries } = input;
8630
+ const declared = new Set(declaredEntryKeys);
8631
+ const added = [];
8632
+ for (const e of liveEntries) {
8633
+ const key = `${e.ruleNumber}|${e.egress}`;
8634
+ if (declared.has(key)) continue;
8635
+ const dir = e.egress ? "egress" : "ingress";
8636
+ const detail = [e.ruleAction, e.cidr].filter((v) => v != null).join(" ");
8637
+ added.push({
8638
+ resourceType: "AWS::EC2::NetworkAclEntry",
8639
+ identifier: `${naclId}|${e.ruleNumber}|${e.egress}`,
8640
+ label: `#${e.ruleNumber} ${dir}${detail ? ` ${detail}` : ""}`,
8641
+ live: {
8642
+ NetworkAclId: naclId,
8643
+ RuleNumber: e.ruleNumber,
8644
+ Egress: e.egress,
8645
+ ...e.ruleAction != null ? { RuleAction: e.ruleAction } : {},
8646
+ ...e.cidr != null ? { CidrBlock: e.cidr } : {}
8647
+ }
8648
+ });
8649
+ }
8650
+ return added;
8651
+ }
8652
+ async function describeNetworkAcl(client, naclId) {
8653
+ return (await client.send(new DescribeNetworkAclsCommand({ NetworkAclIds: [naclId] }))).NetworkAcls?.[0];
8654
+ }
8655
+ async function enumerateNetworkAclChildren(ctx) {
8656
+ const { parent, desired, region } = ctx;
8657
+ const naclId = parent.physicalId;
8658
+ if (!naclId) return [];
8659
+ const declaredEntryKeys = [];
8660
+ for (const r of desired.resources) {
8661
+ if (r.resourceType !== "AWS::EC2::NetworkAclEntry" || !parentRefMatches(r.declared.NetworkAclId, naclId)) continue;
8662
+ const ruleNumber = r.declared.RuleNumber;
8663
+ const egress = r.declared.Egress === true;
8664
+ if (typeof ruleNumber === "number") declaredEntryKeys.push(`${ruleNumber}|${egress}`);
8665
+ }
8666
+ return diffNetworkAclEntryChildren({
8667
+ naclId,
8668
+ declaredEntryKeys,
8669
+ liveEntries: ((await describeNetworkAcl(new EC2Client({
8670
+ region,
8671
+ ...READ_RETRY
8672
+ }), naclId))?.Entries ?? []).filter((e) => typeof e.RuleNumber === "number" && typeof e.Egress === "boolean").filter((e) => e.RuleNumber !== NACL_DEFAULT_RULE_NUMBER).map((e) => ({
8673
+ ruleNumber: e.RuleNumber,
8674
+ egress: e.Egress,
8675
+ cidr: e.CidrBlock ?? e.Ipv6CidrBlock,
8676
+ ruleAction: e.RuleAction
8677
+ }))
8678
+ });
8679
+ }
8480
8680
  function diffRouteTableChildren(input) {
8481
8681
  const { routeTableId, declaredCidrs, liveRoutes, hasUnresolvedDeclaredRoute } = input;
8482
8682
  if (hasUnresolvedDeclaredRoute) return [];
@@ -11499,6 +11699,11 @@ const CC_IDENTIFIER_ADAPTERS = {
11499
11699
  return typeof apiId === "string" && apiId.length > 0 && typeof integrationId === "string" && integrationId.length > 0 ? `${apiId}|${integrationId}|${pid}` : void 0;
11500
11700
  },
11501
11701
  "AWS::GuardDuty::Filter": compositeWith("DetectorId"),
11702
+ "AWS::GuardDuty::IPSet": compositeChildFirstWith("DetectorId"),
11703
+ "AWS::GuardDuty::ThreatIntelSet": compositeChildFirstWith("DetectorId"),
11704
+ "AWS::GuardDuty::ThreatEntitySet": compositeChildFirstWith("DetectorId"),
11705
+ "AWS::GuardDuty::TrustedEntitySet": compositeChildFirstWith("DetectorId"),
11706
+ "AWS::GuardDuty::PublishingDestination": compositeWith("DetectorId"),
11502
11707
  "AWS::Events::Rule": (pid, declared, region, account) => {
11503
11708
  const bar = pid.lastIndexOf("|");
11504
11709
  if (bar < 0) return pid;
@@ -11525,6 +11730,13 @@ function compositeWith(parentKey) {
11525
11730
  return typeof parent === "string" && parent.length > 0 ? `${parent}|${pid}` : void 0;
11526
11731
  };
11527
11732
  }
11733
+ function compositeChildFirstWith(parentKey) {
11734
+ return (pid, declared) => {
11735
+ if (pid.includes("|")) return pid;
11736
+ const parent = declared[parentKey];
11737
+ return typeof parent === "string" && parent.length > 0 ? `${pid}|${parent}` : void 0;
11738
+ };
11739
+ }
11528
11740
  function collectSupplementReadGaps(resourceType, live, error) {
11529
11741
  const exempt = OVERRIDE_READABLE_WRITEONLY[resourceType];
11530
11742
  const gaps = [];
@@ -15831,6 +16043,7 @@ function isUnderCreateOnly(findingPath, createOnlyPaths) {
15831
16043
  }
15832
16044
  return false;
15833
16045
  }
16046
+ const CC_DELETE_UNSUPPORTED_ADDED_TYPES = new Set(["AWS::EC2::NetworkAclEntry"]);
15834
16047
  function buildRevertPlan(findings, baseline, opts = {}) {
15835
16048
  const itemsByLogical = /* @__PURE__ */ new Map();
15836
16049
  const notRevertable = [];
@@ -15887,6 +16100,15 @@ function buildRevertPlan(findings, baseline, opts = {}) {
15887
16100
  });
15888
16101
  continue;
15889
16102
  }
16103
+ if (CC_DELETE_UNSUPPORTED_ADDED_TYPES.has(f.resourceType)) {
16104
+ notRevertable.push({
16105
+ displayId,
16106
+ resourceType: f.resourceType,
16107
+ path: f.path,
16108
+ reason: "out-of-band resource of a type Cloud Control cannot delete (no DeleteResource handler) — remove it manually"
16109
+ });
16110
+ continue;
16111
+ }
15890
16112
  itemsByLogical.set(f.logicalId, {
15891
16113
  logicalId: f.logicalId,
15892
16114
  displayId,