cdk-real-drift 0.12.41 → 0.12.43

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";
@@ -3463,7 +3463,7 @@ function isJsonStringStructEqual(a, b) {
3463
3463
  const JSON_STRING_PROPS = { "AWS::Config::ConfigRule": new Set(["InputParameters"]) };
3464
3464
  const JSON_STRING_DEFAULT_FILLS = { "AWS::CE::CostCategory": { Rules: { Type: "REGULAR" } } };
3465
3465
  const CASE_INSENSITIVE_PATHS = {
3466
- "AWS::Route53::RecordSet": new Set(["AliasTarget.DNSName"]),
3466
+ "AWS::Route53::RecordSet": new Set(["Name", "AliasTarget.DNSName"]),
3467
3467
  "AWS::Batch::ComputeEnvironment": new Set(["Type"]),
3468
3468
  "AWS::EMRServerless::Application": new Set(["Type"]),
3469
3469
  "AWS::RDS::DBInstance": new Set(["DBInstanceIdentifier"]),
@@ -3691,6 +3691,7 @@ function isTrailingSlashEqual(a, b) {
3691
3691
  const VERSION_PREFIX_PATHS = {
3692
3692
  "AWS::RDS::DBInstance": new Set(["EngineVersion"]),
3693
3693
  "AWS::RDS::DBCluster": new Set(["EngineVersion"]),
3694
+ "AWS::RDS::GlobalCluster": new Set(["EngineVersion"]),
3694
3695
  "AWS::Neptune::DBCluster": new Set(["EngineVersion"]),
3695
3696
  "AWS::DocDB::DBCluster": new Set(["EngineVersion"]),
3696
3697
  "AWS::ElastiCache::ReplicationGroup": new Set(["EngineVersion"]),
@@ -5762,12 +5763,7 @@ function compileTransform(expr) {
5762
5763
  return compiled;
5763
5764
  }
5764
5765
  function matchesPropertyTransform(transformExpr, declaredValue, parentObject, rootObject, liveValue, leafName) {
5765
- const scopes = [
5766
- parentObject,
5767
- rootObject,
5768
- { [leafName]: declaredValue },
5769
- declaredValue
5770
- ];
5766
+ const scopes = buildTransformScopes(declaredValue, parentObject, rootObject, leafName);
5771
5767
  for (const alt of transformExpr.split(" $OR ")) {
5772
5768
  const expr = alt.trim();
5773
5769
  if (!expr) continue;
@@ -5780,6 +5776,39 @@ function matchesPropertyTransform(transformExpr, declaredValue, parentObject, ro
5780
5776
  }
5781
5777
  return false;
5782
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
+ }
5783
5812
  function resolveParentObject(root, dottedPath) {
5784
5813
  const segs = dottedPath.split(".");
5785
5814
  if (segs.length <= 1) return root;
@@ -6864,6 +6893,7 @@ const CHILD_ENUMERATORS = {
6864
6893
  "AWS::ElasticLoadBalancingV2::Listener": enumerateListenerChildren,
6865
6894
  "AWS::EC2::VPC": enumerateVpcChildren,
6866
6895
  "AWS::EC2::RouteTable": enumerateRouteTableChildren,
6896
+ "AWS::EC2::NetworkAcl": enumerateNetworkAclChildren,
6867
6897
  "AWS::ECS::Cluster": enumerateEcsClusterChildren,
6868
6898
  "AWS::KMS::Key": enumerateKmsKeyChildren,
6869
6899
  "AWS::AppConfig::Application": enumerateAppConfigApplicationChildren,
@@ -8358,6 +8388,56 @@ function diffVpcNaclChildren(input) {
8358
8388
  }
8359
8389
  return added;
8360
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
+ }
8361
8441
  async function pageSubnets(client, vpcId) {
8362
8442
  const out = [];
8363
8443
  let next;
@@ -8422,6 +8502,25 @@ async function pageNetworkAcls(client, vpcId) {
8422
8502
  } while (next);
8423
8503
  return out;
8424
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
+ }
8425
8524
  async function enumerateVpcChildren(ctx) {
8426
8525
  const { parent, desired, region } = ctx;
8427
8526
  const vpcId = parent.physicalId;
@@ -8437,6 +8536,16 @@ async function enumerateVpcChildren(ctx) {
8437
8536
  else if (r.resourceType === "AWS::EC2::RouteTable") declaredRouteTableIds.push(r.physicalId);
8438
8537
  else if (r.resourceType === "AWS::EC2::NetworkAcl") declaredNaclIds.push(r.physicalId);
8439
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
+ }
8440
8549
  const client = new EC2Client({
8441
8550
  region,
8442
8551
  ...READ_RETRY
@@ -8449,14 +8558,39 @@ async function enumerateVpcChildren(ctx) {
8449
8558
  id: e.VpcEndpointId,
8450
8559
  label: e.ServiceName ?? e.VpcEndpointId
8451
8560
  }));
8452
- 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) => ({
8453
8563
  id: rt.RouteTableId,
8454
8564
  label: rt.RouteTableId
8455
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
+ }));
8456
8571
  const liveNacls = (await pageNetworkAcls(client, vpcId)).filter((n) => typeof n.NetworkAclId === "string").filter((n) => n.IsDefault !== true).map((n) => ({
8457
8572
  id: n.NetworkAclId,
8458
8573
  label: n.NetworkAclId
8459
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
+ }
8460
8594
  return [
8461
8595
  ...diffVpcChildren({
8462
8596
  declaredSubnetIds,
@@ -8473,9 +8607,76 @@ async function enumerateVpcChildren(ctx) {
8473
8607
  ...diffVpcNaclChildren({
8474
8608
  declaredNaclIds,
8475
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
8476
8624
  })
8477
8625
  ];
8478
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
+ }
8479
8680
  function diffRouteTableChildren(input) {
8480
8681
  const { routeTableId, declaredCidrs, liveRoutes, hasUnresolvedDeclaredRoute } = input;
8481
8682
  if (hasUnresolvedDeclaredRoute) return [];
@@ -11498,6 +11699,11 @@ const CC_IDENTIFIER_ADAPTERS = {
11498
11699
  return typeof apiId === "string" && apiId.length > 0 && typeof integrationId === "string" && integrationId.length > 0 ? `${apiId}|${integrationId}|${pid}` : void 0;
11499
11700
  },
11500
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"),
11501
11707
  "AWS::Events::Rule": (pid, declared, region, account) => {
11502
11708
  const bar = pid.lastIndexOf("|");
11503
11709
  if (bar < 0) return pid;
@@ -11524,6 +11730,13 @@ function compositeWith(parentKey) {
11524
11730
  return typeof parent === "string" && parent.length > 0 ? `${parent}|${pid}` : void 0;
11525
11731
  };
11526
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
+ }
11527
11740
  function collectSupplementReadGaps(resourceType, live, error) {
11528
11741
  const exempt = OVERRIDE_READABLE_WRITEONLY[resourceType];
11529
11742
  const gaps = [];
@@ -15671,6 +15884,10 @@ const REVERT_SET_DEFAULT_PATHS = new Set([
15671
15884
  "AWS::EC2::Subnet\0AssignIpv6AddressOnCreation",
15672
15885
  "AWS::EC2::Subnet\0PrivateDnsNameOptionsOnLaunch",
15673
15886
  "AWS::EC2::Subnet\0EnableDns64",
15887
+ "AWS::EC2::VPC\0EnableDnsSupport",
15888
+ "AWS::EC2::NetworkInterface\0SourceDestCheck",
15889
+ "AWS::EC2::Instance\0SourceDestCheck",
15890
+ "AWS::EC2::Instance\0InstanceInitiatedShutdownBehavior",
15674
15891
  "AWS::EC2::ClientVpnEndpoint\0VpnPort",
15675
15892
  "AWS::EC2::ClientVpnEndpoint\0DisconnectOnSessionTimeout",
15676
15893
  "AWS::EC2::ClientVpnEndpoint\0SplitTunnel",