cdk-real-drift 0.10.0 → 0.10.2
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 +8 -0
- package/dist/cli.js +136 -23
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -631,6 +631,14 @@ builds printed one pretty-printed `{...}` per stack back-to-back, which was neit
|
|
|
631
631
|
valid JSON value nor JSONL; multi-stack `--json` was unparseable — issue #755.) All
|
|
632
632
|
`note` / `warning` / progress lines go to **stderr**, so stdout stays pure JSON.
|
|
633
633
|
|
|
634
|
+
**Secret redaction.** Values on known secret-bearing properties — Lambda
|
|
635
|
+
`Environment.Variables`, CodeBuild `Environment.EnvironmentVariables[].Value`,
|
|
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 —
|
|
640
|
+
only the value is hidden (#798).
|
|
641
|
+
|
|
634
642
|
A **stack that errored or was skipped** before it could be checked still appears as an
|
|
635
643
|
element so a consumer sees which stacks ran: it carries `"error": "<reason>"` alongside
|
|
636
644
|
`"drifted": 0` and an empty `"findings": []`. (`error` is absent on a
|
package/dist/cli.js
CHANGED
|
@@ -3043,7 +3043,6 @@ const VALUE_INDEPENDENT_DEFAULT_TOPLEVEL_PATHS = {
|
|
|
3043
3043
|
"AWS::ElasticLoadBalancing::LoadBalancer": new Set(["AvailabilityZones"]),
|
|
3044
3044
|
"AWS::AutoScaling::AutoScalingGroup": new Set(["AvailabilityZones", "AvailabilityZoneIds"]),
|
|
3045
3045
|
"AWS::ApiGateway::Authorizer": new Set(["AuthType"]),
|
|
3046
|
-
"AWS::GuardDuty::Detector": new Set(["Features"]),
|
|
3047
3046
|
"AWS::RDS::DBCluster": new Set([
|
|
3048
3047
|
"KmsKeyId",
|
|
3049
3048
|
"PerformanceInsightsKmsKeyId",
|
|
@@ -4912,8 +4911,26 @@ const MEANINGFUL_WHEN_OFF = {
|
|
|
4912
4911
|
"AWS::EC2::NetworkInterface": { SourceDestCheck: () => true },
|
|
4913
4912
|
"AWS::Cognito::UserPoolClient": { EnableTokenRevocation: () => true },
|
|
4914
4913
|
"AWS::CloudWatch::CompositeAlarm": { ActionsEnabled: () => true },
|
|
4915
|
-
"AWS::ApplicationInsights::Application": { CWEMonitorEnabled: () => true }
|
|
4914
|
+
"AWS::ApplicationInsights::Application": { CWEMonitorEnabled: () => true },
|
|
4915
|
+
"AWS::GuardDuty::Detector": { DataSources: () => true }
|
|
4916
4916
|
};
|
|
4917
|
+
const GUARDDUTY_DEFAULT_DISABLED_FEATURES = new Set(["AI_ANALYST"]);
|
|
4918
|
+
function guardDutyFeaturesAllAtDefault(features) {
|
|
4919
|
+
const atDefault = (node) => {
|
|
4920
|
+
if (Array.isArray(node)) return node.every(atDefault);
|
|
4921
|
+
if (node !== null && typeof node === "object") {
|
|
4922
|
+
const rec = node;
|
|
4923
|
+
if ("Status" in rec) {
|
|
4924
|
+
const name = typeof rec["Name"] === "string" ? rec["Name"] : "";
|
|
4925
|
+
const defaultStatus = GUARDDUTY_DEFAULT_DISABLED_FEATURES.has(name) ? "DISABLED" : "ENABLED";
|
|
4926
|
+
if (rec["Status"] !== defaultStatus) return false;
|
|
4927
|
+
}
|
|
4928
|
+
return Object.values(rec).every(atDefault);
|
|
4929
|
+
}
|
|
4930
|
+
return true;
|
|
4931
|
+
};
|
|
4932
|
+
return features.every(atDefault);
|
|
4933
|
+
}
|
|
4917
4934
|
const stripCognitoAttrPrefix = (id) => id.replace(/^(custom|dev):/, "");
|
|
4918
4935
|
const IDENTITY_KEYED_SUBSET_ARRAYS = {
|
|
4919
4936
|
"AWS::Cognito::UserPool": { Schema: {
|
|
@@ -6092,6 +6109,16 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
|
|
|
6092
6109
|
}
|
|
6093
6110
|
continue;
|
|
6094
6111
|
}
|
|
6112
|
+
if (resourceType === "AWS::GuardDuty::Detector" && k === "Features" && Array.isArray(v)) {
|
|
6113
|
+
findings.push({
|
|
6114
|
+
tier: guardDutyFeaturesAllAtDefault(v) ? "atDefault" : "undeclared",
|
|
6115
|
+
logicalId,
|
|
6116
|
+
resourceType,
|
|
6117
|
+
path: k,
|
|
6118
|
+
actual: v
|
|
6119
|
+
});
|
|
6120
|
+
continue;
|
|
6121
|
+
}
|
|
6095
6122
|
if (k in schema.defaults && matchesKnownDefault(v, schema.defaults[k]) || k in knownDef && matchesKnownDefault(v, knownDef[k]) || KNOWN_DEFAULT_ONE_OF[resourceType]?.[k]?.some((d) => matchesKnownDefault(v, d)) || VALUE_INDEPENDENT_DEFAULT_TOPLEVEL_PATHS[resourceType]?.has(k) && !isTrivialEmpty(v) && !(k in knownDef) || clbDefaultSslPoliciesAtDefault(resourceType, k, v)) {
|
|
6096
6123
|
findings.push({
|
|
6097
6124
|
tier: "atDefault",
|
|
@@ -6235,10 +6262,11 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
|
|
|
6235
6262
|
}
|
|
6236
6263
|
if (isAllAwsTags(v)) continue;
|
|
6237
6264
|
if (physicalId !== void 0 && v === physicalId) continue;
|
|
6238
|
-
|
|
6265
|
+
const offStateIsMeaningful = k in knownDef && !matchesKnownDefault(v, knownDef[k]) && (MEANINGFUL_WHEN_OFF[resourceType]?.[k]?.({
|
|
6239
6266
|
declared,
|
|
6240
6267
|
live
|
|
6241
|
-
}) ?? false)
|
|
6268
|
+
}) ?? false);
|
|
6269
|
+
if (!offStateIsMeaningful && (isTrivialEmpty(v) || isSelfEchoTrivialEmpty(v, physicalId) || isEmptyPolicyShell(v))) continue;
|
|
6242
6270
|
if (isNestedObject(v) && DESCEND_UNDECLARED_OBJECT_PATHS[resourceType]?.has(k)) {
|
|
6243
6271
|
collectNestedUndeclared({}, v, k, emitNested, NESTED_ARRAY_IDENTITY[resourceType]);
|
|
6244
6272
|
continue;
|
|
@@ -6272,7 +6300,7 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
|
|
|
6272
6300
|
}
|
|
6273
6301
|
continue;
|
|
6274
6302
|
}
|
|
6275
|
-
if (isNestedObject(v) && Object.keys(v).length > 0 && allLeavesAtSchemaDefault(v, k)) {
|
|
6303
|
+
if (!offStateIsMeaningful && isNestedObject(v) && Object.keys(v).length > 0 && allLeavesAtSchemaDefault(v, k)) {
|
|
6276
6304
|
findings.push({
|
|
6277
6305
|
tier: "atDefault",
|
|
6278
6306
|
logicalId,
|
|
@@ -15837,6 +15865,87 @@ function annotateHints(findings) {
|
|
|
15837
15865
|
});
|
|
15838
15866
|
}
|
|
15839
15867
|
|
|
15868
|
+
//#endregion
|
|
15869
|
+
//#region src/report/redact.ts
|
|
15870
|
+
function maskPlaceholder(value) {
|
|
15871
|
+
if (typeof value === "string") return `<redacted:${value.length} chars>`;
|
|
15872
|
+
return "<redacted>";
|
|
15873
|
+
}
|
|
15874
|
+
const maskWhole = (value) => maskPlaceholder(value);
|
|
15875
|
+
const maskEntryValueField = (value) => {
|
|
15876
|
+
if (value && typeof value === "object" && !Array.isArray(value) && "Value" in value) return {
|
|
15877
|
+
...value,
|
|
15878
|
+
Value: maskPlaceholder(value.Value)
|
|
15879
|
+
};
|
|
15880
|
+
return maskPlaceholder(value);
|
|
15881
|
+
};
|
|
15882
|
+
const maskMapValues = (value) => {
|
|
15883
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
15884
|
+
const out = {};
|
|
15885
|
+
for (const [k, v] of Object.entries(value)) out[k] = maskPlaceholder(v);
|
|
15886
|
+
return out;
|
|
15887
|
+
}
|
|
15888
|
+
return maskPlaceholder(value);
|
|
15889
|
+
};
|
|
15890
|
+
const REDACTED_VALUE_PATHS = {
|
|
15891
|
+
"AWS::Lambda::Function": [{
|
|
15892
|
+
pathRe: /(^|\.)Environment\.Variables\./,
|
|
15893
|
+
redact: maskWhole
|
|
15894
|
+
}, {
|
|
15895
|
+
pathRe: /(^|\.)Environment\.Variables$/,
|
|
15896
|
+
redact: maskMapValues
|
|
15897
|
+
}],
|
|
15898
|
+
"AWS::CodeBuild::Project": [{
|
|
15899
|
+
pathRe: /(^|\.)Environment\.EnvironmentVariables\.\d+\.Value$/,
|
|
15900
|
+
redact: maskWhole
|
|
15901
|
+
}],
|
|
15902
|
+
"AWS::EC2::LaunchTemplate": [{
|
|
15903
|
+
pathRe: /(^|\.)LaunchTemplateData\.UserData$/,
|
|
15904
|
+
redact: maskWhole
|
|
15905
|
+
}],
|
|
15906
|
+
"AWS::ElasticBeanstalk::Environment": [{
|
|
15907
|
+
pathRe: /(^|\.)OptionSettings\[aws:elasticbeanstalk:application:environment\|/,
|
|
15908
|
+
redact: maskEntryValueField
|
|
15909
|
+
}]
|
|
15910
|
+
};
|
|
15911
|
+
function redactValue(resourceType, path, value) {
|
|
15912
|
+
const matchers = REDACTED_VALUE_PATHS[resourceType];
|
|
15913
|
+
if (!matchers) return value;
|
|
15914
|
+
for (const m of matchers) if (m.pathRe.test(path)) return m.redact(value);
|
|
15915
|
+
return value;
|
|
15916
|
+
}
|
|
15917
|
+
function isRedactedPath(resourceType, path) {
|
|
15918
|
+
const matchers = REDACTED_VALUE_PATHS[resourceType];
|
|
15919
|
+
return !!matchers && matchers.some((m) => m.pathRe.test(path));
|
|
15920
|
+
}
|
|
15921
|
+
function redactFinding(f) {
|
|
15922
|
+
if (!isRedactedPath(f.resourceType, f.path)) return f;
|
|
15923
|
+
const out = { ...f };
|
|
15924
|
+
if ("desired" in f && f.desired !== void 0) out.desired = redactValue(f.resourceType, f.path, f.desired);
|
|
15925
|
+
if ("actual" in f && f.actual !== void 0) out.actual = redactValue(f.resourceType, f.path, f.actual);
|
|
15926
|
+
if (f.arrayDelta && typeof f.arrayDelta === "object") out.arrayDelta = redactArrayDelta(f.resourceType, f.path, f.arrayDelta);
|
|
15927
|
+
return out;
|
|
15928
|
+
}
|
|
15929
|
+
function redactArrayDelta(resourceType, path, d) {
|
|
15930
|
+
const mv = (v) => redactValue(resourceType, path, v);
|
|
15931
|
+
return {
|
|
15932
|
+
identityField: d.identityField,
|
|
15933
|
+
added: d.added.map((a) => ({
|
|
15934
|
+
id: a.id,
|
|
15935
|
+
value: mv(a.value)
|
|
15936
|
+
})),
|
|
15937
|
+
removed: d.removed.map((r) => ({
|
|
15938
|
+
id: r.id,
|
|
15939
|
+
value: mv(r.value)
|
|
15940
|
+
})),
|
|
15941
|
+
changed: d.changed.map((c) => ({
|
|
15942
|
+
id: c.id,
|
|
15943
|
+
recorded: mv(c.recorded),
|
|
15944
|
+
actual: mv(c.actual)
|
|
15945
|
+
}))
|
|
15946
|
+
};
|
|
15947
|
+
}
|
|
15948
|
+
|
|
15840
15949
|
//#endregion
|
|
15841
15950
|
//#region src/report/report.ts
|
|
15842
15951
|
function stackNameFromHeader(header) {
|
|
@@ -15889,42 +15998,45 @@ function formatFinding(f, stackName = "") {
|
|
|
15889
15998
|
const pathDisplay = f.attributeKey ? `${f.path}[${sanitizeForTerminal(f.attributeKey)}]` : f.path;
|
|
15890
15999
|
let s = `${pathDisplay ? `${id}.${pathDisplay}` : id} (${f.resourceType})`;
|
|
15891
16000
|
if (f.note) s += ` — ${sanitizeForTerminal(f.note)}`;
|
|
15892
|
-
|
|
16001
|
+
const rt = f.resourceType;
|
|
16002
|
+
const rd = (v) => redactValue(rt, f.path, v);
|
|
16003
|
+
if (f.tier === "declared") if (isRecord(f.desired) && isRecord(f.actual)) s += formatMapDelta(f.desired, f.actual, false, rt, f.path);
|
|
15893
16004
|
else {
|
|
15894
|
-
const { a: d, b: act } = jPair(f.desired, f.actual);
|
|
16005
|
+
const { a: d, b: act } = jPair(rd(f.desired), rd(f.actual));
|
|
15895
16006
|
s += `\n desired=${style.desired(d)}\n actual =${style.actual(act)}`;
|
|
15896
16007
|
}
|
|
15897
|
-
else if (f.tier === "added" && f.desired !== void 0) if (isRecord(f.desired) && isRecord(f.actual)) s += formatMapDelta(f.desired, f.actual, true);
|
|
16008
|
+
else if (f.tier === "added" && f.desired !== void 0) if (isRecord(f.desired) && isRecord(f.actual)) s += formatMapDelta(f.desired, f.actual, true, rt, f.path);
|
|
15898
16009
|
else {
|
|
15899
|
-
const { a: base, b: act } = jPair(f.desired, f.actual);
|
|
16010
|
+
const { a: base, b: act } = jPair(rd(f.desired), rd(f.actual));
|
|
15900
16011
|
s += `\n baseline=${style.desired(base)}\n actual =${style.actual(act)}`;
|
|
15901
16012
|
}
|
|
15902
|
-
else if (f.tier === "added" && f.actual !== void 0) s += `\n actual =${style.actual(j(f.actual))}`;
|
|
15903
|
-
else if (f.tier === "undeclared" && f.arrayDelta) s += formatArrayDelta(f.arrayDelta);
|
|
15904
|
-
else if (f.tier === "undeclared" && f.desired !== void 0) if (isRecord(f.desired) && isRecord(f.actual)) s += formatMapDelta(f.desired, f.actual, true);
|
|
16013
|
+
else if (f.tier === "added" && f.actual !== void 0) s += `\n actual =${style.actual(j(rd(f.actual)))}`;
|
|
16014
|
+
else if (f.tier === "undeclared" && f.arrayDelta) s += formatArrayDelta(f.arrayDelta, rt, f.path);
|
|
16015
|
+
else if (f.tier === "undeclared" && f.desired !== void 0) if (isRecord(f.desired) && isRecord(f.actual)) s += formatMapDelta(f.desired, f.actual, true, rt, f.path);
|
|
15905
16016
|
else {
|
|
15906
|
-
const { a: base, b: act } = jPair(f.desired, f.actual);
|
|
16017
|
+
const { a: base, b: act } = jPair(rd(f.desired), rd(f.actual));
|
|
15907
16018
|
s += `\n baseline=${style.desired(base)}\n actual =${style.actual(act)}`;
|
|
15908
16019
|
}
|
|
15909
|
-
else if (f.tier === "undeclared" || f.tier === "atDefault" || f.tier === "generated") s += `\n actual =${style.actual(j(f.actual))}`;
|
|
16020
|
+
else if (f.tier === "undeclared" || f.tier === "atDefault" || f.tier === "generated") s += `\n actual =${style.actual(j(rd(f.actual)))}`;
|
|
15910
16021
|
if (f.hint) s += `\n ${style.note(`↳ ${sanitizeForTerminal(f.hint)}`)}`;
|
|
15911
16022
|
return s;
|
|
15912
16023
|
}
|
|
15913
16024
|
const isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
15914
|
-
function formatMapDelta(desired, actual, baselineLabels) {
|
|
16025
|
+
function formatMapDelta(desired, actual, baselineLabels, resourceType, basePath) {
|
|
15915
16026
|
const lhs = baselineLabels ? "baseline" : "desired";
|
|
15916
16027
|
const rhs = baselineLabels ? "actual " : "actual ";
|
|
15917
16028
|
const keys = [...new Set([...Object.keys(desired), ...Object.keys(actual)])].sort();
|
|
16029
|
+
const rd = (k, v) => resourceType !== void 0 && basePath !== void 0 ? redactValue(resourceType, `${basePath}.${k}`, v) : v;
|
|
15918
16030
|
let s = "";
|
|
15919
16031
|
for (const k of keys) {
|
|
15920
16032
|
const inD = Object.hasOwn(desired, k);
|
|
15921
16033
|
if (inD && Object.hasOwn(actual, k)) {
|
|
15922
16034
|
if (deepEqual(desired[k], actual[k])) continue;
|
|
15923
|
-
const { a, b } = jPair(desired[k], actual[k]);
|
|
16035
|
+
const { a, b } = jPair(rd(k, desired[k]), rd(k, actual[k]));
|
|
15924
16036
|
const sk = sanitizeForTerminal(k);
|
|
15925
16037
|
s += `\n ~ ${sk}\n ${lhs}=${style.desired(a)}\n ${rhs}=${style.actual(b)}`;
|
|
15926
|
-
} else if (inD) s += `\n - ${sanitizeForTerminal(k)} (in ${baselineLabels ? "baseline" : "template"}, absent in live)\n ${lhs}=${style.desired(j(desired[k]))}`;
|
|
15927
|
-
else s += `\n + ${sanitizeForTerminal(k)} (in live, not in ${baselineLabels ? "baseline" : "template"})\n ${rhs}=${style.actual(j(actual[k]))}`;
|
|
16038
|
+
} else if (inD) s += `\n - ${sanitizeForTerminal(k)} (in ${baselineLabels ? "baseline" : "template"}, absent in live)\n ${lhs}=${style.desired(j(rd(k, desired[k])))}`;
|
|
16039
|
+
else s += `\n + ${sanitizeForTerminal(k)} (in live, not in ${baselineLabels ? "baseline" : "template"})\n ${rhs}=${style.actual(j(rd(k, actual[k])))}`;
|
|
15928
16040
|
}
|
|
15929
16041
|
if (s === "") {
|
|
15930
16042
|
const { a, b } = jPair(desired, actual);
|
|
@@ -15932,13 +16044,14 @@ function formatMapDelta(desired, actual, baselineLabels) {
|
|
|
15932
16044
|
}
|
|
15933
16045
|
return s;
|
|
15934
16046
|
}
|
|
15935
|
-
function formatArrayDelta(d) {
|
|
15936
|
-
const
|
|
15937
|
-
const
|
|
16047
|
+
function formatArrayDelta(d, resourceType, path) {
|
|
16048
|
+
const rd = (v) => resourceType !== void 0 && path !== void 0 ? redactValue(resourceType, path, v) : v;
|
|
16049
|
+
const baseline = (v) => `\n baseline=${style.desired(j(rd(v)))}`;
|
|
16050
|
+
const actual = (v) => `\n actual =${style.actual(j(rd(v)))}`;
|
|
15938
16051
|
let s = ` — ${sanitizeForTerminal(d.identityField)}-keyed element(s) changed vs .cdkrd baseline:`;
|
|
15939
16052
|
for (const a of d.added) s += `\n + [${sanitizeForTerminal(a.id)}]${actual(a.value)}`;
|
|
15940
16053
|
for (const c of d.changed) {
|
|
15941
|
-
const { a: base, b: act } = jPair(c.recorded, c.actual);
|
|
16054
|
+
const { a: base, b: act } = jPair(rd(c.recorded), rd(c.actual));
|
|
15942
16055
|
s += `\n ~ [${sanitizeForTerminal(c.id)}]\n baseline=${style.desired(base)}\n actual =${style.actual(act)}`;
|
|
15943
16056
|
}
|
|
15944
16057
|
for (const r of d.removed) s += `\n - [${sanitizeForTerminal(r.id)}]${baseline(r.value)}`;
|
|
@@ -15983,7 +16096,7 @@ function buildStackJson(rawFindings, header, hasBaseline) {
|
|
|
15983
16096
|
json: {
|
|
15984
16097
|
stack: header,
|
|
15985
16098
|
drifted,
|
|
15986
|
-
findings,
|
|
16099
|
+
findings: findings.map((f) => redactFinding(f)),
|
|
15987
16100
|
baseline: hasBaseline === true
|
|
15988
16101
|
},
|
|
15989
16102
|
code: drifted === 0 ? 0 : 1
|