cdk-real-drift 0.12.18 → 0.12.20

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
@@ -634,9 +634,19 @@ valid JSON value nor JSONL; multi-stack `--json` was unparseable — issue #755.
634
634
  **Secret redaction.** Values on known secret-bearing properties — Lambda
635
635
  `Environment.Variables`, CodeBuild `Environment.EnvironmentVariables[].Value`,
636
636
  Elastic Beanstalk env-namespace `OptionSettings`, EC2 LaunchTemplate `UserData` —
637
- are masked as `<redacted:NN chars>` in both text and `--json` output, so a rotated
638
- secret surfacing as drift does not leak its plaintext into CI logs. The finding
639
- still surfaces (detection is preserved) and the property/key name stays visible —
637
+ are masked as `<redacted:NN chars:HHHHHHHH>` in both text and `--json` output, so a rotated
638
+ secret surfacing as drift does not leak its plaintext into CI logs. The `NN` is the
639
+ value's char length and `HHHHHHHH` is the first 8 hex of its sha256 — a **deterministic,
640
+ stable distinguisher** (#1308): the same secret masks to the same placeholder across runs,
641
+ so a consumer diffing two consecutive `--json` runs compares them correctly, while a
642
+ **rotated same-length** secret now masks to a **different** placeholder instead of a
643
+ byte-identical one (the length-only mask erased that change). The hash is non-reversible for
644
+ a high-entropy value; a low-entropy value's short hash is brute-forceable, so it is a
645
+ change-distinguisher, not a confidentiality guarantee — but the plaintext itself is never
646
+ printed. In `--json` a masked finding additionally carries a `"redacted": true` sibling, an
647
+ **out-of-band marker** so a consumer can tell a masked value from a literal live string that
648
+ happens to look like the placeholder (a non-secret finding has no `redacted` field). The
649
+ finding still surfaces (detection is preserved) and the property/key name stays visible —
640
650
  only the value is hidden. The same protection covers persistence: `record` writes a
641
651
  **hash** of these values into the git-committed baseline instead of the plaintext, so
642
652
  the secret never lands in a committed file while a later change still re-surfaces as
@@ -886,6 +896,15 @@ covers them. **If you never run `revert`, cdkrd needs no write permissions at al
886
896
  "changed since record". The old code bytes are gone, so it is detect-only (not
887
897
  revertable — redeploy with a forced code update). Without the permission the
888
898
  signal is skipped, never false-flagged.
899
+ - Optional: `glue:GetJob` + `s3:GetObject` (on the script bucket) record a content
900
+ hash of an `AWS::Glue::Job`'s ETL script (`ScriptSha256`, fetched from
901
+ `Command.ScriptLocation`) so an out-of-band script swap at the **same S3 key**
902
+ (`aws s3 cp new.py s3://bucket/key`) re-surfaces as drift — otherwise invisible
903
+ (`GetJob` returns only the S3 path, never the bytes, and a later `cdk deploy` does
904
+ not heal it). Same behavior as the Lambda code digest: folds silently on a clean
905
+ deploy, `record` snapshots it, a swap re-surfaces as "changed since record",
906
+ detect-only (re-upload the intended script). Without the permission (or on any S3
907
+ read failure / a non-`s3://` location) the signal is skipped, never false-flagged.
889
908
  - Optional: `kms:ListAliases` enables strict verification that a declared
890
909
  `alias/aws/*` key was not swapped for a customer-managed key. Without it that case
