cdk-real-drift 0.7.6 → 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
@@ -339,9 +339,16 @@ CI (with `--yes`).
339
339
  - **`--fail`** (the `cdk diff --fail` / `cdk drift --fail` convention) exits `1` on
340
340
  drift and suppresses all prompts. It's the one flag for scripts and CI.
341
341
  - **`--strict`** is the orthogonal **coverage** axis: it exits `1` when a run was
342
- incomplete (any resource skipped, or a nested stack not recursed into). The gap
343
- is always surfaced regardless (as the `skipped=N` footer line or a loud
344
- `warning:`); `--strict` only decides whether it fails the build.
342
+ incomplete (a resource skipped for an ACTIONABLE reason — a CC-unsupported type
343
+ with no override, a read error / throttle / AccessDenied — or a nested stack not
344
+ recursed into). A **custom resource** (`Custom::*` /
345
+ `AWS::CloudFormation::CustomResource`, e.g. `Custom::S3AutoDeleteObjects` /
346
+ `Custom::LogRetention`) has no cloud-side model to read, so it is a
347
+ permanent-by-nature gap that no `record` / `ignore` could clear — it is
348
+ **informational** and does NOT fail `--strict` (otherwise the flag would exit `1`
349
+ forever on nearly every real CDK app). The gap is always surfaced regardless (as
350
+ the `skipped=N` footer line or a loud `warning:`); `--strict` only decides whether
351
+ an actionable gap fails the build.
345
352
  - Errors always exit `2`; `revert` exits `1` when drift remains after it.
346
353
  - Interrupting a run with **Ctrl-C** (or **ESC** / SIGINT) during the gather/read
