cdk-real-drift 0.12.7 → 0.12.9

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
@@ -637,7 +637,11 @@ Elastic Beanstalk env-namespace `OptionSettings`, EC2 LaunchTemplate `UserData`
637
637
  are masked as `<redacted:NN chars>` in both text and `--json` output, so a rotated
638
638
  secret surfacing as drift does not leak its plaintext into CI logs. The finding
639
639
  still surfaces (detection is preserved) and the property/key name stays visible —
640
- only the value is hidden (#798).
640
+ only the value is hidden. The same protection covers persistence: `record` writes a
641
+ **hash** of these values into the git-committed baseline instead of the plaintext, so
642
+ the secret never lands in a committed file while a later change still re-surfaces as
643
+ drift (an unchanged one stays recorded). Older baselines holding a plaintext value keep
644
+ comparing correctly and migrate to the hashed form on the next `record` (#798).
641
645
 
642
646
  A **stack that errored or was skipped** before it could be checked still appears as an
643
647
  element so a consumer sees which stacks ran: it carries `"error": "<reason>"` alongside
package/dist/cli.js CHANGED
@@ -3232,7 +3232,12 @@ function stripAsymmetricIdentityFields(declared, live) {
3232
3232
  }
3233
3233
  const ORDER_SIGNIFICANT_ARRAY_KEYS = {
3234
3234
  "AWS::CodePipeline::Pipeline": new Set(["Stages", "Actions"]),
3235
- "AWS::Logs::Transformer": new Set(["TransformerConfig"])
3235
+ "AWS::Logs::Transformer": new Set(["TransformerConfig"]),
3236
+ "AWS::SSMContacts::Plan": new Set(["Stages"])
3237
+ };
3238
+ const ORDER_SIGNIFICANT_PATHS = {
3239
+ "AWS::Scheduler::Schedule": new Set(["Target.EcsParameters.PlacementStrategy"]),
3240
+ "AWS::AppSync::Resolver": new Set(["PipelineConfig.Functions"])
3236
3241
  };
3237
3242
  function canonicalizeTagListsDeep(v, orderSig) {
3238
3243
  return canonicalizeTagLists(v, orderSig, void 0);
@@ -5549,8 +5554,12 @@ function sortUnorderedSetProps(model, resourceType, schemaObjectArrayKeys = [],
5549
5554
  const objKeys = new Set([...UNORDERED_OBJECT_ARRAY_PROPS[resourceType] ?? [], ...schemaObjectArrayKeys]);
5550
5555
  const orderSig = ORDER_SIGNIFICANT_ARRAY_KEYS[resourceType];
5551
5556
  for (const k of objKeys) if (!orderSig?.has(k) && Array.isArray(model[k])) model[k] = sortUnorderedObjectArray(model[k]);
5552
- for (const path of [...UNORDERED_ARRAY_PROPS[resourceType] ?? [], ...schemaScalarPaths]) if (path.includes(".")) sortScalarSetAtNestedPath(model, path.split("."));
5553
- else if (path in model) model[path] = sortScalarSet(model[path]);
5557
+ const orderSigPaths = ORDER_SIGNIFICANT_PATHS[resourceType];
5558
+ for (const path of [...UNORDERED_ARRAY_PROPS[resourceType] ?? [], ...schemaScalarPaths]) {
5559
+ if (orderSigPaths?.has(path)) continue;
5560
+ if (path.includes(".")) sortScalarSetAtNestedPath(model, path.split("."));
5561
+ else if (path in model) model[path] = sortScalarSet(model[path]);
5562
+ }
5554
5563
  }
5555
5564
  function normalizeLiveModel(liveRaw, schema, opts = {}) {
5556
5565
  const oaiMap = opts.oaiCanonicalIds ?? {};
@@ -6162,7 +6171,8 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
6162
6171
  const subsetSpec = IDENTITY_KEYED_SUBSET_ARRAYS[resourceType]?.[k];
6163
6172
  const unorderedObjArray = !(ORDER_SIGNIFICANT_ARRAY_KEYS[resourceType]?.has(k) ?? false) && (UNORDERED_OBJECT_ARRAY_PROPS[resourceType]?.has(k) || (schema.unorderedObjectArrayPaths?.includes(k) ?? false));
6164
6173
  const nestedUnordered = UNORDERED_NESTED_OBJECT_ARRAY_PATHS[resourceType];
6165
- const nestedSubPaths = [...new Set([...nestedUnordered ?? [], ...schema.unorderedObjectArrayPaths ?? []].filter((p) => p.startsWith(`${k}.`)).map((p) => p.slice(k.length + 1)))];
6174
+ const orderSigPathsForType = ORDER_SIGNIFICANT_PATHS[resourceType];
6175
+ const nestedSubPaths = [...new Set([...nestedUnordered ?? [], ...schema.unorderedObjectArrayPaths ?? []].filter((p) => p.startsWith(`${k}.`) && !orderSigPathsForType?.has(p)).map((p) => p.slice(k.length + 1)))];
6166
6176
  let declaredVal = v;
6167
6177
  let liveVal = live[k];
6168
6178
  let declaredRemapSource;
@@ -6305,7 +6315,7 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
6305
6315
  if (VERSION_PREFIX_PATHS[resourceType]?.has(d.path) && isVersionPrefixMatch(d.stateValue, d.awsValue)) continue;
6306
6316
  if (LATEST_SENTINEL_PATHS[resourceType]?.has(d.path) && isLatestSentinelMatch(d.stateValue, d.awsValue)) continue;
6307
6317
  if (INTELLIGENT_TIERING_PATHS[resourceType]?.has(d.path) && isIntelligentTieringMatch(d.stateValue, d.awsValue)) continue;
6308
- if ((UNORDERED_ARRAY_PROPS[resourceType]?.has(d.path) || UNORDERED_ARRAY_PROPS[resourceType]?.has(d.path.replace(/\.\d+(?=\.|$)/g, ".*")) || schema.unorderedScalarPaths?.includes(d.path)) && isEqualUnorderedScalarSet(d.stateValue, d.awsValue)) continue;
6318
+ if ((UNORDERED_ARRAY_PROPS[resourceType]?.has(d.path) || UNORDERED_ARRAY_PROPS[resourceType]?.has(d.path.replace(/\.\d+(?=\.|$)/g, ".*")) || schema.unorderedScalarPaths?.includes(d.path)) && !ORDER_SIGNIFICANT_PATHS[resourceType]?.has(d.path) && isEqualUnorderedScalarSet(d.stateValue, d.awsValue)) continue;
6309
6319
  if (isTrivialEmpty(d.stateValue) && d.path in knownDef && deepEqual(d.awsValue, knownDef[d.path]) && !(MEANINGFUL_WHEN_OFF[resourceType]?.[d.path]?.({
6310
6320
  declared,
6311
6321
  live
@@ -8496,12 +8506,16 @@ async function enumerateEfsFileSystemChildren(ctx) {
8496
8506
  }))
8497
8507
  });
8498
8508
  }
8509
+ function isImplicitClusterMemberName(clusterId, instanceId) {
8510
+ const escaped = clusterId.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
8511
+ return new RegExp(`^${escaped}-instance-\\d+$`).test(instanceId);
8512
+ }
8499
8513
  function diffRdsClusterChildren(input) {
8500
8514
  const declared = new Set(input.declaredInstanceIds);
8501
8515
  const clusterMembers = new Set(input.clusterMemberIds);
8502
8516
  const added = [];
8503
8517
  for (const i of input.liveInstances) {
8504
- if (declared.has(i.id) || clusterMembers.has(i.id)) continue;
8518
+ if (declared.has(i.id) || clusterMembers.has(i.id) && isImplicitClusterMemberName(input.clusterId, i.id)) continue;
8505
8519
  added.push({
8506
8520
  resourceType: "AWS::RDS::DBInstance",
8507
8521
  identifier: i.id,
@@ -8546,6 +8560,7 @@ async function enumerateRdsClusterChildren(ctx) {
8546
8560
  });
8547
8561
  const [instances, clusterMemberIds] = await Promise.all([pageDbInstances(client, clusterId), describeClusterMemberIds(client, clusterId)]);
8548
8562
  return diffRdsClusterChildren({
8563
+ clusterId,
8549
8564
  declaredInstanceIds,
8550
8565
  liveInstances: instances.filter((i) => typeof i.DBInstanceIdentifier === "string" && !isAasManagedReader(i.DBInstanceIdentifier)).map((i) => ({
8551
8566
  id: i.DBInstanceIdentifier,
@@ -11765,6 +11780,113 @@ function stackCountAnnouncement(stackNames) {
11765
11780
  return `note: checking ${stackNames.length} stack(s): ${stackNames.join(", ")}`;
11766
11781
  }
11767
11782
 
11783
+ //#endregion
11784
+ //#region src/report/redact.ts
11785
+ function maskPlaceholder(value) {
11786
+ if (typeof value === "string") return `<redacted:${value.length} chars>`;
11787
+ return "<redacted>";
11788
+ }
11789
+ const maskWhole = (value) => maskPlaceholder(value);
11790
+ const maskEntryValueField = (value) => {
11791
+ if (value && typeof value === "object" && !Array.isArray(value) && "Value" in value) return {
11792
+ ...value,
11793
+ Value: maskPlaceholder(value.Value)
11794
+ };
11795
+ return maskPlaceholder(value);
11796
+ };
11797
+ const maskMapValues = (value) => {
11798
+ if (value && typeof value === "object" && !Array.isArray(value)) {
11799
+ const out = {};
11800
+ for (const [k, v] of Object.entries(value)) out[k] = maskPlaceholder(v);
11801
+ return out;
11802
+ }
11803
+ return maskPlaceholder(value);
11804
+ };
11805
+ const REDACTED_VALUE_PATHS = {
11806
+ "AWS::Lambda::Function": [{
11807
+ pathRe: /(^|\.)Environment\.Variables\./,
11808
+ redact: maskWhole
11809
+ }, {
11810
+ pathRe: /(^|\.)Environment\.Variables$/,
11811
+ redact: maskMapValues
11812
+ }],
11813
+ "AWS::CodeBuild::Project": [{
11814
+ pathRe: /(^|\.)Environment\.EnvironmentVariables\.\d+\.Value$/,
11815
+ redact: maskWhole
11816
+ }],
11817
+ "AWS::EC2::LaunchTemplate": [{
11818
+ pathRe: /(^|\.)LaunchTemplateData\.UserData$/,
11819
+ redact: maskWhole
11820
+ }],
11821
+ "AWS::ElasticBeanstalk::Environment": [{
11822
+ pathRe: /(^|\.)OptionSettings\[aws:elasticbeanstalk:application:environment\|/,
11823
+ redact: maskEntryValueField
11824
+ }]
11825
+ };
11826
+ function redactValue(resourceType, path, value) {
11827
+ const matchers = REDACTED_VALUE_PATHS[resourceType];
11828
+ if (!matchers) return value;
11829
+ if (isRedactedHashSentinel(value)) return "<redacted>";
11830
+ for (const m of matchers) if (m.pathRe.test(path)) return m.redact(value);
11831
+ return value;
11832
+ }
11833
+ function isRedactedPath(resourceType, path) {
11834
+ const matchers = REDACTED_VALUE_PATHS[resourceType];
11835
+ return !!matchers && matchers.some((m) => m.pathRe.test(path));
11836
+ }
11837
+ function redactFinding(f) {
11838
+ if (!isRedactedPath(f.resourceType, f.path)) return f;
11839
+ const out = { ...f };
11840
+ if ("desired" in f && f.desired !== void 0) out.desired = redactValue(f.resourceType, f.path, f.desired);
11841
+ if ("actual" in f && f.actual !== void 0) out.actual = redactValue(f.resourceType, f.path, f.actual);
11842
+ if (f.arrayDelta && typeof f.arrayDelta === "object") out.arrayDelta = redactArrayDelta(f.resourceType, f.path, f.arrayDelta);
11843
+ return out;
11844
+ }
11845
+ function redactArrayDelta(resourceType, path, d) {
11846
+ const mv = (v) => redactValue(resourceType, path, v);
11847
+ return {
11848
+ identityField: d.identityField,
11849
+ added: d.added.map((a) => ({
11850
+ id: a.id,
11851
+ value: mv(a.value)
11852
+ })),
11853
+ removed: d.removed.map((r) => ({
11854
+ id: r.id,
11855
+ value: mv(r.value)
11856
+ })),
11857
+ changed: d.changed.map((c) => ({
11858
+ id: c.id,
11859
+ recorded: mv(c.recorded),
11860
+ actual: mv(c.actual)
11861
+ }))
11862
+ };
11863
+ }
11864
+ const REDACTION_HASH_KEY = "__cdkrdRedactedSha256__";
11865
+ function stableStringify(v) {
11866
+ const sortDeep = (x) => {
11867
+ if (Array.isArray(x)) return x.map(sortDeep);
11868
+ if (x && typeof x === "object") {
11869
+ const out = {};
11870
+ for (const k of Object.keys(x).sort()) out[k] = sortDeep(x[k]);
11871
+ return out;
11872
+ }
11873
+ return x;
11874
+ };
11875
+ return JSON.stringify(sortDeep(v)) ?? "null";
11876
+ }
11877
+ function hashOfCanonical(canonicalValue) {
11878
+ return "sha256:" + createHash("sha256").update(stableStringify(canonicalValue)).digest("hex");
11879
+ }
11880
+ function redactedHashSentinel(canonicalValue) {
11881
+ return { [REDACTION_HASH_KEY]: hashOfCanonical(canonicalValue) };
11882
+ }
11883
+ function isRedactedHashSentinel(v) {
11884
+ return !!v && typeof v === "object" && !Array.isArray(v) && Object.keys(v).length === 1 && typeof v[REDACTION_HASH_KEY] === "string";
11885
+ }
11886
+ function redactedHashOf(sentinelOrCanonical) {
11887
+ return isRedactedHashSentinel(sentinelOrCanonical) ? sentinelOrCanonical[REDACTION_HASH_KEY] ?? hashOfCanonical(sentinelOrCanonical) : hashOfCanonical(sentinelOrCanonical);
11888
+ }
11889
+
11768
11890
  //#endregion
11769
11891
  //#region src/baseline/baseline-file.ts
11770
11892
  const KNOWN_BASELINE_KEYS = new Set([
@@ -12066,7 +12188,7 @@ function buildRecorded(findings) {
12066
12188
  logicalId: f.logicalId,
12067
12189
  resourceType: f.resourceType,
12068
12190
  path: f.path,
12069
- value: f.actual
12191
+ value: isRedactedPath(f.resourceType, f.path) ? redactedHashSentinel(canonicalizeBaselineForCompare(f.actual, f.resourceType)) : f.actual
12070
12192
  }));
12071
12193
  }
12072
12194
  /** Stable key uniquely identifying an undeclared finding / recorded entry, for
@@ -12176,6 +12298,10 @@ function carryForwardIgnored(recorded, existing, findings) {
12176
12298
  * order-significant declared array, so an order-insensitive sort is safe here.
12177
12299
  */
12178
12300
  function baselineValueMatches(baselineValue, currentCanonicalValue, resourceType) {
12301
+ if (isRedactedHashSentinel(baselineValue) || isRedactedHashSentinel(currentCanonicalValue)) {
12302
+ const asHash = (v) => redactedHashOf(isRedactedHashSentinel(v) ? v : canonicalizeBaselineForCompare(v, resourceType));
12303
+ return asHash(baselineValue) === asHash(currentCanonicalValue);
12304
+ }
12179
12305
  return deepEqual(canonicalizeBaselineForCompare(baselineValue, resourceType), canonicalizeBaselineForCompare(currentCanonicalValue, resourceType));
12180
12306
  }
12181
12307
  const DELTA_IDENTITY_FIELDS = [
@@ -16440,87 +16566,6 @@ function annotateHints(findings) {
16440
16566
  });
16441
16567
  }
16442
16568
 
16443
- //#endregion
16444
- //#region src/report/redact.ts
16445
- function maskPlaceholder(value) {
16446
- if (typeof value === "string") return `<redacted:${value.length} chars>`;
16447
- return "<redacted>";
16448
- }
16449
- const maskWhole = (value) => maskPlaceholder(value);
16450
- const maskEntryValueField = (value) => {
16451
- if (value && typeof value === "object" && !Array.isArray(value) && "Value" in value) return {
16452
- ...value,
16453
- Value: maskPlaceholder(value.Value)
16454
- };
16455
- return maskPlaceholder(value);
16456
- };
16457
- const maskMapValues = (value) => {
16458
- if (value && typeof value === "object" && !Array.isArray(value)) {
16459
- const out = {};
16460
- for (const [k, v] of Object.entries(value)) out[k] = maskPlaceholder(v);
16461
- return out;
16462
- }
16463
- return maskPlaceholder(value);
16464
- };
16465
- const REDACTED_VALUE_PATHS = {
16466
- "AWS::Lambda::Function": [{
16467
- pathRe: /(^|\.)Environment\.Variables\./,
16468
- redact: maskWhole
16469
- }, {
16470
- pathRe: /(^|\.)Environment\.Variables$/,
16471
- redact: maskMapValues
16472
- }],
16473
- "AWS::CodeBuild::Project": [{
16474
- pathRe: /(^|\.)Environment\.EnvironmentVariables\.\d+\.Value$/,
16475
- redact: maskWhole
16476
- }],
16477
- "AWS::EC2::LaunchTemplate": [{
16478
- pathRe: /(^|\.)LaunchTemplateData\.UserData$/,
16479
- redact: maskWhole
16480
- }],
16481
- "AWS::ElasticBeanstalk::Environment": [{
16482
- pathRe: /(^|\.)OptionSettings\[aws:elasticbeanstalk:application:environment\|/,
16483
- redact: maskEntryValueField
16484
- }]
16485
- };
16486
- function redactValue(resourceType, path, value) {
16487
- const matchers = REDACTED_VALUE_PATHS[resourceType];
16488
- if (!matchers) return value;
16489
- for (const m of matchers) if (m.pathRe.test(path)) return m.redact(value);
16490
- return value;
16491
- }
16492
- function isRedactedPath(resourceType, path) {
16493
- const matchers = REDACTED_VALUE_PATHS[resourceType];
16494
- return !!matchers && matchers.some((m) => m.pathRe.test(path));
16495
- }
16496
- function redactFinding(f) {
16497
- if (!isRedactedPath(f.resourceType, f.path)) return f;
16498
- const out = { ...f };
16499
- if ("desired" in f && f.desired !== void 0) out.desired = redactValue(f.resourceType, f.path, f.desired);
16500
- if ("actual" in f && f.actual !== void 0) out.actual = redactValue(f.resourceType, f.path, f.actual);
16501
- if (f.arrayDelta && typeof f.arrayDelta === "object") out.arrayDelta = redactArrayDelta(f.resourceType, f.path, f.arrayDelta);
16502
- return out;
16503
- }
16504
- function redactArrayDelta(resourceType, path, d) {
16505
- const mv = (v) => redactValue(resourceType, path, v);
16506
- return {
16507
- identityField: d.identityField,
16508
- added: d.added.map((a) => ({
16509
- id: a.id,
16510
- value: mv(a.value)
16511
- })),
16512
- removed: d.removed.map((r) => ({
16513
- id: r.id,
16514
- value: mv(r.value)
16515
- })),
16516
- changed: d.changed.map((c) => ({
16517
- id: c.id,
16518
- recorded: mv(c.recorded),
16519
- actual: mv(c.actual)
16520
- }))
16521
- };
16522
- }
16523
-
16524
16569
  //#endregion
16525
16570
  //#region src/report/report.ts
16526
16571
  function stackNameFromHeader(header) {