891
910
  is conservatively suppressed AND cdkrd prints a one-line warning per region (the
package/dist/cli.js CHANGED
@@ -36,7 +36,7 @@ import { DescribeDBClustersCommand as DescribeDBClustersCommand$1, DescribeDBIns
36
36
  import { DAXClient, DescribeClustersCommand, DescribeParameterGroupsCommand, DescribeParametersCommand as DescribeParametersCommand$1, DescribeSubnetGroupsCommand, UpdateClusterCommand, UpdateParameterGroupCommand } from "@aws-sdk/client-dax";
37
37
  import { GetClassifierCommand, GetConnectionCommand, GetJobCommand, GetSecurityConfigurationCommand, GetTableCommand, GetWorkflowCommand, GlueClient, UpdateClassifierCommand, UpdateConnectionCommand, UpdateJobCommand, UpdateTableCommand, UpdateWorkflowCommand } from "@aws-sdk/client-glue";
38
38
  import { AttachGroupPolicyCommand, AttachRolePolicyCommand, AttachUserPolicyCommand, CreatePolicyVersionCommand, DeletePolicyVersionCommand, DeleteRolePolicyCommand, DetachGroupPolicyCommand, DetachRolePolicyCommand, DetachUserPolicyCommand, GetGroupPolicyCommand, GetPolicyCommand as GetPolicyCommand$1, GetPolicyVersionCommand, GetRolePolicyCommand, GetUserPolicyCommand, IAMClient, ListAccessKeysCommand, ListEntitiesForPolicyCommand, ListPolicyVersionsCommand, PutGroupPolicyCommand, PutRolePolicyCommand, PutUserPolicyCommand } from "@aws-sdk/client-iam";
39
- import { DeleteBucketPolicyCommand, GetBucketPolicyCommand, PutBucketPolicyCommand, S3Client } from "@aws-sdk/client-s3";
39
+ import { DeleteBucketPolicyCommand, GetBucketPolicyCommand, GetObjectCommand, PutBucketPolicyCommand, S3Client } from "@aws-sdk/client-s3";
40
40
  import { DescribeCacheClustersCommand, DescribeCacheParameterGroupsCommand, DescribeCacheParametersCommand, DescribeReplicationGroupsCommand, DescribeUsersCommand, ElastiCacheClient, ModifyCacheParameterGroupCommand, ResetCacheParameterGroupCommand } from "@aws-sdk/client-elasticache";
41
41
  import { DescribeParameterGroupsCommand as DescribeParameterGroupsCommand$1, DescribeParametersCommand as DescribeParametersCommand$2, DescribeUsersCommand as DescribeUsersCommand$1, MemoryDBClient, ResetParameterGroupCommand, UpdateParameterGroupCommand as UpdateParameterGroupCommand$1 } from "@aws-sdk/client-memorydb";
42
42
  import { CloudWatchClient, DescribeAnomalyDetectorsCommand, PutAnomalyDetectorCommand } from "@aws-sdk/client-cloudwatch";
@@ -2908,6 +2908,7 @@ const GENERATED_TOPLEVEL_PATHS = {
2908
2908
  ]),
2909
2909
  "AWS::Lambda::Version": new Set(["CodeSha256"]),
2910
2910
  "AWS::Lambda::Function": new Set(["CodeSha256"]),
2911
+ "AWS::Glue::Job": new Set(["ScriptSha256"]),
2911
2912
  "AWS::EFS::AccessPoint": new Set(["ClientToken"])
2912
2913
  };
2913
2914
  const DESCEND_UNDECLARED_OBJECT_PATHS = {
@@ -8753,6 +8754,10 @@ function hashCaBundle(pem) {
8753
8754
  bodies.sort();
8754
8755
  return createHash("sha256").update(bodies.join("\n")).digest("hex");
8755
8756
  }
8757
+ function sha256Hex(bytes) {
8758
+ if (bytes === void 0 || bytes.length === 0) return void 0;
8759
+ return createHash("sha256").update(bytes).digest("hex");
8760
+ }
8756
8761
 
8757
8762
  //#endregion
8758
8763
  //#region src/read/overrides.ts
@@ -10441,6 +10446,28 @@ const supplementLambdaFunction = async ({ physicalId, region }) => {
10441
10446
  }).send(new GetFunctionCommand({ FunctionName: name }))).Configuration?.CodeSha256);
10442
10447
  return sha !== void 0 ? { CodeSha256: sha } : void 0;
10443
10448
  };