347
354
  phase exits `130` (128 + SIGINT) for every verb, and a **SIGTERM** (CI
@@ -824,7 +831,13 @@ covers them. **If you never run `revert`, cdkrd needs no write permissions at al
824
831
  `glue:GetClassifier` + `glue:GetWorkflow` + `glue:GetConnection`
825
832
  (`glue:GetConnection` is issued with `HidePassword` so NO credential enters the
826
833
  baseline — read an `AWS::Glue::Classifier` / `Workflow` / `Connection`, the rest
827
- 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)
828
841
  - Optional: `elasticloadbalancing:GetTrustStoreCaCertificatesBundle` records a
829
842
  content hash of an `AWS::ElasticLoadBalancingV2::TrustStore`'s live mTLS CA
830
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";
@@ -48,6 +48,7 @@ import { BuildBotLocaleCommand, CreateIntentCommand, CreateSlotCommand, CreateSl
48
48
  import { GetScheduleCommand, SchedulerClient } from "@aws-sdk/client-scheduler";
49
49
  import { DescribeReceiptRuleCommand, DescribeReceiptRuleSetCommand, ListReceiptFiltersCommand, SESClient, UpdateReceiptRuleCommand } from "@aws-sdk/client-ses";
50
50
  import { DescribeParametersCommand as DescribeParametersCommand$2, SSMClient } from "@aws-sdk/client-ssm";
51
+ import { DescribeEndpointConfigCommand, SageMakerClient } from "@aws-sdk/client-sagemaker";
51
52
  import { GetNamespaceCommand, GetServiceCommand, ServiceDiscoveryClient, UpdateHttpNamespaceCommand } from "@aws-sdk/client-servicediscovery";
52
53
  import { GetQueueAttributesCommand, SQSClient, SetQueueAttributesCommand } from "@aws-sdk/client-sqs";
53
54
  import { createHash } from "node:crypto";
@@ -1633,6 +1634,7 @@ function buildCorpusCase(resource, liveRaw, schema, opts, findings) {
1633
1634
  const sgSibling = resource.resourceType === "AWS::EC2::SecurityGroup" && resource.physicalId ? opts.siblingSgRules?.[resource.physicalId] : void 0;
1634
1635
  const bucketNotif = resource.physicalId && opts.bucketNotificationManaged?.has(resource.physicalId) ? [resource.physicalId] : void 0;
1635
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;
1636
1638
  return sanitizeAccountId({
1637
1639
  corpusVersion: 1,
1638
1640
  resource: {
@@ -1664,7 +1666,8 @@ function buildCorpusCase(resource, liveRaw, schema, opts, findings) {
1664
1666
  oaiCanonicalIds: opts.oaiCanonicalIds,
1665
1667
  ...sgSibling && resource.physicalId ? { siblingSgRules: { [resource.physicalId]: sgSibling } } : {},
1666
1668
  ...bucketNotif ? { bucketNotificationManaged: bucketNotif } : {},
1667
- ...echoModel && resource.physicalId ? { clusterEchoModel: { [resource.physicalId]: echoModel } } : {}
1669
+ ...echoModel && resource.physicalId ? { clusterEchoModel: { [resource.physicalId]: echoModel } } : {},
1670
+ ...rdsOptCatalog && resource.physicalId ? { rdsOptionSettingDefaults: { [resource.physicalId]: rdsOptCatalog } } : {}
1668
1671
  },
1669
1672
  expected: findings
1670
1673
  }, opts.accountId);
@@ -2977,7 +2980,11 @@ const VALUE_INDEPENDENT_DEFAULT_TOPLEVEL_PATHS = {
2977
2980
  "AWS::EC2::SecurityGroupEgress": new Set(["DestinationSecurityGroupName"]),
2978
2981
  "AWS::DocDB::DBCluster": new Set(["PreferredMaintenanceWindow", "PreferredBackupWindow"]),
2979
2982
  "AWS::DocDB::DBInstance": new Set(["PreferredMaintenanceWindow"]),
2980
- "AWS::Neptune::DBCluster": new Set(["PreferredMaintenanceWindow", "PreferredBackupWindow"]),
2983
+ "AWS::Neptune::DBCluster": new Set([
2984
+ "PreferredMaintenanceWindow",
2985
+ "PreferredBackupWindow",
2986
+ "EngineVersion"
2987
+ ]),
2981
2988
  "AWS::Neptune::DBInstance": new Set(["PreferredMaintenanceWindow", "AvailabilityZone"]),
2982
2989
  "AWS::ElastiCache::CacheCluster": new Set([
2983
2990
  "PreferredMaintenanceWindow",
@@ -5076,18 +5083,18 @@ function isSelfEchoTrivialEmpty(v, physicalId) {
5076
5083
  const rest = entries.filter(([, val]) => val !== physicalId);
5077
5084
  return rest.length < entries.length && rest.every(([, val]) => isTrivialEmpty(val));
5078
5085
  }
5079
- const RDS_OPTION_SETTING_DEFAULTS = {
5080
- SERVER_AUDIT: "FORCE_PLUS_PERMANENT",
5081
- SERVER_AUDIT_LOGGING: "ON",
5082
- SERVER_AUDIT_FILE_PATH: "/rdsdbdata/log/audit/"
5083
- };
5084
5086
  function isIdentityOnlyHusk(el, idField) {
5085
5087
  return Object.entries(el).every(([k, v]) => k === idField || isTrivialEmpty(v));
5086
5088
  }
5087
- function isRdsOptionSettingDefault(resourceType, el, name, value) {
5088
- if (resourceType !== "AWS::RDS::OptionGroup") return false;
5089
- if (isIdentityOnlyHusk(el, "Name")) return true;
5090
- 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;
5091
5098
  }
5092
5099
  function isEmptyPolicyShell(v) {
5093
5100
  if (v === null || typeof v !== "object" || Array.isArray(v)) return false;
@@ -5784,7 +5791,12 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
5784
5791
  const loName = String(loRec[nvSubsetSpec.nameField]);
5785
5792
  const loValue = loRec[nvSubsetSpec.valueField];
5786
5793
  const isFirehoseRetriesDefault = resourceType === "AWS::KinesisFirehose::DeliveryStream" && loName === "NumberOfRetries" && loValue === "3";
5787
- 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
+ }
5788
5800
  findings.push({
5789
5801
  tier: isFirehoseRetriesDefault || isRdsOptionDefault ? "atDefault" : "undeclared",
5790
5802
  logicalId,
@@ -8806,6 +8818,47 @@ const readGlueSecurityConfiguration = async ({ physicalId, declared, region }) =
8806
8818
  if (Object.keys(ec).length > 0) model.EncryptionConfiguration = ec;
8807
8819
  return model;
8808
8820
  };
8821
+ const projectSageMakerVariant = (v) => {
8822
+ const out = {};
8823
+ if (str$1(v.VariantName)) out.VariantName = v.VariantName;
8824
+ if (str$1(v.ModelName)) out.ModelName = v.ModelName;
8825
+ if (typeof v.InitialInstanceCount === "number") out.InitialInstanceCount = v.InitialInstanceCount;
8826
+ if (str$1(v.InstanceType)) out.InstanceType = v.InstanceType;
8827
+ if (typeof v.InitialVariantWeight === "number") out.InitialVariantWeight = v.InitialVariantWeight;
8828
+ if (v.ServerlessConfig !== void 0) out.ServerlessConfig = v.ServerlessConfig;
8829
+ if (typeof v.VolumeSizeInGB === "number") out.VolumeSizeInGB = v.VolumeSizeInGB;
8830
+ if (typeof v.ModelDataDownloadTimeoutInSeconds === "number") out.ModelDataDownloadTimeoutInSeconds = v.ModelDataDownloadTimeoutInSeconds;
8831
+ if (typeof v.ContainerStartupHealthCheckTimeoutInSeconds === "number") out.ContainerStartupHealthCheckTimeoutInSeconds = v.ContainerStartupHealthCheckTimeoutInSeconds;
8832
+ if (typeof v.EnableSSMAccess === "boolean") out.EnableSSMAccess = v.EnableSSMAccess;
8833
+ if (v.ManagedInstanceScaling !== void 0) out.ManagedInstanceScaling = v.ManagedInstanceScaling;
8834
+ if (v.RoutingConfig !== void 0) out.RoutingConfig = v.RoutingConfig;
8835
+ if (typeof v.VariantInstanceProvisionTimeoutInSeconds === "number") out.VariantInstanceProvisionTimeoutInSeconds = v.VariantInstanceProvisionTimeoutInSeconds;
8836
+ if (Array.isArray(v.InstancePools) && v.InstancePools.length > 0) out.InstancePools = v.InstancePools;
8837
+ if (v.CapacityReservationConfig !== void 0) out.CapacityReservationConfig = v.CapacityReservationConfig;
8838
+ if (str$1(v.InferenceAmiVersion)) out.InferenceAmiVersion = v.InferenceAmiVersion;
8839
+ return out;
8840
+ };
8841
+ const readSageMakerEndpointConfig = async ({ physicalId, declared, region }) => {
8842
+ const name = str$1(physicalId) ?? str$1(declared.EndpointConfigName);
8843
+ if (!name) return void 0;
8844
+ const r = await new SageMakerClient({
8845
+ region,
8846
+ ...READ_RETRY
8847
+ }).send(new DescribeEndpointConfigCommand({ EndpointConfigName: name }));
8848
+ if (!r.EndpointConfigName) throw new ResourceGoneError(`SageMaker EndpointConfig ${name} absent`);
8849
+ const model = {};
8850
+ if (str$1(r.EndpointConfigName)) model.EndpointConfigName = r.EndpointConfigName;
8851
+ if (Array.isArray(r.ProductionVariants) && r.ProductionVariants.length > 0) model.ProductionVariants = r.ProductionVariants.map(projectSageMakerVariant);
8852
+ if (Array.isArray(r.ShadowProductionVariants) && r.ShadowProductionVariants.length > 0) model.ShadowProductionVariants = r.ShadowProductionVariants.map(projectSageMakerVariant);
8853
+ if (r.DataCaptureConfig !== void 0) model.DataCaptureConfig = r.DataCaptureConfig;
8854
+ if (r.AsyncInferenceConfig !== void 0) model.AsyncInferenceConfig = r.AsyncInferenceConfig;
8855
+ if (str$1(r.KmsKeyId)) model.KmsKeyId = r.KmsKeyId;
8856
+ if (r.ExplainerConfig !== void 0) model.ExplainerConfig = r.ExplainerConfig;
8857
+ if (typeof r.EnableNetworkIsolation === "boolean") model.EnableNetworkIsolation = r.EnableNetworkIsolation;
8858
+ if (str$1(r.ExecutionRoleArn)) model.ExecutionRoleArn = r.ExecutionRoleArn;
8859
+ if (r.VpcConfig !== void 0) model.VpcConfig = r.VpcConfig;
8860
+ return model;
8861
+ };
8809
8862
  const readMetricFilter = async ({ physicalId, declared, region }) => {
8810
8863
  const logGroup = str$1(declared.LogGroupName);
8811
8864
  const filterName = str$1(physicalId) ?? str$1(declared.FilterName);
@@ -9264,6 +9317,7 @@ const SDK_OVERRIDES = {
9264
9317
  "AWS::Glue::Workflow": readGlueWorkflow,
9265
9318
  "AWS::Glue::Connection": readGlueConnection,
9266
9319
  "AWS::Glue::SecurityConfiguration": readGlueSecurityConfiguration,
9320
+ "AWS::SageMaker::EndpointConfig": readSageMakerEndpointConfig,
9267
9321
  "AWS::Logs::MetricFilter": readMetricFilter,
9268
9322
  "AWS::Scheduler::Schedule": readSchedulerSchedule
9269
9323
  };
@@ -10413,6 +10467,56 @@ function buildClusterEchoModels(desired) {
10413
10467
  }
10414
10468
  return map;
10415
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
+ }
10416
10520
  const OAI_TYPE = "AWS::CloudFront::CloudFrontOriginAccessIdentity";
10417
10521
  function buildOaiCanonicalIds(desired) {
10418
10522
  const map = {};
@@ -10550,7 +10654,8 @@ async function gatherFindings(stackName, region, templateOverride, recoveryTempl
10550
10654
  siblingManagedPolicyAttachments: buildSiblingManagedPolicyAttachments(desired),
10551
10655
  siblingUserGroups: buildSiblingUserGroups(desired),
10552
10656
  bucketNotificationManaged: buildBucketNotificationManaged(desired),
10553
- clusterEchoModel: buildClusterEchoModels(desired)
10657
+ clusterEchoModel: buildClusterEchoModels(desired),
10658
+ rdsOptionSettingDefaults: await buildRdsOptionSettingDefaults(desired, region)
10554
10659
  };
10555
10660
  const corpusDir = process.env[CORPUS_DIR_ENV];
10556
10661
  for (const r of desired.resources) {
@@ -10611,7 +10716,8 @@ async function regatherTouched(gathered, touched, region) {
10611
10716
  siblingManagedPolicyAttachments: buildSiblingManagedPolicyAttachments(desired),
10612
10717
  siblingUserGroups: buildSiblingUserGroups(desired),
10613
10718
  bucketNotificationManaged: buildBucketNotificationManaged(desired),
10614
- clusterEchoModel: buildClusterEchoModels(desired)
10719
+ clusterEchoModel: buildClusterEchoModels(desired),
10720
+ rdsOptionSettingDefaults: await buildRdsOptionSettingDefaults(desired, region)
10615
10721
  };
10616
10722
  const fresh = [];
10617
10723
  for (const r of targets) fresh.push(...await classifyRead(cfn, r, reads.get(r.logicalId), schemas, classifyOpts));
@@ -16038,6 +16144,9 @@ function nestedStackWarning(resources, stackName) {
16038
16144
  function isPendingCreationSkip(f) {
16039
16145
  return f.tier === "skipped" && f.note === "no physical id";
16040
16146
  }
16147
+ function isCustomResourceSkip(f) {
16148
+ return f.tier === "skipped" && (f.resourceType === "AWS::CloudFormation::CustomResource" || f.resourceType.startsWith("Custom::"));
16149
+ }
16041
16150
  function coverageWarning(findings, stackName, preDeploy = false) {
16042
16151
  const skipped = findings.filter((f) => f.tier === "skipped" && !(preDeploy && isPendingCreationSkip(f)));
16043
16152
  if (skipped.length === 0) return null;
@@ -16055,7 +16164,7 @@ function pendingCreationInfo(findings, stackName) {
16055
16164
  return `info: ${stackName}: ${pending.length} resource(s) not yet deployed — will be created by the next deploy (pending creation, not a coverage gap): ${shown.join(", ")}${more}`;
16056
16165
  }
16057
16166
  function hasCoverageGap(findings, resources, preDeploy = false) {
16058
- return findings.some((f) => f.tier === "skipped" && !(preDeploy && isPendingCreationSkip(f))) || resources.some((r) => r.resourceType === "AWS::CloudFormation::Stack");
16167
+ return findings.some((f) => f.tier === "skipped" && !(preDeploy && isPendingCreationSkip(f)) && !isCustomResourceSkip(f)) || resources.some((r) => r.resourceType === "AWS::CloudFormation::Stack");
16059
16168
  }
16060
16169
  function strictCoverageExit(strict, findings, resources, preDeploy = false) {
16061
16170
  return strict && hasCoverageGap(findings, resources, preDeploy) ? 1 : 0;