cdk-real-drift 0.2.76 → 0.2.77
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 +66 -7
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -816,6 +816,29 @@ var QuietIoHost = class extends NonInteractiveIoHost {
|
|
|
816
816
|
}
|
|
817
817
|
};
|
|
818
818
|
|
|
819
|
+
//#endregion
|
|
820
|
+
//#region src/synth/missing-context.ts
|
|
821
|
+
/** Unique, sorted missing-context keys (dedup by key). Empty array when nothing is missing. */
|
|
822
|
+
function missingContextKeys(missing) {
|
|
823
|
+
if (!missing || missing.length === 0) return [];
|
|
824
|
+
return [...new Set(missing.map((m) => m.key))].sort();
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* Build the stderr message body (no `warning:`/`error:` prefix — the caller adds it) for an
|
|
828
|
+
* assembly synthesized with unresolved context lookups. Returns `null` when `keys` is empty
|
|
829
|
+
* (a clean assembly — behavior unchanged). Under `preDeploy` the wording escalates to an
|
|
830
|
+
* explicit REFUSAL: the placeholders are the declared source there, so proceeding on
|
|
831
|
+
* fabricated values (false drift, a bad `--fail`, a revert that writes dummies back) is worse
|
|
832
|
+
* than stopping — the user must supply the context or deploy so the lookups resolve.
|
|
833
|
+
*/
|
|
834
|
+
function missingContextWarning(keys, opts = {}) {
|
|
835
|
+
if (keys.length === 0) return null;
|
|
836
|
+
const lead = `the CDK app synthesized with ${keys.length} unresolved context lookup(s): ${keys.join(", ")}`;
|
|
837
|
+
const why = "CDK filled these with placeholder dummy values (e.g. vpc-12345), so the synthesized template does not reflect real infrastructure.";
|
|
838
|
+
if (opts.preDeploy) return `${lead}\n${why}\n(--pre-deploy) refusing: those placeholders are the DECLARED source, so every check would report fabricated declared drift and a revert would write the dummy values back to AWS. Provide the context (commit cdk.context.json, pass -c key=value, or deploy so the lookups resolve) and re-run.`;
|
|
839
|
+
return `${lead}\n${why}`;
|
|
840
|
+
}
|
|
841
|
+
|
|
819
842
|
//#endregion
|
|
820
843
|
//#region src/synth/synth.ts
|
|
821
844
|
const CONCRETE_REGION = /^[a-z]{2}(-[a-z]+)+-\d+$/;
|
|
@@ -847,6 +870,12 @@ async function synthApp(app, opts = {}) {
|
|
|
847
870
|
}
|
|
848
871
|
const cached = await toolkit.synth(source);
|
|
849
872
|
try {
|
|
873
|
+
const missingKeys = missingContextKeys(cached.cloudAssembly.manifest.missing);
|
|
874
|
+
if (missingKeys.length > 0) {
|
|
875
|
+
const msg = missingContextWarning(missingKeys, { preDeploy: opts.preDeploy });
|
|
876
|
+
if (opts.preDeploy) throw new Error(msg ?? "unresolved CDK context lookups");
|
|
877
|
+
console.error(`warning: ${msg}`);
|
|
878
|
+
}
|
|
850
879
|
return cached.cloudAssembly.stacksRecursively.map((s) => ({
|
|
851
880
|
stackName: s.stackName,
|
|
852
881
|
region: CONCRETE_REGION.test(s.environment.region) ? s.environment.region : void 0,
|
|
@@ -1383,6 +1412,20 @@ const KNOWN_DEFAULTS = {
|
|
|
1383
1412
|
BucketKeyEnabled: true,
|
|
1384
1413
|
ServerSideEncryptionByDefault: { SSEAlgorithm: "AES256" }
|
|
1385
1414
|
}] } },
|
|
1415
|
+
"AWS::S3::AccessPoint": { PublicAccessBlockConfiguration: {
|
|
1416
|
+
RestrictPublicBuckets: true,
|
|
1417
|
+
BlockPublicPolicy: true,
|
|
1418
|
+
BlockPublicAcls: true,
|
|
1419
|
+
IgnorePublicAcls: true
|
|
1420
|
+
} },
|
|
1421
|
+
"AWS::ImageBuilder::InfrastructureConfiguration": { TerminateInstanceOnFailure: true },
|
|
1422
|
+
"AWS::ImageBuilder::ImagePipeline": {
|
|
1423
|
+
EnhancedImageMetadataEnabled: true,
|
|
1424
|
+
ImageTestsConfiguration: {
|
|
1425
|
+
ImageTestsEnabled: true,
|
|
1426
|
+
TimeoutMinutes: 720
|
|
1427
|
+
}
|
|
1428
|
+
},
|
|
1386
1429
|
"AWS::S3Tables::TableBucket": {
|
|
1387
1430
|
StorageClassConfiguration: { StorageClass: "STANDARD" },
|
|
1388
1431
|
MetricsConfiguration: { Status: "Disabled" },
|
|
@@ -2323,7 +2366,8 @@ const CONTEXT_ARN_DEFAULTS = {
|
|
|
2323
2366
|
"AWS::ResourceExplorer2::View": { Scope: "arn:{partition}:iam::{accountId}:root" },
|
|
2324
2367
|
"AWS::KinesisVideo::Stream": { KmsKeyId: "arn:{partition}:kms:{region}:{accountId}:alias/aws/kinesisvideo" },
|
|
2325
2368
|
"AWS::AutoScaling::AutoScalingGroup": { ServiceLinkedRoleARN: "arn:{partition}:iam::{accountId}:role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling" },
|
|
2326
|
-
"AWS::LakeFormation::Tag": { CatalogId: "{accountId}" }
|
|
2369
|
+
"AWS::LakeFormation::Tag": { CatalogId: "{accountId}" },
|
|
2370
|
+
"AWS::S3::AccessPoint": { BucketAccountId: "{accountId}" }
|
|
2327
2371
|
};
|
|
2328
2372
|
const ENGINE_DEFAULTS = {
|
|
2329
2373
|
"AWS::RDS::DBInstance": {
|
|
@@ -2788,7 +2832,10 @@ const CASE_INSENSITIVE_PATHS = {
|
|
|
2788
2832
|
"AWS::RDS::DBCluster": new Set(["DBClusterIdentifier"]),
|
|
2789
2833
|
"AWS::DMS::Endpoint": new Set(["EndpointType"]),
|
|
2790
2834
|
"AWS::WAFv2::LoggingConfiguration": new Set(["RedactedFields.*.SingleHeader.Name"]),
|
|
2791
|
-
"AWS::ElasticLoadBalancing::LoadBalancer": new Set(["Listeners.*.Protocol", "Listeners.*.InstanceProtocol"])
|
|
2835
|
+
"AWS::ElasticLoadBalancing::LoadBalancer": new Set(["Listeners.*.Protocol", "Listeners.*.InstanceProtocol"]),
|
|
2836
|
+
"AWS::EC2::SecurityGroup": new Set(["SecurityGroupIngress.*.IpProtocol", "SecurityGroupEgress.*.IpProtocol"]),
|
|
2837
|
+
"AWS::EC2::SecurityGroupIngress": new Set(["IpProtocol"]),
|
|
2838
|
+
"AWS::EC2::SecurityGroupEgress": new Set(["IpProtocol"])
|
|
2792
2839
|
};
|
|
2793
2840
|
function isCaseInsensitiveScalarEqual(a, b) {
|
|
2794
2841
|
return typeof a === "string" && typeof b === "string" && a.toLowerCase() === b.toLowerCase();
|
|
@@ -9367,8 +9414,11 @@ async function loadBaseline(stackName, accountId, region) {
|
|
|
9367
9414
|
throw new Error(`baseline file ${path} is not valid JSON (corrupt or partially written)`);
|
|
9368
9415
|
}
|
|
9369
9416
|
if (parsed === null || typeof parsed !== "object") throw new Error(`baseline file ${path} is malformed: root is not an object`);
|
|
9417
|
+
if (parsed.stackName && parsed.stackName !== stackName) throw new Error(`baseline file ${path} was captured for stack ${parsed.stackName}, but it was loaded as stack ${stackName} (the file was likely copied or renamed to the wrong path, or a case-insensitive filesystem collided two stacks onto one file). Baselines are per-stack — run \`cdkrd record\` to write this stack's own baseline file, or restore the correct file from git.`);
|
|
9418
|
+
if (parsed.region && parsed.region !== region) throw new Error(`baseline file ${path} was captured in region ${parsed.region}, but the current region is ${region} (the file was likely copied or renamed to the wrong region path). Baselines are per-region — run \`cdkrd record\` to write this region's own baseline file, or restore the correct file from git.`);
|
|
9370
9419
|
if (parsed.recorded === void 0 && parsed.accepted !== void 0) parsed.recorded = parsed.accepted;
|
|
9371
9420
|
delete parsed.accepted;
|
|
9421
|
+
if (parsed.schemaVersion !== void 0 && typeof parsed.schemaVersion !== "number") throw new Error(`baseline file ${path} has a non-numeric schemaVersion (${JSON.stringify(parsed.schemaVersion)}); it is malformed (corrupt or hand-edited)`);
|
|
9372
9422
|
if (typeof parsed.schemaVersion === "number" && parsed.schemaVersion > 2) throw new Error(`baseline file ${path} was written by a newer cdkrd (schemaVersion ${parsed.schemaVersion}); upgrade cdkrd`);
|
|
9373
9423
|
if (!Array.isArray(parsed.recorded)) throw new Error(`baseline file ${path} is malformed: \`recorded\` is missing or not an array`);
|
|
9374
9424
|
parsed.recorded.forEach((entry, i) => validateRecordedEntry(entry, i, path));
|
|
@@ -12349,6 +12399,7 @@ function revertSelectMessage(stackName) {
|
|
|
12349
12399
|
async function recordStack(p) {
|
|
12350
12400
|
const { stackName, region, desired, findings, yes, interactive, preselectedKeys, expandNested } = p;
|
|
12351
12401
|
const existing = await loadBaseline(stackName, desired.accountId, region);
|
|
12402
|
+
if (existing) checkBaselineAccount(existing, desired.accountId, stackName);
|
|
12352
12403
|
if (!yes && existing) console.error(`note: ${stackName}: will overwrite the existing baseline file on confirm (nothing written yet; it is git-tracked — review the diff afterwards). Pass --yes to silence.`);
|
|
12353
12404
|
let recorded = carryForwardUnreadable(buildRecorded(findings), existing, findings);
|
|
12354
12405
|
let refreshedOnly = false;
|
|
@@ -13909,11 +13960,19 @@ async function runCheck(args) {
|
|
|
13909
13960
|
emitEmptyJsonOnError();
|
|
13910
13961
|
return 2;
|
|
13911
13962
|
}
|
|
13912
|
-
|
|
13913
|
-
|
|
13914
|
-
|
|
13915
|
-
|
|
13916
|
-
|
|
13963
|
+
let synthed;
|
|
13964
|
+
try {
|
|
13965
|
+
synthed = await synthApp(app, {
|
|
13966
|
+
region: a.region,
|
|
13967
|
+
profile: a.profile,
|
|
13968
|
+
context: a.context,
|
|
13969
|
+
preDeploy: true
|
|
13970
|
+
});
|
|
13971
|
+
} catch (e) {
|
|
13972
|
+
console.error(`error: ${e.message}`);
|
|
13973
|
+
emitEmptyJsonOnError();
|
|
13974
|
+
return 2;
|
|
13975
|
+
}
|
|
13917
13976
|
synthTemplates = new Map(synthed.map((s) => [synthKey(s.stackName, s.region ?? a.region), s.template]));
|
|
13918
13977
|
console.error("(--pre-deploy) comparing live state against the LOCAL synth template");
|
|
13919
13978
|
}
|