10449
+ const supplementGlueJob = async ({ physicalId, region }) => {
10450
+ const name = str$1(physicalId);
10451
+ if (!name) return void 0;
10452
+ const loc = str$1((await new GlueClient({
10453
+ region,
10454
+ ...READ_RETRY
10455
+ }).send(new GetJobCommand({ JobName: name }))).Job?.Command?.ScriptLocation);
10456
+ const m = loc !== void 0 ? /^s3:\/\/([^/]+)\/(.+)$/.exec(loc) : null;
10457
+ if (m === null) return void 0;
10458
+ try {
10459
+ const hash = sha256Hex(await (await new S3Client({
10460
+ region,
10461
+ ...READ_RETRY
10462
+ }).send(new GetObjectCommand({
10463
+ Bucket: m[1],
10464
+ Key: m[2]
10465
+ }))).Body?.transformToByteArray());
10466
+ return hash !== void 0 ? { ScriptSha256: hash } : void 0;
10467
+ } catch {
10468
+ return;
10469
+ }
10470
+ };
10444
10471
  function projectLexPrompt(p) {
10445
10472
  const ps = p;
10446
10473
  if (!ps || typeof ps !== "object") return void 0;
@@ -10668,6 +10695,7 @@ const SDK_SUPPLEMENTS = {
10668
10695
  "AWS::MSK::Configuration": supplementMskConfiguration,
10669
10696
  "AWS::ElasticLoadBalancingV2::TrustStore": supplementTrustStore,
10670
10697
  "AWS::Lambda::Function": supplementLambdaFunction,
10698
+ "AWS::Glue::Job": supplementGlueJob,
10671
10699
  "AWS::SSM::Parameter": supplementSsmParameter,
10672
10700
  "AWS::ElastiCache::ReplicationGroup": supplementElastiCacheReplicationGroup,
10673
10701
  "AWS::ECS::Service": supplementEcsService,
@@ -11870,7 +11898,10 @@ function stackCountAnnouncement(stackNames) {
11870
11898
  //#endregion
11871
11899
  //#region src/report/redact.ts
11872
11900
  function maskPlaceholder(value) {
11873
- if (typeof value === "string") return `<redacted:${value.length} chars>`;
11901
+ if (typeof value === "string") {
11902
+ const sig = createHash("sha256").update(value).digest("hex").slice(0, 8);
11903
+ return `<redacted:${value.length} chars:${sig}>`;
11904
+ }
11874
11905
  return "<redacted>";
11875
11906
  }
11876
11907
  const maskWhole = (value) => maskPlaceholder(value);
@@ -11923,7 +11954,10 @@ function isRedactedPath(resourceType, path) {
11923
11954
  }
11924
11955
  function redactFinding(f) {
11925
11956
  if (!isRedactedPath(f.resourceType, f.path)) return f;
11926
- const out = { ...f };
11957
+ const out = {
11958
+ ...f,
11959
+ redacted: true
11960
+ };
11927
11961
  if ("desired" in f && f.desired !== void 0) out.desired = redactValue(f.resourceType, f.path, f.desired);
11928
11962
  if ("actual" in f && f.actual !== void 0) out.actual = redactValue(f.resourceType, f.path, f.actual);
11929
11963
  if (f.arrayDelta && typeof f.arrayDelta === "object") out.arrayDelta = redactArrayDelta(f.resourceType, f.path, f.arrayDelta);
@@ -12265,7 +12299,10 @@ function checkBaselineAccount(baseline, currentAccountId, stackName, warn = cons
12265
12299
  }
12266
12300
  if (currentAccountId && baseline.accountId !== currentAccountId) throw new Error(`baseline file for ${stackName} was captured in account ${baseline.accountId}, but the current account is ${currentAccountId} (the file was likely copied or renamed to the wrong account path). Baselines are per-account — run \`cdkrd record\` to write this account's own baseline file, or restore the correct file from git.`);
12267
12301
  }
12268
- const RECORDABLE_GENERATED_PATHS = { "AWS::Lambda::Function": new Set(["CodeSha256"]) };
12302
+ const RECORDABLE_GENERATED_PATHS = {
12303
+ "AWS::Lambda::Function": new Set(["CodeSha256"]),
12304
+ "AWS::Glue::Job": new Set(["ScriptSha256"])
12305
+ };
12269
12306
  function isRecordableGenerated(f) {
12270
12307
  return f.tier === "generated" && (RECORDABLE_GENERATED_PATHS[f.resourceType]?.has(f.path) ?? false);
12271
12308
  }
@@ -14738,7 +14775,8 @@ function resolveSdkWriter(resourceType, ops) {
14738
14775
  const WRITEONLY_NESTED_NO_CC_REVERT = {};
14739
14776
  const SYNTHETIC_READ_SIGNAL_PATHS = {
14740
14777
  "AWS::ElasticLoadBalancingV2::TrustStore": ["CaCertificatesBundleSha256"],
14741
- "AWS::Lambda::Function": ["CodeSha256"]
14778
+ "AWS::Lambda::Function": ["CodeSha256"],
14779
+ "AWS::Glue::Job": ["ScriptSha256"]
14742
14780
  };
14743
14781
  const CC_REVERTABLE_DESPITE_READ_OVERRIDE = new Set(["AWS::Scheduler::Schedule", "AWS::Cognito::IdentityPool"]);
14744
14782
  const REVERT_SET_DEFAULT_PATHS = new Set([