cdk-real-drift 0.8.0 → 0.9.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/README.md CHANGED
@@ -831,7 +831,13 @@ covers them. **If you never run `revert`, cdkrd needs no write permissions at al
831
831
  `glue:GetClassifier` + `glue:GetWorkflow` + `glue:GetConnection`
832
832
  (`glue:GetConnection` is issued with `HidePassword` so NO credential enters the
833
833
  baseline — read an `AWS::Glue::Classifier` / `Workflow` / `Connection`, the rest
834
- of the Glue family that has no Cloud Control handler)
834
+ of the Glue family that has no Cloud Control handler),
835
+ `rds:DescribeOptionGroupOptions` (reads an `AWS::RDS::OptionGroup`'s option-default
836
+ catalog — the `DefaultValue` AWS materializes for every plugin setting the template
837
+ did not declare — so the service default-fill folds to `atDefault` instead of
838
+ flooding a clean first check with undeclared settings; equality-gated, so an
839
+ out-of-band setting change is still detected. Without the permission cdkrd warns
840
+ once and those default-fill settings surface as first-run drift)
835
841
  - Optional: `elasticloadbalancing:GetTrustStoreCaCertificatesBundle` records a
836
842
  content hash of an `AWS::ElasticLoadBalancingV2::TrustStore`'s live mTLS CA
837
843
  bundle (`CaCertificatesBundleSha256`) so an out-of-band CA-bundle swap
package/dist/cli.js CHANGED
@@ -8,6 +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 { DescribeDBClustersCommand, DescribeDBInstancesCommand, DescribeOptionGroupOptionsCommand, RDSClient } from "@aws-sdk/client-rds";
11
12
  import jsonata from "jsonata";
12
13
  import { KMSClient, ListAliasesCommand } from "@aws-sdk/client-kms";
13
14
  import { createCredentialChain, fromEnv, fromNodeProviderChain } from "@aws-sdk/credential-providers";
@@ -23,7 +24,6 @@ import { DescribeMountTargetsCommand, EFSClient } from "@aws-sdk/client-efs";
23
24
  import { DescribeListenersCommand, DescribeRulesCommand, ElasticLoadBalancingV2Client, GetTrustStoreCaCertificatesBundleCommand, ModifyLoadBalancerAttributesCommand, ModifyTargetGroupAttributesCommand } from "@aws-sdk/client-elastic-load-balancing-v2";
24
25
  import { DescribeEventBusCommand, EventBridgeClient, ListRulesCommand, PutPermissionCommand } from "@aws-sdk/client-eventbridge";
25
26
  import { GetPolicyCommand, LambdaClient, ListAliasesCommand as ListAliasesCommand$1, ListEventSourceMappingsCommand, ListFunctionUrlConfigsCommand, ListVersionsByFunctionCommand } from "@aws-sdk/client-lambda";
26
- import { DescribeDBClustersCommand, DescribeDBInstancesCommand, RDSClient } from "@aws-sdk/client-rds";
27
27
  import { ChangeResourceRecordSetsCommand, ListResourceRecordSetsCommand, Route53Client } from "@aws-sdk/client-route-53";
28
28
  import { GetTopicAttributesCommand, ListSubscriptionsByTopicCommand, SNSClient, SetTopicAttributesCommand } from "@aws-sdk/client-sns";
29
29
  import { ACMClient, DescribeCertificateCommand, ListTagsForCertificateCommand } from "@aws-sdk/client-acm";
