cdk-real-drift 0.12.19 → 0.12.21
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 +9 -0
- package/dist/cli.js +96 -10
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -896,6 +896,15 @@ covers them. **If you never run `revert`, cdkrd needs no write permissions at al
|
|
|
896
896
|
"changed since record". The old code bytes are gone, so it is detect-only (not
|
|
897
897
|
revertable — redeploy with a forced code update). Without the permission the
|
|
898
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.
|
|
899
908
|
- Optional: `kms:ListAliases` enables strict verification that a declared
|
|
900
909
|
`alias/aws/*` key was not swapped for a customer-managed key. Without it that case
|
|
901
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,
|
|
@@ -11892,17 +11920,42 @@ const maskMapValues = (value) => {
|
|
|
11892
11920
|
}
|
|
11893
11921
|
return maskPlaceholder(value);
|
|
11894
11922
|
};
|
|
11923
|
+
const maskEnvironmentContainer = (value) => {
|
|
11924
|
+
if (value && typeof value === "object" && !Array.isArray(value) && "Variables" in value) return {
|
|
11925
|
+
...value,
|
|
11926
|
+
Variables: maskMapValues(value.Variables)
|
|
11927
|
+
};
|
|
11928
|
+
return value;
|
|
11929
|
+
};
|
|
11930
|
+
const maskEnvVarArrayElement = (element) => {
|
|
11931
|
+
if (element && typeof element === "object" && !Array.isArray(element) && "Value" in element) return {
|
|
11932
|
+
...element,
|
|
11933
|
+
Value: maskPlaceholder(element.Value)
|
|
11934
|
+
};
|
|
11935
|
+
return element;
|
|
11936
|
+
};
|
|
11937
|
+
const maskEnvVarArray = (value) => Array.isArray(value) ? value.map(maskEnvVarArrayElement) : maskEnvVarArrayElement(value);
|
|
11895
11938
|
const REDACTED_VALUE_PATHS = {
|
|
11896
|
-
"AWS::Lambda::Function": [
|
|
11897
|
-
|
|
11898
|
-
|
|
11899
|
-
|
|
11900
|
-
|
|
11901
|
-
|
|
11902
|
-
|
|
11939
|
+
"AWS::Lambda::Function": [
|
|
11940
|
+
{
|
|
11941
|
+
pathRe: /(^|\.)Environment\.Variables\./,
|
|
11942
|
+
redact: maskWhole
|
|
11943
|
+
},
|
|
11944
|
+
{
|
|
11945
|
+
pathRe: /(^|\.)Environment\.Variables$/,
|
|
11946
|
+
redact: maskMapValues
|
|
11947
|
+
},
|
|
11948
|
+
{
|
|
11949
|
+
pathRe: /(^|\.)Environment$/,
|
|
11950
|
+
redact: maskEnvironmentContainer
|
|
11951
|
+
}
|
|
11952
|
+
],
|
|
11903
11953
|
"AWS::CodeBuild::Project": [{
|
|
11904
11954
|
pathRe: /(^|\.)Environment\.EnvironmentVariables\.\d+\.Value$/,
|
|
11905
11955
|
redact: maskWhole
|
|
11956
|
+
}, {
|
|
11957
|
+
pathRe: /(^|\.)Environment\.EnvironmentVariables$/,
|
|
11958
|
+
redact: maskEnvVarArray
|
|
11906
11959
|
}],
|
|
11907
11960
|
"AWS::EC2::LaunchTemplate": [{
|
|
11908
11961
|
pathRe: /(^|\.)LaunchTemplateData\.UserData$/,
|
|
@@ -12271,7 +12324,10 @@ function checkBaselineAccount(baseline, currentAccountId, stackName, warn = cons
|
|
|
12271
12324
|
}
|
|
12272
12325
|
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.`);
|
|
12273
12326
|
}
|
|
12274
|
-
const RECORDABLE_GENERATED_PATHS = {
|
|
12327
|
+
const RECORDABLE_GENERATED_PATHS = {
|
|
12328
|
+
"AWS::Lambda::Function": new Set(["CodeSha256"]),
|
|
12329
|
+
"AWS::Glue::Job": new Set(["ScriptSha256"])
|
|
12330
|
+
};
|
|
12275
12331
|
function isRecordableGenerated(f) {
|
|
12276
12332
|
return f.tier === "generated" && (RECORDABLE_GENERATED_PATHS[f.resourceType]?.has(f.path) ?? false);
|
|
12277
12333
|
}
|
|
@@ -12561,6 +12617,18 @@ function addedChildParentLogicalId(logicalId) {
|
|
|
12561
12617
|
const slash = logicalId.indexOf("/");
|
|
12562
12618
|
return slash < 0 ? void 0 : logicalId.slice(0, slash);
|
|
12563
12619
|
}
|
|
12620
|
+
function addedChildIdentifier(logicalId) {
|
|
12621
|
+
const slash = logicalId.indexOf("/");
|
|
12622
|
+
return slash < 0 ? void 0 : logicalId.slice(slash + 1);
|
|
12623
|
+
}
|
|
12624
|
+
function addedChildWasAdopted(childLogicalId, physicalIdByLogical) {
|
|
12625
|
+
if (physicalIdByLogical === void 0 || physicalIdByLogical.size === 0) return false;
|
|
12626
|
+
const identifier = addedChildIdentifier(childLogicalId);
|
|
12627
|
+
if (identifier === void 0) return false;
|
|
12628
|
+
const trailing = identifier.slice(identifier.lastIndexOf("|") + 1);
|
|
12629
|
+
for (const livePhysicalId of physicalIdByLogical.values()) if (livePhysicalId === identifier || livePhysicalId === trailing) return true;
|
|
12630
|
+
return false;
|
|
12631
|
+
}
|
|
12564
12632
|
function descendDeclared(node, seg) {
|
|
12565
12633
|
if (node === null || typeof node !== "object") return void 0;
|
|
12566
12634
|
if (Array.isArray(node)) {
|
|
@@ -12693,11 +12761,16 @@ function applyBaseline(findings, baseline, opts = {}) {
|
|
|
12693
12761
|
const removedFromTemplate = [];
|
|
12694
12762
|
const replacedStale = [];
|
|
12695
12763
|
const typeMismatchStale = [];
|
|
12764
|
+
const adoptedStale = [];
|
|
12696
12765
|
for (const a of recorded) {
|
|
12697
12766
|
if (a.path === "") {
|
|
12698
12767
|
if (presentAddedLogical.has(a.logicalId)) continue;
|
|
12699
12768
|
const parent = addedChildParentLogicalId(a.logicalId);
|
|
12700
12769
|
if (!(parent !== void 0 && readParentLogical.has(parent))) continue;
|
|
12770
|
+
if (addedChildWasAdopted(a.logicalId, opts.physicalIdByLogical)) {
|
|
12771
|
+
adoptedStale.push(a.logicalId);
|
|
12772
|
+
continue;
|
|
12773
|
+
}
|
|
12701
12774
|
kept.push({
|
|
12702
12775
|
tier: "deleted",
|
|
12703
12776
|
logicalId: a.logicalId,
|
|
@@ -12744,6 +12817,7 @@ function applyBaseline(findings, baseline, opts = {}) {
|
|
|
12744
12817
|
if (removedFromTemplate.length > 0) opts.warn?.(formatRemovedFromTemplateNote(removedFromTemplate));
|
|
12745
12818
|
if (replacedStale.length > 0) opts.warn?.(formatReplacedStaleNote(replacedStale));
|
|
12746
12819
|
if (typeMismatchStale.length > 0) opts.warn?.(formatTypeMismatchStaleNote(typeMismatchStale));
|
|
12820
|
+
if (adoptedStale.length > 0) opts.warn?.(formatAdoptedStaleNote(adoptedStale));
|
|
12747
12821
|
return kept;
|
|
12748
12822
|
}
|
|
12749
12823
|
/**
|
|
@@ -12784,6 +12858,17 @@ function formatTypeMismatchStaleNote(paths) {
|
|
|
12784
12858
|
return `note: ${n === 1 ? `baseline entry (${paths[0]}) was` : `${n} baseline entries were`} recorded against a resource whose logicalId now has a DIFFERENT type — re-run \`cdkrd record\`.`;
|
|
12785
12859
|
}
|
|
12786
12860
|
/**
|
|
12861
|
+
* #1279: the folded one-line note for recorded out-of-band `added` resources that have since
|
|
12862
|
+
* been ADOPTED into the template (`cdk import`, or re-declared + deployed) — the child is no
|
|
12863
|
+
* longer enumerated as `added`, but its identifier matches a template resource's live physical
|
|
12864
|
+
* id, so it is alive and now IaC-managed, not deleted. Mirror of formatReplacedStaleNote. Pure
|
|
12865
|
+
* + exported for unit tests.
|
|
12866
|
+
*/
|
|
12867
|
+
function formatAdoptedStaleNote(logicalIds) {
|
|
12868
|
+
const n = logicalIds.length;
|
|
12869
|
+
return `note: ${n === 1 ? `recorded added resource (${logicalIds[0]}) was` : `${n} recorded added resources were`} adopted into the template (now IaC-managed) — re-run \`cdkrd record\` to clean up the baseline.`;
|
|
12870
|
+
}
|
|
12871
|
+
/**
|
|
12787
12872
|
* logicalId -> the resource's declared model, for applyBaseline's promotion check.
|
|
12788
12873
|
* #1079: carries the WHOLE declared object (not just its top-level key set) so a NESTED
|
|
12789
12874
|
* recorded path the user later declares is RESOLVED against the declared tree and folded
|
|
@@ -14744,7 +14829,8 @@ function resolveSdkWriter(resourceType, ops) {
|
|
|
14744
14829
|
const WRITEONLY_NESTED_NO_CC_REVERT = {};
|
|
14745
14830
|
const SYNTHETIC_READ_SIGNAL_PATHS = {
|
|
14746
14831
|
"AWS::ElasticLoadBalancingV2::TrustStore": ["CaCertificatesBundleSha256"],
|
|
14747
|
-
"AWS::Lambda::Function": ["CodeSha256"]
|
|
14832
|
+
"AWS::Lambda::Function": ["CodeSha256"],
|
|
14833
|
+
"AWS::Glue::Job": ["ScriptSha256"]
|
|
14748
14834
|
};
|
|
14749
14835
|
const CC_REVERTABLE_DESPITE_READ_OVERRIDE = new Set(["AWS::Scheduler::Schedule", "AWS::Cognito::IdentityPool"]);
|
|
14750
14836
|
const REVERT_SET_DEFAULT_PATHS = new Set([
|