cdk-real-drift 0.3.9 → 0.3.10
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/dist/cli.js +45 -15
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -744,12 +744,23 @@ function parseIgnoreRule(entry) {
|
|
|
744
744
|
* structured property covers its leaves, including array / identity-keyed elements), and a
|
|
745
745
|
* rule "MyApi/Res" covers its whole construct-path subtree "MyApi/Res/Method.Prop".
|
|
746
746
|
* Parent matching walks ancestors at each `.`, `[`, OR `/` boundary, combined with the glob.
|
|
747
|
+
*
|
|
748
|
+
* `wholeResource` marks an atomic, whole-resource target (an `added` finding — empty property
|
|
749
|
+
* path, so the target is just `<parentLogicalId>/<CC-identifier>`). Such a target has NO
|
|
750
|
+
* property subtree: the `.` / `[` inside it are DATA within the CC identifier
|
|
751
|
+
* (`example.com`, an ARN, `a[0]`), never property separators. Trimming there would walk into
|
|
752
|
+
* a DIFFERENT sibling resource whose identifier is this one extended by `.` / `[`
|
|
753
|
+
* (`MyApi/a` wrongly swallowing `MyApi/a.b`, `MyApi/a[0]`) — a silent over-suppression of the
|
|
754
|
+
* `added` out-of-band feature (issue #990). So in this mode the ancestor walk trims ONLY at
|
|
755
|
+
* `/` boundaries, which alone mark a resource boundary: a bare PARENT-resource rule (`MyLb`)
|
|
756
|
+
* still covers its added children across `/` (e.g. a listener child whose id is an ARN full
|
|
757
|
+
* of `/`, issue #903), while a rule for one whole resource can no longer reach a sibling.
|
|
747
758
|
*/
|
|
748
|
-
function pathMatches(pattern, target) {
|
|
759
|
+
function pathMatches(pattern, target, wholeResource = false) {
|
|
749
760
|
if (matchesPathGlob(pattern, target)) return true;
|
|
750
761
|
let t = target;
|
|
751
762
|
while (true) {
|
|
752
|
-
const cut = Math.max(t.lastIndexOf("."), t.lastIndexOf("["), t.lastIndexOf("/"));
|
|
763
|
+
const cut = wholeResource ? t.lastIndexOf("/") : Math.max(t.lastIndexOf("."), t.lastIndexOf("["), t.lastIndexOf("/"));
|
|
753
764
|
if (cut <= 0) break;
|
|
754
765
|
t = t.slice(0, cut);
|
|
755
766
|
if (matchesPathGlob(pattern, t)) return true;
|
|
@@ -763,12 +774,13 @@ function applyIgnores(findings, scope, config) {
|
|
|
763
774
|
return findings.map((f) => {
|
|
764
775
|
if (f.tier !== "declared" && f.tier !== "undeclared" && f.tier !== "added") return f;
|
|
765
776
|
const suffix = f.path ? `.${f.path}` : "";
|
|
777
|
+
const wholeResource = f.tier === "added";
|
|
766
778
|
const targets = [`${f.logicalId}${suffix}`];
|
|
767
779
|
if (f.constructPath) {
|
|
768
780
|
targets.push(`${withinStackPath(f.constructPath, stackName)}${suffix}`);
|
|
769
781
|
targets.push(`${f.constructPath}${suffix}`);
|
|
770
782
|
}
|
|
771
|
-
const hit = rules.find((r) => (r.stackGlob === void 0 || matchesGlob(r.stackGlob, stackName)) && (r.accountGlob === void 0 || matchesGlob(r.accountGlob, accountId)) && (r.regionGlob === void 0 || matchesGlob(r.regionGlob, region)) && targets.some((t) => pathMatches(r.pathPattern, t)));
|
|
783
|
+
const hit = rules.find((r) => (r.stackGlob === void 0 || matchesGlob(r.stackGlob, stackName)) && (r.accountGlob === void 0 || matchesGlob(r.accountGlob, accountId)) && (r.regionGlob === void 0 || matchesGlob(r.regionGlob, region)) && targets.some((t) => pathMatches(r.pathPattern, t, wholeResource)));
|
|
772
784
|
if (!hit) return f;
|
|
773
785
|
const { unrecorded: _unrecorded, ...rest } = f;
|
|
774
786
|
return {
|
|
@@ -2640,7 +2652,7 @@ const VALUE_INDEPENDENT_DEFAULT_TOPLEVEL_PATHS = {
|
|
|
2640
2652
|
"AWS::EKS::AccessEntry": new Set(["Username"]),
|
|
2641
2653
|
"AWS::Glue::Job": new Set(["MaxCapacity", "AllocatedCapacity"]),
|
|
2642
2654
|
"AWS::EC2::SecurityGroupIngress": new Set(["SourceSecurityGroupName"]),
|
|
2643
|
-
"AWS::EC2::SecurityGroupEgress": new Set(["
|
|
2655
|
+
"AWS::EC2::SecurityGroupEgress": new Set(["DestinationSecurityGroupName"]),
|
|
2644
2656
|
"AWS::DocDB::DBCluster": new Set(["PreferredMaintenanceWindow", "PreferredBackupWindow"]),
|
|
2645
2657
|
"AWS::DocDB::DBInstance": new Set(["PreferredMaintenanceWindow"]),
|
|
2646
2658
|
"AWS::Neptune::DBCluster": new Set(["PreferredMaintenanceWindow", "PreferredBackupWindow"]),
|
|
@@ -4385,8 +4397,13 @@ function stripInjectedJsonStringDefaults(declared, live, defaults) {
|
|
|
4385
4397
|
return stripObject(declared, live);
|
|
4386
4398
|
}
|
|
4387
4399
|
function isCfnGeneratedName(value, constructPath, physicalId, logicalId) {
|
|
4388
|
-
if (typeof value !== "string" ||
|
|
4400
|
+
if (typeof value !== "string" || value === physicalId) return false;
|
|
4389
4401
|
if (logicalId && value === logicalId) return true;
|
|
4402
|
+
if (logicalId && CFN_RANDOM_SUFFIX.test(value)) {
|
|
4403
|
+
const base = value.replace(CFN_RANDOM_SUFFIX, "");
|
|
4404
|
+
if (base.length > logicalId.length && base.endsWith(`-${logicalId}`)) return true;
|
|
4405
|
+
}
|
|
4406
|
+
if (!constructPath) return false;
|
|
4390
4407
|
const stackName = constructPath.split("/")[0];
|
|
4391
4408
|
if (!stackName || !CFN_RANDOM_SUFFIX.test(value)) return false;
|
|
4392
4409
|
if (value.startsWith(`${stackName}-`)) return true;
|
|
@@ -14094,17 +14111,26 @@ function finalCheckExit(code, fail) {
|
|
|
14094
14111
|
return fail || code !== 1 ? code : 0;
|
|
14095
14112
|
}
|
|
14096
14113
|
/**
|
|
14097
|
-
* #781: does a committed baseline exist for this stack
|
|
14098
|
-
* When a stack is gone (a DescribeStacks "does not exist"), we do NOT know the
|
|
14099
|
-
* account/region it was deployed to, so we cannot construct the exact baseline path.
|
|
14114
|
+
* #781: does a committed baseline exist for this stack IN THE REGION being checked?
|
|
14100
14115
|
* A committed baseline is named `<stackName>.<accountId>.<region>.json` under
|
|
14101
|
-
* `.cdkrd/baselines
|
|
14102
|
-
*
|
|
14103
|
-
*
|
|
14104
|
-
*
|
|
14116
|
+
* `.cdkrd/baselines/`. The gone stack's ACCOUNT is unknown without an STS call, so it
|
|
14117
|
+
* stays wildcarded; but the REGION being checked IS known (the loop's `region`), and a
|
|
14118
|
+
* baseline recorded for THIS stack in THIS region carries exactly that region in its
|
|
14119
|
+
* filename — so we require the `.<region>.json` suffix. A prior baseline in this region
|
|
14120
|
+
* is PROOF the stack was once deployed THERE, which distinguishes "deleted out of band"
|
|
14121
|
+
* (real drift) from "never deployed yet" (a benign skip). Without the region gate, a
|
|
14122
|
+
* same-named stack that was never deployed in region B but has a baseline in region A is
|
|
14123
|
+
* falsely reported "deleted out of band" (#942).
|
|
14124
|
+
*
|
|
14125
|
+
* #986: the match is CASE-INSENSITIVE (both sides lowercased) so it answers consistently
|
|
14126
|
+
* with `loadBaseline`, whose `readFile` opens the file case-insensitively on macOS/Windows.
|
|
14127
|
+
* A case-sensitive `readdirSync` prefix would MISS a baseline committed as `mystack.….json`
|
|
14128
|
+
* when checking `MyStack`, silently downgrading a genuinely deleted stack to a benign skip.
|
|
14129
|
+
*
|
|
14130
|
+
* The baselines directory is derived from `baselinePath` so the layout stays single-sourced.
|
|
14105
14131
|
* Pure (filesystem-only, no AWS) + exported for unit tests. Missing dir → false.
|
|
14106
14132
|
*/
|
|
14107
|
-
function hasBaselineForStack(stackName) {
|
|
14133
|
+
function hasBaselineForStack(stackName, region) {
|
|
14108
14134
|
const dir = dirname(baselinePath(stackName, "a", "r"));
|
|
14109
14135
|
let entries;
|
|
14110
14136
|
try {
|
|
@@ -14113,7 +14139,11 @@ function hasBaselineForStack(stackName) {
|
|
|
14113
14139
|
return false;
|
|
14114
14140
|
}
|
|
14115
14141
|
const prefix = `${stackName}.`.toLowerCase();
|
|
14116
|
-
|
|
14142
|
+
const suffix = `.${region}.json`.toLowerCase();
|
|
14143
|
+
return entries.some((f) => {
|
|
14144
|
+
const lower = f.toLowerCase();
|
|
14145
|
+
return lower.startsWith(prefix) && lower.endsWith(suffix);
|
|
14146
|
+
});
|
|
14117
14147
|
}
|
|
14118
14148
|
async function runCheck(args) {
|
|
14119
14149
|
const a = parseCommonArgs(args, "check");
|
|
@@ -14294,7 +14324,7 @@ async function runCheck(args) {
|
|
|
14294
14324
|
worst = Math.max(worst, strictCoverageExit(a.strict, gathered.findings, desired.resources));
|
|
14295
14325
|
} catch (e) {
|
|
14296
14326
|
if (isStackNotDeployed(e)) {
|
|
14297
|
-
if (hasBaselineForStack(stackName)) {
|
|
14327
|
+
if (hasBaselineForStack(stackName, region)) {
|
|
14298
14328
|
const msg = "deployed baseline exists but the stack is gone — deleted out of band";
|
|
14299
14329
|
const label = `${stackName} (${region})`;
|
|
14300
14330
|
console.error(`[Drift] ${label}: ${msg}`);
|