cdk-real-drift 0.12.89 → 0.12.90
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 +14 -7
- package/dist/cli.js +149 -1
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -512,10 +512,17 @@ no such gap and compares transformed stacks fully; prefer it for SAM/macro apps.
|
|
|
512
512
|
|
|
513
513
|
### Ignoring externally-managed properties
|
|
514
514
|
|
|
515
|
-
Some properties are _legitimately_ rewritten by another system
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
515
|
+
Some properties are _legitimately_ rewritten by another system. cdkrd already folds
|
|
516
|
+
the most common case automatically: a property a sibling
|
|
517
|
+
`AWS::ApplicationAutoScaling::ScalableTarget` governs — an ECS Service `DesiredCount`,
|
|
518
|
+
autoscaled DynamoDB capacity, a Lambda alias's provisioned concurrency, … — is **not**
|
|
519
|
+
flagged while its live value stays within the declared `MinCapacity`/`MaxCapacity`
|
|
520
|
+
band (the autoscaler enforcing the template's own delegation is intent, not drift,
|
|
521
|
+
#688). A value pushed _beyond_ the band still surfaces as real drift, but `revert`
|
|
522
|
+
deliberately refuses it (writing the initial value back would just be re-scaled). For
|
|
523
|
+
anything cdkrd does not fold — an externally-managed Lambda **reserved** concurrency,
|
|
524
|
+
a value another controller rewrites — run **`cdkrd ignore`** to pick the drift to
|
|
525
|
+
suppress, or hand-edit the git-committed `.cdkrd/ignore.yaml`. It is a
|
|
519
526
|
hand-edited policy file (the `.gitignore` / `.dockerignore` / `.trivyignore`
|
|
520
527
|
family), so it is YAML rather than JSON: the single most valuable hand-edit is a
|
|
521
528
|
`#` comment recording **why** a property is ignored, and YAML can carry it where
|
|
@@ -525,10 +532,10 @@ machine-generated, wholesale-rewritten data, not human policy.)
|
|
|
525
532
|
```yaml
|
|
526
533
|
# cdkrd ignore rules — properties cdkrd should stop reporting as drift.
|
|
527
534
|
ignore:
|
|
528
|
-
#
|
|
529
|
-
- path: '*.
|
|
535
|
+
# reserved concurrency is managed by an external controller (not AAS, so not auto-folded)
|
|
536
|
+
- path: '*.ReservedConcurrentExecutions'
|
|
530
537
|
# the common case: scope a rule to one stack
|
|
531
|
-
- path: '*.
|
|
538
|
+
- path: '*.ReservedConcurrentExecutions'
|
|
532
539
|
stack: Prod*
|
|
533
540
|
# narrow further to a single account and/or region when the same stack
|
|
534
541
|
# name is deployed to several (a property may legitimately drift in only one)
|
package/dist/cli.js
CHANGED
|
@@ -6287,6 +6287,65 @@ function pushDeclaredFinding(findings, finding) {
|
|
|
6287
6287
|
...finding
|
|
6288
6288
|
});
|
|
6289
6289
|
}
|
|
6290
|
+
const AAS_SCALABLE_DIMENSIONS = {
|
|
6291
|
+
"ecs:service:DesiredCount": {
|
|
6292
|
+
resourceType: "AWS::ECS::Service",
|
|
6293
|
+
paths: ["DesiredCount"]
|
|
6294
|
+
},
|
|
6295
|
+
"dynamodb:table:ReadCapacityUnits": {
|
|
6296
|
+
resourceType: "AWS::DynamoDB::Table",
|
|
6297
|
+
paths: ["ProvisionedThroughput.ReadCapacityUnits"]
|
|
6298
|
+
},
|
|
6299
|
+
"dynamodb:table:WriteCapacityUnits": {
|
|
6300
|
+
resourceType: "AWS::DynamoDB::Table",
|
|
6301
|
+
paths: ["ProvisionedThroughput.WriteCapacityUnits"]
|
|
6302
|
+
},
|
|
6303
|
+
"lambda:function:ProvisionedConcurrency": {
|
|
6304
|
+
resourceType: "AWS::Lambda::Alias",
|
|
6305
|
+
paths: ["ProvisionedConcurrencyConfig.ProvisionedConcurrentExecutions"]
|
|
6306
|
+
},
|
|
6307
|
+
"elasticache:replication-group:NodeGroups": {
|
|
6308
|
+
resourceType: "AWS::ElastiCache::ReplicationGroup",
|
|
6309
|
+
paths: ["NumNodeGroups"]
|
|
6310
|
+
},
|
|
6311
|
+
"elasticache:replication-group:Replicas": {
|
|
6312
|
+
resourceType: "AWS::ElastiCache::ReplicationGroup",
|
|
6313
|
+
paths: ["ReplicasPerNodeGroup"]
|
|
6314
|
+
}
|
|
6315
|
+
};
|
|
6316
|
+
const AUTOSCALER_HINT_PREFIX = "governed by a sibling AWS::ApplicationAutoScaling::ScalableTarget (Application Auto Scaling)";
|
|
6317
|
+
/**
|
|
6318
|
+
* #688: fold declared findings whose property the stack DELEGATES to Application Auto Scaling.
|
|
6319
|
+
* A sibling ScalableTarget over `(resource, dimension)` means the live value moving within the
|
|
6320
|
+
* declared `[MinCapacity, MaxCapacity]` band is the autoscaler enforcing the template's own
|
|
6321
|
+
* intent (min-enforcement fires within minutes of a clean deploy, zero traffic) — NOT drift, so
|
|
6322
|
+
* the declared finding is DROPPED. A value OUTSIDE the band is a real over-set: it stays, but is
|
|
6323
|
+
* marked `autoscalerGoverned` (+ a hint) so the revert plan refuses a write the scaler would
|
|
6324
|
+
* immediately undo. Range-gated → detection preserved. Pure; only touches `declared`-tier
|
|
6325
|
+
* findings whose path is a governed path (all else passes through untouched).
|
|
6326
|
+
*/
|
|
6327
|
+
function applyAutoscalerBandFold(findings, bands) {
|
|
6328
|
+
const out = [];
|
|
6329
|
+
for (const f of findings) {
|
|
6330
|
+
if (f.tier !== "declared") {
|
|
6331
|
+
out.push(f);
|
|
6332
|
+
continue;
|
|
6333
|
+
}
|
|
6334
|
+
const band = bands.find((b) => b.path === f.path);
|
|
6335
|
+
if (band === void 0) {
|
|
6336
|
+
out.push(f);
|
|
6337
|
+
continue;
|
|
6338
|
+
}
|
|
6339
|
+
const actual = f.actual;
|
|
6340
|
+
if (typeof actual === "number" && Number.isFinite(actual) && actual >= band.min && actual <= band.max) continue;
|
|
6341
|
+
out.push({
|
|
6342
|
+
...f,
|
|
6343
|
+
autoscalerGoverned: true,
|
|
6344
|
+
...f.hint === void 0 ? { hint: `${AUTOSCALER_HINT_PREFIX}, band ${band.min}..${band.max}; the live value is outside it, so this is a real change — but revert cannot converge (the scaler re-adjusts it). Change the ScalableTarget band / scaling policy, or record/ignore to accept it` } : {}
|
|
6345
|
+
});
|
|
6346
|
+
}
|
|
6347
|
+
return out;
|
|
6348
|
+
}
|
|
6290
6349
|
function classifyResource(resource, liveRaw, schema, opts = {}) {
|
|
6291
6350
|
const { logicalId, resourceType, physicalId, declared: declaredIn } = resource;
|
|
6292
6351
|
const findings = [];
|
|
@@ -7404,7 +7463,8 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
|
|
|
7404
7463
|
const cp = resource.constructPath;
|
|
7405
7464
|
const pid = resource.physicalId;
|
|
7406
7465
|
const unresolvedSibling = IAM_PRINCIPAL_POLICY_TYPES.has(resourceType) && resource.siblingPolicyNames === "unresolved";
|
|
7407
|
-
|
|
7466
|
+
const bands = opts.scalableTargetBands?.[resource.logicalId];
|
|
7467
|
+
return (bands ? applyAutoscalerBandFold(findings, bands) : findings).map((f) => ({
|
|
7408
7468
|
...f,
|
|
7409
7469
|
...pid !== void 0 && { physicalId: pid },
|
|
7410
7470
|
...cp !== void 0 && { constructPath: cp },
|
|
@@ -13264,6 +13324,83 @@ function buildClusterEchoModels(desired) {
|
|
|
13264
13324
|
}
|
|
13265
13325
|
return map;
|
|
13266
13326
|
}
|
|
13327
|
+
const SCALABLE_TARGET_TYPE = "AWS::ApplicationAutoScaling::ScalableTarget";
|
|
13328
|
+
function collectRefLogicalIds(v, out = /* @__PURE__ */ new Set()) {
|
|
13329
|
+
if (v == null) return out;
|
|
13330
|
+
if (Array.isArray(v)) {
|
|
13331
|
+
for (const el of v) collectRefLogicalIds(el, out);
|
|
13332
|
+
return out;
|
|
13333
|
+
}
|
|
13334
|
+
if (typeof v !== "object") return out;
|
|
13335
|
+
const o = v;
|
|
13336
|
+
if ("Ref" in o && typeof o.Ref === "string") out.add(o.Ref);
|
|
13337
|
+
if ("Fn::GetAtt" in o) {
|
|
13338
|
+
const g = o["Fn::GetAtt"];
|
|
13339
|
+
if (Array.isArray(g) && typeof g[0] === "string") out.add(g[0]);
|
|
13340
|
+
else if (typeof g === "string") out.add(g.split(".")[0] ?? g);
|
|
13341
|
+
}
|
|
13342
|
+
if ("Fn::Sub" in o) {
|
|
13343
|
+
const s = o["Fn::Sub"];
|
|
13344
|
+
const body = Array.isArray(s) ? s[0] : s;
|
|
13345
|
+
if (typeof body === "string") {
|
|
13346
|
+
for (const m of body.matchAll(/\$\{([A-Za-z0-9]+)(?:\.[^}]+)?\}/g)) if (m[1]) out.add(m[1]);
|
|
13347
|
+
}
|
|
13348
|
+
if (Array.isArray(s) && s[1] && typeof s[1] === "object") collectRefLogicalIds(s[1], out);
|
|
13349
|
+
}
|
|
13350
|
+
for (const [k, val] of Object.entries(o)) {
|
|
13351
|
+
if (k === "Ref" || k === "Fn::GetAtt" || k === "Fn::Sub") continue;
|
|
13352
|
+
collectRefLogicalIds(val, out);
|
|
13353
|
+
}
|
|
13354
|
+
return out;
|
|
13355
|
+
}
|
|
13356
|
+
function buildScalableTargetBands(desired) {
|
|
13357
|
+
const byLogicalId = /* @__PURE__ */ new Map();
|
|
13358
|
+
const byType = /* @__PURE__ */ new Map();
|
|
13359
|
+
for (const r of desired.resources) {
|
|
13360
|
+
byLogicalId.set(r.logicalId, r);
|
|
13361
|
+
const arr = byType.get(r.resourceType);
|
|
13362
|
+
if (arr) arr.push(r);
|
|
13363
|
+
else byType.set(r.resourceType, [r]);
|
|
13364
|
+
}
|
|
13365
|
+
const map = {};
|
|
13366
|
+
const num = (v) => typeof v === "number" && Number.isFinite(v) ? v : void 0;
|
|
13367
|
+
for (const r of desired.resources) {
|
|
13368
|
+
if (r.resourceType !== SCALABLE_TARGET_TYPE) continue;
|
|
13369
|
+
const decl = r.declared ?? {};
|
|
13370
|
+
const dim = decl.ScalableDimension;
|
|
13371
|
+
if (typeof dim !== "string") continue;
|
|
13372
|
+
const spec = AAS_SCALABLE_DIMENSIONS[dim];
|
|
13373
|
+
if (!spec) continue;
|
|
13374
|
+
const live = desired.ctx.liveAttrs[r.logicalId] ?? {};
|
|
13375
|
+
const min = num(decl.MinCapacity) ?? num(live.MinCapacity);
|
|
13376
|
+
const max = num(decl.MaxCapacity) ?? num(live.MaxCapacity);
|
|
13377
|
+
if (min === void 0 || max === void 0) continue;
|
|
13378
|
+
const rawResourceId = r.declaredRaw?.ResourceId;
|
|
13379
|
+
let governed;
|
|
13380
|
+
for (const id of collectRefLogicalIds(rawResourceId)) {
|
|
13381
|
+
const cand = byLogicalId.get(id);
|
|
13382
|
+
if (cand && cand.resourceType === spec.resourceType) {
|
|
13383
|
+
governed = cand;
|
|
13384
|
+
break;
|
|
13385
|
+
}
|
|
13386
|
+
}
|
|
13387
|
+
if (!governed) {
|
|
13388
|
+
const rid = decl.ResourceId;
|
|
13389
|
+
if (typeof rid === "string") {
|
|
13390
|
+
const segs = new Set(rid.split("/"));
|
|
13391
|
+
governed = byType.get(spec.resourceType)?.find((c) => c.physicalId !== void 0 && (segs.has(c.physicalId) || rid.endsWith(c.physicalId)));
|
|
13392
|
+
}
|
|
13393
|
+
}
|
|
13394
|
+
if (!governed) continue;
|
|
13395
|
+
const entries = map[governed.logicalId] ??= [];
|
|
13396
|
+
for (const path of spec.paths) entries.push({
|
|
13397
|
+
path,
|
|
13398
|
+
min,
|
|
13399
|
+
max
|
|
13400
|
+
});
|
|
13401
|
+
}
|
|
13402
|
+
return map;
|
|
13403
|
+
}
|
|
13267
13404
|
async function buildRdsOptionSettingDefaults(desired, region) {
|
|
13268
13405
|
const groups = desired.resources.filter((r) => r.resourceType === "AWS::RDS::OptionGroup" && r.physicalId);
|
|
13269
13406
|
if (groups.length === 0) return {};
|
|
@@ -13501,6 +13638,7 @@ async function gatherFindings(stackName, region, templateOverride, recoveryTempl
|
|
|
13501
13638
|
bucketNotificationManaged: buildBucketNotificationManaged(desired),
|
|
13502
13639
|
bucketNotificationConfigs: buildBucketNotificationConfigs(desired),
|
|
13503
13640
|
clusterEchoModel: buildClusterEchoModels(desired),
|
|
13641
|
+
scalableTargetBands: buildScalableTargetBands(desired),
|
|
13504
13642
|
rdsOptionSettingDefaults: await buildRdsOptionSettingDefaults(desired, region)
|
|
13505
13643
|
};
|
|
13506
13644
|
const corpusDir = process.env[CORPUS_DIR_ENV];
|
|
@@ -13575,6 +13713,7 @@ async function regatherTouched(gathered, touched, region) {
|
|
|
13575
13713
|
bucketNotificationManaged: buildBucketNotificationManaged(desired),
|
|
13576
13714
|
bucketNotificationConfigs: buildBucketNotificationConfigs(desired),
|
|
13577
13715
|
clusterEchoModel: buildClusterEchoModels(desired),
|
|
13716
|
+
scalableTargetBands: buildScalableTargetBands(desired),
|
|
13578
13717
|
rdsOptionSettingDefaults: await buildRdsOptionSettingDefaults(desired, region)
|
|
13579
13718
|
};
|
|
13580
13719
|
const fresh = [];
|
|
@@ -17243,6 +17382,15 @@ function buildRevertPlan(findings, baseline, opts = {}) {
|
|
|
17243
17382
|
desired: f.wholeArrayRevert.value
|
|
17244
17383
|
};
|
|
17245
17384
|
}
|
|
17385
|
+
if (f.autoscalerGoverned) {
|
|
17386
|
+
notRevertable.push({
|
|
17387
|
+
displayId,
|
|
17388
|
+
resourceType: f.resourceType,
|
|
17389
|
+
path: f.path,
|
|
17390
|
+
reason: "managed by Application Auto Scaling — revert would fight the scaler; change the ScalableTarget band / scaling policy, or record/ignore to accept"
|
|
17391
|
+
});
|
|
17392
|
+
continue;
|
|
17393
|
+
}
|
|
17246
17394
|
if (f.tier === "deleted") {
|
|
17247
17395
|
notRevertable.push({
|
|
17248
17396
|
displayId,
|