@@ -1634,6 +1634,7 @@ function buildCorpusCase(resource, liveRaw, schema, opts, findings) {
1634
1634
  const sgSibling = resource.resourceType === "AWS::EC2::SecurityGroup" && resource.physicalId ? opts.siblingSgRules?.[resource.physicalId] : void 0;
1635
1635
  const bucketNotif = resource.physicalId && opts.bucketNotificationManaged?.has(resource.physicalId) ? [resource.physicalId] : void 0;
1636
1636
  const echoModel = resource.physicalId && opts.clusterEchoModel?.[resource.physicalId] ? opts.clusterEchoModel[resource.physicalId] : void 0;
1637
+ const rdsOptCatalog = resource.physicalId && opts.rdsOptionSettingDefaults?.[resource.physicalId] ? opts.rdsOptionSettingDefaults[resource.physicalId] : void 0;
1637
1638
  return sanitizeAccountId({
1638
1639
  corpusVersion: 1,
1639
1640
  resource: {
@@ -1665,7 +1666,8 @@ function buildCorpusCase(resource, liveRaw, schema, opts, findings) {
1665
1666
  oaiCanonicalIds: opts.oaiCanonicalIds,
1666
1667
  ...sgSibling && resource.physicalId ? { siblingSgRules: { [resource.physicalId]: sgSibling } } : {},
1667
1668
  ...bucketNotif ? { bucketNotificationManaged: bucketNotif } : {},
1668
- ...echoModel && resource.physicalId ? { clusterEchoModel: { [resource.physicalId]: echoModel } } : {}
1669
+ ...echoModel && resource.physicalId ? { clusterEchoModel: { [resource.physicalId]: echoModel } } : {},
1670
+ ...rdsOptCatalog && resource.physicalId ? { rdsOptionSettingDefaults: { [resource.physicalId]: rdsOptCatalog } } : {}
1669
1671
  },
1670
1672
  expected: findings
1671
1673
  }, opts.accountId);
@@ -2978,7 +2980,11 @@ const VALUE_INDEPENDENT_DEFAULT_TOPLEVEL_PATHS = {
2978
2980
  "AWS::EC2::SecurityGroupEgress": new Set(["DestinationSecurityGroupName"]),
2979
2981
  "AWS::DocDB::DBCluster": new Set(["PreferredMaintenanceWindow", "PreferredBackupWindow"]),
2980
2982
  "AWS::DocDB::DBInstance": new Set(["PreferredMaintenanceWindow"]),
2981
- "AWS::Neptune::DBCluster": new Set(["PreferredMaintenanceWindow", "PreferredBackupWindow"]),
2983
+ "AWS::Neptune::DBCluster": new Set([
2984
+ "PreferredMaintenanceWindow",
2985
+ "PreferredBackupWindow",
2986
+ "EngineVersion"
2987
+ ]),
2982
2988
  "AWS::Neptune::DBInstance": new Set(["PreferredMaintenanceWindow", "AvailabilityZone"]),
2983
2989
  "AWS::ElastiCache::CacheCluster": new Set([
2984
2990
  "PreferredMaintenanceWindow",
@@ -5077,18 +5083,18 @@ function isSelfEchoTrivialEmpty(v, physicalId) {
5077
5083
  const rest = entries.filter(([, val]) => val !== physicalId);
5078
5084
  return rest.length < entries.length && rest.every(([, val]) => isTrivialEmpty(val));
5079
5085
  }
5080
- const RDS_OPTION_SETTING_DEFAULTS = {
5081
- SERVER_AUDIT: "FORCE_PLUS_PERMANENT",
5082
- SERVER_AUDIT_LOGGING: "ON",
5083
- SERVER_AUDIT_FILE_PATH: "/rdsdbdata/log/audit/"
5084
- };
5085
5086
  function isIdentityOnlyHusk(el, idField) {
5086
5087
  return Object.entries(el).every(([k, v]) => k === idField || isTrivialEmpty(v));
5087
5088
  }
5088
- function isRdsOptionSettingDefault(resourceType, el, name, value) {
5089
- if (resourceType !== "AWS::RDS::OptionGroup") return false;
5090
- if (isIdentityOnlyHusk(el, "Name")) return true;
5091
- return name in RDS_OPTION_SETTING_DEFAULTS && value === RDS_OPTION_SETTING_DEFAULTS[name];
5089
+ function rdsMaterializedDefault(catalog, physicalId, declared, path, settingName) {
5090
+ if (!catalog || physicalId === void 0) return void 0;
5091
+ const m = /OptionConfigurations\.(\d+)\.OptionSettings$/.exec(path);
5092
+ if (!m) return void 0;
5093
+ const configs = declared?.OptionConfigurations;
5094
+ const optName = Array.isArray(configs) ? configs[Number(m[1])]?.OptionName : void 0;
5095
+ if (typeof optName !== "string") return void 0;
5096
+ const perOption = catalog[physicalId]?.[optName];
5097
+ return perOption && settingName in perOption ? perOption[settingName] : void 0;
5092
5098
  }
5093
5099
  function isEmptyPolicyShell(v) {
5094
5100
  if (v === null || typeof v !== "object" || Array.isArray(v)) return false;
@@ -5785,7 +5791,12 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
5785
5791
  const loName = String(loRec[nvSubsetSpec.nameField]);
5786
5792
  const loValue = loRec[nvSubsetSpec.valueField];
5787
5793
  const isFirehoseRetriesDefault = resourceType === "AWS::KinesisFirehose::DeliveryStream" && loName === "NumberOfRetries" && loValue === "3";
5788
- const isRdsOptionDefault = isRdsOptionSettingDefault(resourceType, loRec, loName, loValue);
5794
+ let isRdsOptionDefault = false;
5795
+ if (resourceType === "AWS::RDS::OptionGroup") if (isIdentityOnlyHusk(loRec, nvSubsetSpec.nameField)) isRdsOptionDefault = true;
5796
+ else {
5797
+ const matDefault = rdsMaterializedDefault(opts.rdsOptionSettingDefaults, physicalId, declaredIn, d.path, loName);
5798
+ isRdsOptionDefault = matDefault != null && matDefault === loValue;
5799
+ }
5789
5800
  findings.push({
5790
5801
  tier: isFirehoseRetriesDefault || isRdsOptionDefault ? "atDefault" : "undeclared",
5791
5802
  logicalId,
@@ -10456,6 +10467,56 @@ function buildClusterEchoModels(desired) {
10456
10467
  }
10457
10468
  return map;
10458
10469
  }
10470
+ async function buildRdsOptionSettingDefaults(desired, region) {
10471
+ const groups = desired.resources.filter((r) => r.resourceType === "AWS::RDS::OptionGroup" && r.physicalId);
10472
+ if (groups.length === 0) return {};
10473
+ const client = new RDSClient({
10474
+ region,
10475
+ ...READ_RETRY
10476
+ });
10477
+ const catalogCache = /* @__PURE__ */ new Map();
10478
+ const out = {};
10479
+ let warned = false;
10480
+ for (const r of groups) {
10481
+ const decl = r.declared;
10482
+ const engine = typeof decl?.EngineName === "string" ? decl.EngineName : void 0;
10483
+ const version = decl?.MajorEngineVersion != null ? String(decl.MajorEngineVersion) : void 0;
10484
+ if (!engine || !version || !r.physicalId) continue;
10485
+ const key = `${engine}:${version}`;
10486
+ let catalog = catalogCache.get(key);
10487
+ if (!catalog) try {
10488
+ catalog = await fetchOptionCatalog(client, engine, version);
10489
+ catalogCache.set(key, catalog);
10490
+ } catch (e) {
10491
+ if (!warned) {
10492
+ console.error(`warning: describe-option-group-options failed for ${engine} ${version} (${e.name}) — RDS OptionGroup default-fill settings may surface as first-run drift; grant rds:DescribeOptionGroupOptions`);
10493
+ warned = true;
10494
+ }
10495
+ continue;
10496
+ }
10497
+ out[r.physicalId] = catalog;
10498
+ }
10499
+ return out;
10500
+ }
10501
+ async function fetchOptionCatalog(client, engineName, majorEngineVersion) {
10502
+ const catalog = {};
10503
+ let marker;
10504
+ do {
10505
+ const resp = await client.send(new DescribeOptionGroupOptionsCommand({
10506
+ EngineName: engineName,
10507
+ MajorEngineVersion: majorEngineVersion,
10508
+ Marker: marker
10509
+ }));
10510
+ for (const opt of resp.OptionGroupOptions ?? []) {
10511
+ if (!opt.Name) continue;
10512
+ const settings = catalog[opt.Name] ?? {};
10513
+ for (const s of opt.OptionGroupOptionSettings ?? []) if (s.SettingName) settings[s.SettingName] = s.DefaultValue ?? null;
10514
+ catalog[opt.Name] = settings;
10515
+ }
10516
+ marker = resp.Marker;
10517
+ } while (marker);
10518
+ return catalog;
10519
+ }
10459
10520
  const OAI_TYPE = "AWS::CloudFront::CloudFrontOriginAccessIdentity";
10460
10521
  function buildOaiCanonicalIds(desired) {
10461
10522
  const map = {};
@@ -10593,7 +10654,8 @@ async function gatherFindings(stackName, region, templateOverride, recoveryTempl
10593
10654
  siblingManagedPolicyAttachments: buildSiblingManagedPolicyAttachments(desired),
10594
10655
  siblingUserGroups: buildSiblingUserGroups(desired),
10595
10656
  bucketNotificationManaged: buildBucketNotificationManaged(desired),
10596
- clusterEchoModel: buildClusterEchoModels(desired)
10657
+ clusterEchoModel: buildClusterEchoModels(desired),
10658
+ rdsOptionSettingDefaults: await buildRdsOptionSettingDefaults(desired, region)
10597
10659
  };
10598
10660
  const corpusDir = process.env[CORPUS_DIR_ENV];
10599
10661
  for (const r of desired.resources) {
@@ -10654,7 +10716,8 @@ async function regatherTouched(gathered, touched, region) {
10654
10716
  siblingManagedPolicyAttachments: buildSiblingManagedPolicyAttachments(desired),
10655
10717
  siblingUserGroups: buildSiblingUserGroups(desired),
10656
10718
  bucketNotificationManaged: buildBucketNotificationManaged(desired),
10657
- clusterEchoModel: buildClusterEchoModels(desired)
10719
+ clusterEchoModel: buildClusterEchoModels(desired),
10720
+ rdsOptionSettingDefaults: await buildRdsOptionSettingDefaults(desired, region)
10658
10721
  };
10659
10722
  const fresh = [];
10660
10723
  for (const r of targets) fresh.push(...await classifyRead(cfn, r, reads.get(r.logicalId), schemas, classifyOpts));