cdk-real-drift 0.12.89 → 0.12.91
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 +154 -2
- 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
|
@@ -2746,6 +2746,7 @@ const KNOWN_DEFAULTS = {
|
|
|
2746
2746
|
},
|
|
2747
2747
|
"AWS::CodeStarNotifications::NotificationRule": { Status: "ENABLED" },
|
|
2748
2748
|
"AWS::Rbin::Rule": { Status: "available" },
|
|
2749
|
+
"AWS::Route53Resolver::FirewallRuleGroupAssociation": { MutationProtection: "DISABLED" },
|
|
2749
2750
|
"AWS::RolesAnywhere::TrustAnchor": { NotificationSettings: [{
|
|
2750
2751
|
Channel: "ALL",
|
|
2751
2752
|
Enabled: true,
|
|
@@ -2870,6 +2871,7 @@ const KNOWN_DEFAULT_PATHS = {
|
|
|
2870
2871
|
},
|
|
2871
2872
|
"AWS::ApiGateway::UsagePlan": { "Quota.Offset": 0 },
|
|
2872
2873
|
"AWS::CloudFront::Distribution": {
|
|
2874
|
+
"DistributionConfig.IPV6Enabled": true,
|
|
2873
2875
|
"DistributionConfig.OriginGroups": {
|
|
2874
2876
|
Quantity: 0,
|
|
2875
2877
|
Items: []
|
|
@@ -2879,6 +2881,7 @@ const KNOWN_DEFAULT_PATHS = {
|
|
|
2879
2881
|
"DistributionConfig.Origins.*.CustomOriginConfig.HTTPPort": 80,
|
|
2880
2882
|
"DistributionConfig.Origins.*.CustomOriginConfig.HTTPSPort": 443,
|
|
2881
2883
|
"DistributionConfig.Origins.*.CustomOriginConfig.OriginKeepaliveTimeout": 5,
|
|
2884
|
+
"DistributionConfig.Origins.*.CustomOriginConfig.OriginSSLProtocols": ["SSLv3", "TLSv1"],
|
|
2882
2885
|
"DistributionConfig.Origins.*.S3OriginConfig.OriginReadTimeout": 30,
|
|
2883
2886
|
"DistributionConfig.Restrictions": { GeoRestriction: {
|
|
2884
2887
|
Locations: [],
|
|
@@ -4231,7 +4234,7 @@ const UNORDERED_OBJECT_ARRAY_IDENTITY = {
|
|
|
4231
4234
|
};
|
|
4232
4235
|
const UNORDERED_NESTED_OBJECT_ARRAY_PATHS = {
|
|
4233
4236
|
"AWS::CloudFront::CachePolicy": new Set(["CachePolicyConfig.ParametersInCacheKeyAndForwardedToOrigin.HeadersConfig.Headers"]),
|
|
4234
|
-
"AWS::CloudFront::Distribution": new Set(["DistributionConfig.Aliases"]),
|
|
4237
|
+
"AWS::CloudFront::Distribution": new Set(["DistributionConfig.Aliases", "DistributionConfig.CustomErrorResponses"]),
|
|
4235
4238
|
"AWS::IoT::ThingType": new Set(["ThingTypeProperties.SearchableAttributes"]),
|
|
4236
4239
|
"AWS::Bedrock::Guardrail": new Set([
|
|
4237
4240
|
"ContentPolicyConfig.FiltersConfig",
|
|
@@ -4258,6 +4261,7 @@ const UNORDERED_NESTED_OBJECT_ARRAY_PATHS = {
|
|
|
4258
4261
|
"AWS::Lambda::EventSourceMapping": new Set(["SelfManagedEventSource.Endpoints.KafkaBootstrapServers"])
|
|
4259
4262
|
};
|
|
4260
4263
|
const NESTED_OBJECT_ARRAY_IDENTITY = {
|
|
4264
|
+
"AWS::CloudFront::Distribution": { "DistributionConfig.CustomErrorResponses": "ErrorCode" },
|
|
4261
4265
|
"AWS::Bedrock::Guardrail": {
|
|
4262
4266
|
"ContentPolicyConfig.FiltersConfig": "Type",
|
|
4263
4267
|
"TopicPolicyConfig.TopicsConfig": "Name",
|
|
@@ -6287,6 +6291,65 @@ function pushDeclaredFinding(findings, finding) {
|
|
|
6287
6291
|
...finding
|
|
6288
6292
|
});
|
|
6289
6293
|
}
|
|
6294
|
+
const AAS_SCALABLE_DIMENSIONS = {
|
|
6295
|
+
"ecs:service:DesiredCount": {
|
|
6296
|
+
resourceType: "AWS::ECS::Service",
|
|
6297
|
+
paths: ["DesiredCount"]
|
|
6298
|
+
},
|
|
6299
|
+
"dynamodb:table:ReadCapacityUnits": {
|
|
6300
|
+
resourceType: "AWS::DynamoDB::Table",
|
|
6301
|
+
paths: ["ProvisionedThroughput.ReadCapacityUnits"]
|
|
6302
|
+
},
|
|
6303
|
+
"dynamodb:table:WriteCapacityUnits": {
|
|
6304
|
+
resourceType: "AWS::DynamoDB::Table",
|
|
6305
|
+
paths: ["ProvisionedThroughput.WriteCapacityUnits"]
|
|
6306
|
+
},
|
|
6307
|
+
"lambda:function:ProvisionedConcurrency": {
|
|
6308
|
+
resourceType: "AWS::Lambda::Alias",
|
|
6309
|
+
paths: ["ProvisionedConcurrencyConfig.ProvisionedConcurrentExecutions"]
|
|
6310
|
+
},
|
|
6311
|
+
"elasticache:replication-group:NodeGroups": {
|
|
6312
|
+
resourceType: "AWS::ElastiCache::ReplicationGroup",
|
|
6313
|
+
paths: ["NumNodeGroups"]
|
|
6314
|
+
},
|
|
6315
|
+
"elasticache:replication-group:Replicas": {
|
|
6316
|
+
resourceType: "AWS::ElastiCache::ReplicationGroup",
|
|
6317
|
+
paths: ["ReplicasPerNodeGroup"]
|
|
6318
|
+
}
|
|
6319
|
+
};
|
|
6320
|
+
const AUTOSCALER_HINT_PREFIX = "governed by a sibling AWS::ApplicationAutoScaling::ScalableTarget (Application Auto Scaling)";
|
|
6321
|
+
/**
|
|
6322
|
+
* #688: fold declared findings whose property the stack DELEGATES to Application Auto Scaling.
|
|
6323
|
+
* A sibling ScalableTarget over `(resource, dimension)` means the live value moving within the
|
|
6324
|
+
* declared `[MinCapacity, MaxCapacity]` band is the autoscaler enforcing the template's own
|
|
6325
|
+
* intent (min-enforcement fires within minutes of a clean deploy, zero traffic) — NOT drift, so
|
|
6326
|
+
* the declared finding is DROPPED. A value OUTSIDE the band is a real over-set: it stays, but is
|
|
6327
|
+
* marked `autoscalerGoverned` (+ a hint) so the revert plan refuses a write the scaler would
|
|
6328
|
+
* immediately undo. Range-gated → detection preserved. Pure; only touches `declared`-tier
|
|
6329
|
+
* findings whose path is a governed path (all else passes through untouched).
|
|
6330
|
+
*/
|
|
6331
|
+
function applyAutoscalerBandFold(findings, bands) {
|
|
6332
|
+
const out = [];
|
|
6333
|
+
for (const f of findings) {
|
|
6334
|
+
if (f.tier !== "declared") {
|
|
6335
|
+
out.push(f);
|
|
6336
|
+
continue;
|
|
6337
|
+
}
|
|
6338
|
+
const band = bands.find((b) => b.path === f.path);
|
|
6339
|
+
if (band === void 0) {
|
|
6340
|
+
out.push(f);
|
|
6341
|
+
continue;
|
|
6342
|
+
}
|
|
6343
|
+
const actual = f.actual;
|
|
6344
|
+
if (typeof actual === "number" && Number.isFinite(actual) && actual >= band.min && actual <= band.max) continue;
|
|
6345
|
+
out.push({
|
|
6346
|
+
...f,
|
|
6347
|
+
autoscalerGoverned: true,
|
|
6348
|
+
...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` } : {}
|
|
6349
|
+
});
|
|
6350
|
+
}
|
|
6351
|
+
return out;
|
|
6352
|
+
}
|
|
6290
6353
|
function classifyResource(resource, liveRaw, schema, opts = {}) {
|
|
6291
6354
|
const { logicalId, resourceType, physicalId, declared: declaredIn } = resource;
|
|
6292
6355
|
const findings = [];
|
|
@@ -7404,7 +7467,8 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
|
|
|
7404
7467
|
const cp = resource.constructPath;
|
|
7405
7468
|
const pid = resource.physicalId;
|
|
7406
7469
|
const unresolvedSibling = IAM_PRINCIPAL_POLICY_TYPES.has(resourceType) && resource.siblingPolicyNames === "unresolved";
|
|
7407
|
-
|
|
7470
|
+
const bands = opts.scalableTargetBands?.[resource.logicalId];
|
|
7471
|
+
return (bands ? applyAutoscalerBandFold(findings, bands) : findings).map((f) => ({
|
|
7408
7472
|
...f,
|
|
7409
7473
|
...pid !== void 0 && { physicalId: pid },
|
|
7410
7474
|
...cp !== void 0 && { constructPath: cp },
|
|
@@ -13264,6 +13328,83 @@ function buildClusterEchoModels(desired) {
|
|
|
13264
13328
|
}
|
|
13265
13329
|
return map;
|
|
13266
13330
|
}
|
|
13331
|
+
const SCALABLE_TARGET_TYPE = "AWS::ApplicationAutoScaling::ScalableTarget";
|
|
13332
|
+
function collectRefLogicalIds(v, out = /* @__PURE__ */ new Set()) {
|
|
13333
|
+
if (v == null) return out;
|
|
13334
|
+
if (Array.isArray(v)) {
|
|
13335
|
+
for (const el of v) collectRefLogicalIds(el, out);
|
|
13336
|
+
return out;
|
|
13337
|
+
}
|
|
13338
|
+
if (typeof v !== "object") return out;
|
|
13339
|
+
const o = v;
|
|
13340
|
+
if ("Ref" in o && typeof o.Ref === "string") out.add(o.Ref);
|
|
13341
|
+
if ("Fn::GetAtt" in o) {
|
|
13342
|
+
const g = o["Fn::GetAtt"];
|
|
13343
|
+
if (Array.isArray(g) && typeof g[0] === "string") out.add(g[0]);
|
|
13344
|
+
else if (typeof g === "string") out.add(g.split(".")[0] ?? g);
|
|
13345
|
+
}
|
|
13346
|
+
if ("Fn::Sub" in o) {
|
|
13347
|
+
const s = o["Fn::Sub"];
|
|
13348
|
+
const body = Array.isArray(s) ? s[0] : s;
|
|
13349
|
+
if (typeof body === "string") {
|
|
13350
|
+
for (const m of body.matchAll(/\$\{([A-Za-z0-9]+)(?:\.[^}]+)?\}/g)) if (m[1]) out.add(m[1]);
|
|
13351
|
+
}
|
|
13352
|
+
if (Array.isArray(s) && s[1] && typeof s[1] === "object") collectRefLogicalIds(s[1], out);
|
|
13353
|
+
}
|
|
13354
|
+
for (const [k, val] of Object.entries(o)) {
|
|
13355
|
+
if (k === "Ref" || k === "Fn::GetAtt" || k === "Fn::Sub") continue;
|
|
13356
|
+
collectRefLogicalIds(val, out);
|
|
13357
|
+
}
|
|
13358
|
+
return out;
|
|
13359
|
+
}
|
|
13360
|
+
function buildScalableTargetBands(desired) {
|
|
13361
|
+
const byLogicalId = /* @__PURE__ */ new Map();
|
|
13362
|
+
const byType = /* @__PURE__ */ new Map();
|
|
13363
|
+
for (const r of desired.resources) {
|
|
13364
|
+
byLogicalId.set(r.logicalId, r);
|
|
13365
|
+
const arr = byType.get(r.resourceType);
|
|
13366
|
+
if (arr) arr.push(r);
|
|
13367
|
+
else byType.set(r.resourceType, [r]);
|
|
13368
|
+
}
|
|
13369
|
+
const map = {};
|
|
13370
|
+
const num = (v) => typeof v === "number" && Number.isFinite(v) ? v : void 0;
|
|
13371
|
+
for (const r of desired.resources) {
|
|
13372
|
+
if (r.resourceType !== SCALABLE_TARGET_TYPE) continue;
|
|
13373
|
+
const decl = r.declared ?? {};
|
|
13374
|
+
const dim = decl.ScalableDimension;
|
|
13375
|
+
if (typeof dim !== "string") continue;
|
|
13376
|
+
const spec = AAS_SCALABLE_DIMENSIONS[dim];
|
|
13377
|
+
if (!spec) continue;
|
|
13378
|
+
const live = desired.ctx.liveAttrs[r.logicalId] ?? {};
|
|
13379
|
+
const min = num(decl.MinCapacity) ?? num(live.MinCapacity);
|
|
13380
|
+
const max = num(decl.MaxCapacity) ?? num(live.MaxCapacity);
|
|
13381
|
+
if (min === void 0 || max === void 0) continue;
|
|
13382
|
+
const rawResourceId = r.declaredRaw?.ResourceId;
|
|
13383
|
+
let governed;
|
|
13384
|
+
for (const id of collectRefLogicalIds(rawResourceId)) {
|
|
13385
|
+
const cand = byLogicalId.get(id);
|
|
13386
|
+
if (cand && cand.resourceType === spec.resourceType) {
|
|
13387
|
+
governed = cand;
|
|
13388
|
+
break;
|
|
13389
|
+
}
|
|
13390
|
+
}
|
|
13391
|
+
if (!governed) {
|
|
13392
|
+
const rid = decl.ResourceId;
|
|
13393
|
+
if (typeof rid === "string") {
|
|
13394
|
+
const segs = new Set(rid.split("/"));
|
|
13395
|
+
governed = byType.get(spec.resourceType)?.find((c) => c.physicalId !== void 0 && (segs.has(c.physicalId) || rid.endsWith(c.physicalId)));
|
|
13396
|
+
}
|
|
13397
|
+
}
|
|
13398
|
+
if (!governed) continue;
|
|
13399
|
+
const entries = map[governed.logicalId] ??= [];
|
|
13400
|
+
for (const path of spec.paths) entries.push({
|
|
13401
|
+
path,
|
|
13402
|
+
min,
|
|
13403
|
+
max
|
|
13404
|
+
});
|
|
13405
|
+
}
|
|
13406
|
+
return map;
|
|
13407
|
+
}
|
|
13267
13408
|
async function buildRdsOptionSettingDefaults(desired, region) {
|
|
13268
13409
|
const groups = desired.resources.filter((r) => r.resourceType === "AWS::RDS::OptionGroup" && r.physicalId);
|
|
13269
13410
|
if (groups.length === 0) return {};
|
|
@@ -13501,6 +13642,7 @@ async function gatherFindings(stackName, region, templateOverride, recoveryTempl
|
|
|
13501
13642
|
bucketNotificationManaged: buildBucketNotificationManaged(desired),
|
|
13502
13643
|
bucketNotificationConfigs: buildBucketNotificationConfigs(desired),
|
|
13503
13644
|
clusterEchoModel: buildClusterEchoModels(desired),
|
|
13645
|
+
scalableTargetBands: buildScalableTargetBands(desired),
|
|
13504
13646
|
rdsOptionSettingDefaults: await buildRdsOptionSettingDefaults(desired, region)
|
|
13505
13647
|
};
|
|
13506
13648
|
const corpusDir = process.env[CORPUS_DIR_ENV];
|
|
@@ -13575,6 +13717,7 @@ async function regatherTouched(gathered, touched, region) {
|
|
|
13575
13717
|
bucketNotificationManaged: buildBucketNotificationManaged(desired),
|
|
13576
13718
|
bucketNotificationConfigs: buildBucketNotificationConfigs(desired),
|
|
13577
13719
|
clusterEchoModel: buildClusterEchoModels(desired),
|
|
13720
|
+
scalableTargetBands: buildScalableTargetBands(desired),
|
|
13578
13721
|
rdsOptionSettingDefaults: await buildRdsOptionSettingDefaults(desired, region)
|
|
13579
13722
|
};
|
|
13580
13723
|
const fresh = [];
|
|
@@ -17243,6 +17386,15 @@ function buildRevertPlan(findings, baseline, opts = {}) {
|
|
|
17243
17386
|
desired: f.wholeArrayRevert.value
|
|
17244
17387
|
};
|
|
17245
17388
|
}
|
|
17389
|
+
if (f.autoscalerGoverned) {
|
|
17390
|
+
notRevertable.push({
|
|
17391
|
+
displayId,
|
|
17392
|
+
resourceType: f.resourceType,
|
|
17393
|
+
path: f.path,
|
|
17394
|
+
reason: "managed by Application Auto Scaling — revert would fight the scaler; change the ScalableTarget band / scaling policy, or record/ignore to accept"
|
|
17395
|
+
});
|
|
17396
|
+
continue;
|
|
17397
|
+
}
|
|
17246
17398
|
if (f.tier === "deleted") {
|
|
17247
17399
|
notRevertable.push({
|
|
17248
17400
|
displayId,
|