cdk-real-drift 0.4.21 → 0.4.23
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 +74 -10
- package/dist/cli.js +161 -33
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -710,7 +710,10 @@ covers them. **If you never run `revert`, cdkrd needs no write permissions at al
|
|
|
710
710
|
templates using `Fn::ImportValue`)
|
|
711
711
|
- `cloudcontrol:GetResource`: Cloud Control invokes each type's own read handler,
|
|
712
712
|
so it needs that type's read permissions (this is why `ReadOnlyAccess` is the
|
|
713
|
-
simple answer)
|
|
713
|
+
simple answer). `revert` additionally uses `cloudcontrol:UpdateResource` /
|
|
714
|
+
`cloudcontrol:DeleteResource` (the latter to delete an out-of-band `added`
|
|
715
|
+
resource) and `cloudcontrol:GetResourceRequestStatus` to poll the async request —
|
|
716
|
+
see the revert section below.
|
|
714
717
|
- SDK readers for the Cloud-Control-gap types: `s3:GetBucketPolicy`,
|
|
715
718
|
`sns:GetTopicAttributes`, `sqs:GetQueueAttributes`, `iam:GetRolePolicy`,
|
|
716
719
|
`iam:GetUserPolicy`, `iam:GetGroupPolicy`, `iam:GetPolicy`, `iam:GetPolicyVersion`,
|
|
@@ -776,9 +779,30 @@ covers them. **If you never run `revert`, cdkrd needs no write permissions at al
|
|
|
776
779
|
full resolved option set; an out-of-band console edit to any environment option
|
|
777
780
|
is otherwise invisible, and the service-filled default options fold to
|
|
778
781
|
`atDefault`),
|
|
779
|
-
`servicediscovery:GetNamespace` (
|
|
782
|
+
`servicediscovery:GetNamespace` + `servicediscovery:GetService` (read a Cloud Map
|
|
780
783
|
`HttpNamespace` / `PrivateDnsNamespace` / `PublicDnsNamespace` — incl. the Arn an
|
|
781
|
-
ECS Service Connect namespace `Fn::GetAtt` resolves against
|
|
784
|
+
ECS Service Connect namespace `Fn::GetAtt` resolves against — and a Cloud Map
|
|
785
|
+
`Service`),
|
|
786
|
+
`docdb:DescribeDBClusters` + `docdb:DescribeDBInstances` (read an
|
|
787
|
+
`AWS::DocDB::DBCluster` / `AWS::DocDB::DBInstance` — the whole DocumentDB family is
|
|
788
|
+
a Cloud Control read gap),
|
|
789
|
+
`codebuild:BatchGetProjects` (reads an `AWS::CodeBuild::Project`) +
|
|
790
|
+
`codebuild:BatchGetReportGroups` (reads an `AWS::CodeBuild::ReportGroup`),
|
|
791
|
+
`dax:DescribeClusters` + `dax:DescribeParameterGroups` + `dax:DescribeParameters` +
|
|
792
|
+
`dax:DescribeSubnetGroups` (read an `AWS::DAX::Cluster` / `ParameterGroup` /
|
|
793
|
+
`SubnetGroup` — the DynamoDB Accelerator family),
|
|
794
|
+
`ec2:DescribeClientVpnEndpoints` + `ec2:DescribeClientVpnAuthorizationRules` +
|
|
795
|
+
`ec2:DescribeClientVpnTargetNetworks` (read an `AWS::EC2::ClientVpnEndpoint` /
|
|
796
|
+
`ClientVpnAuthorizationRule` / `ClientVpnTargetNetworkAssociation`),
|
|
797
|
+
`iam:ListAccessKeys` (reads an `AWS::IAM::AccessKey`'s `Status`) +
|
|
798
|
+
`iam:ListEntitiesForPolicy` (enumerates a managed policy's attachments),
|
|
799
|
+
`appsync:ListApiKeys` (reads an `AWS::AppSync::ApiKey` — a Cloud Control gap),
|
|
800
|
+
`cognito-sync:GetCognitoEvents` (enriches the Cloud Control read of an
|
|
801
|
+
`AWS::Cognito::IdentityPool` with its writeOnly `CognitoEvents` Sync trigger),
|
|
802
|
+
`glue:GetClassifier` + `glue:GetWorkflow` + `glue:GetConnection`
|
|
803
|
+
(`glue:GetConnection` is issued with `HidePassword` so NO credential enters the
|
|
804
|
+
baseline — read an `AWS::Glue::Classifier` / `Workflow` / `Connection`, the rest
|
|
805
|
+
of the Glue family that has no Cloud Control handler)
|
|
782
806
|
- Optional: `elasticloadbalancing:GetTrustStoreCaCertificatesBundle` records a
|
|
783
807
|
content hash of an `AWS::ElasticLoadBalancingV2::TrustStore`'s live mTLS CA
|
|
784
808
|
bundle (`CaCertificatesBundleSha256`) so an out-of-band CA-bundle swap
|
|
@@ -839,8 +863,12 @@ covers them. **If you never run `revert`, cdkrd needs no write permissions at al
|
|
|
839
863
|
<summary>Additional write permissions (revert)</summary>
|
|
840
864
|
|
|
841
865
|
`cloudcontrol:UpdateResource` (which resolves to each type's own update
|
|
842
|
-
permissions),
|
|
866
|
+
permissions), `cloudcontrol:DeleteResource` (to delete an out-of-band `added`
|
|
867
|
+
resource), and `cloudcontrol:GetResourceRequestStatus` (to poll the async Cloud
|
|
868
|
+
Control request to completion). Plus, for the SDK-written types:
|
|
869
|
+
`s3:PutBucketPolicy` /
|
|
843
870
|
`s3:DeleteBucketPolicy`, `sns:SetTopicAttributes`, `sqs:SetQueueAttributes`,
|
|
871
|
+
`events:PutPermission` (reverts an `AWS::Events::EventBusPolicy`),
|
|
844
872
|
`iam:PutRolePolicy` / `DeleteRolePolicy` / `PutUserPolicy` / `PutGroupPolicy`,
|
|
845
873
|
`iam:CreatePolicyVersion` / `DeletePolicyVersion` / `ListPolicyVersions`,
|
|
846
874
|
`elasticloadbalancing:ModifyLoadBalancerAttributes` / `ModifyTargetGroupAttributes`,
|
|
@@ -868,12 +896,48 @@ place, since Cloud Control has no handler for the type),
|
|
|
868
896
|
`ecs:UpdateService` (reverts an `AWS::ECS::Service` `ServiceConnectConfiguration` /
|
|
869
897
|
`VolumeConfigurations` drift — the whole writeOnly prop is re-supplied, since Cloud
|
|
870
898
|
Control cannot sub-path patch it),
|
|
871
|
-
`
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
`
|
|
875
|
-
|
|
876
|
-
|
|
899
|
+
`elasticbeanstalk:UpdateApplication` / `elasticbeanstalk:UpdateEnvironment`
|
|
900
|
+
(revert an `AWS::ElasticBeanstalk::Application` / `Environment`),
|
|
901
|
+
`codebuild:UpdateReportGroup` (reverts an `AWS::CodeBuild::ReportGroup`),
|
|
902
|
+
`dax:UpdateCluster` / `dax:UpdateParameterGroup` (revert an `AWS::DAX::Cluster` /
|
|
903
|
+
`ParameterGroup`),
|
|
904
|
+
`ec2:ModifyClientVpnEndpoint` (reverts an `AWS::EC2::ClientVpnEndpoint`),
|
|
905
|
+
`opensearch:UpdateDomainConfig` (reverts an `AWS::OpenSearchService::Domain`),
|
|
906
|
+
`cloudfront:GetDistributionConfig` / `cloudfront:UpdateDistribution` (revert an
|
|
907
|
+
`AWS::CloudFront::Distribution`),
|
|
908
|
+
`wafv2:GetWebACL` / `wafv2:UpdateWebACL` (revert an `AWS::WAFv2::WebACL`),
|
|
909
|
+
`glue:UpdateJob` / `glue:UpdateClassifier` / `glue:UpdateWorkflow` (revert an
|
|
910
|
+
`AWS::Glue::Job` / `Classifier` / `Workflow`),
|
|
911
|
+
`servicediscovery:UpdateHttpNamespace` (reverts an
|
|
912
|
+
`AWS::ServiceDiscovery::HttpNamespace` `Description`),
|
|
913
|
+
`cognito-sync:SetCognitoEvents` (reverts an `AWS::Cognito::IdentityPool`'s
|
|
914
|
+
writeOnly `CognitoEvents`),
|
|
915
|
+
`kinesisvideo:UpdateDataRetention` / `kinesisvideo:UpdateSignalingChannel` /
|
|
916
|
+
`kinesisvideo:UpdateStreamStorageConfiguration` (revert an `AWS::KinesisVideo::Stream`
|
|
917
|
+
`DataRetentionInHours` / `StreamStorageConfiguration` and an
|
|
918
|
+
`AWS::KinesisVideo::SignalingChannel` `MessageTtlSeconds`),
|
|
919
|
+
`kafka:UpdateConfiguration` (reverts an `AWS::MSK::Configuration` `ServerProperties`
|
|
920
|
+
— append-only, a new revision carrying the desired properties),
|
|
921
|
+
`logs:PutBearerTokenAuthentication` (reverts an `AWS::Logs::LogGroup`
|
|
922
|
+
`BearerTokenAuthenticationEnabled`),
|
|
923
|
+
`iam:AttachRolePolicy` / `DetachRolePolicy` / `AttachUserPolicy` /
|
|
924
|
+
`DetachUserPolicy` /
|
|
925
|
+
`AttachGroupPolicy` / `DetachGroupPolicy` / `ListEntitiesForPolicy` (revert an
|
|
926
|
+
`AWS::IAM::ManagedPolicy`'s attachments alongside the `CreatePolicyVersion` above),
|
|
927
|
+
the `lexv2models:*` write family
|
|
928
|
+
(`CreateIntent` / `UpdateIntent` / `DeleteIntent`, `CreateSlot` / `UpdateSlot` /
|
|
929
|
+
`DeleteSlot`, `CreateSlotType` / `UpdateSlotType` / `DeleteSlotType`,
|
|
930
|
+
`UpdateBotLocale` / `BuildBotLocale`, plus the `Describe*` / `List*` reads they
|
|
931
|
+
build on) to revert an `AWS::Lex::Bot` `BotLocales` drift,
|
|
932
|
+
`apigateway:PATCH` (the single IAM action API Gateway maps its update operations
|
|
933
|
+
to — reverts an `AWS::ApiGatewayV2::Stage`, where an `autoDeploy` stage rejects the
|
|
934
|
+
`DeploymentId` the Cloud Control handler injects so only the drifted stage
|
|
935
|
+
properties are written directly, and an `AWS::ApiGateway::RestApi` `Policy`, where
|
|
936
|
+
the whole desired resource policy is re-serialized and replaced since Cloud Control
|
|
937
|
+
holds the policy as a JSON string it cannot sub-path patch, and an
|
|
938
|
+
`AWS::ApiGateway::Method`'s
|
|
939
|
+
nested integration/response knobs) plus `apigateway:DELETE` (clearing a stage's
|
|
940
|
+
access-log / route settings back to unset).
|
|
877
941
|
|
|
878
942
|
</details>
|
|
879
943
|
|
package/dist/cli.js
CHANGED
|
@@ -573,11 +573,17 @@ async function loadConfig() {
|
|
|
573
573
|
}
|
|
574
574
|
let parsed;
|
|
575
575
|
const doc = parseDocument(raw, { prettyErrors: true });
|
|
576
|
-
|
|
576
|
+
const [firstError] = doc.errors;
|
|
577
|
+
if (firstError !== void 0) {
|
|
578
|
+
const more = doc.errors.length > 1 ? ` (+${doc.errors.length - 1} more)` : "";
|
|
579
|
+
throw new Error(`${CONFIG_PATH} is not valid YAML: ${firstError.message}${more}`);
|
|
580
|
+
}
|
|
577
581
|
try {
|
|
578
582
|
parsed = doc.toJS();
|
|
579
|
-
} catch {
|
|
580
|
-
|
|
583
|
+
} catch (e) {
|
|
584
|
+
const msg = e.message;
|
|
585
|
+
const hint = /alias|anchor/i.test(msg) ? " — a glob path starting with \"*\" or \"?\" must be quoted (e.g. `path: \"*.DesiredCount\"`) so it is read as a literal, not YAML alias/anchor syntax" : "";
|
|
586
|
+
throw new Error(`${CONFIG_PATH} is not valid YAML: ${msg}${hint}`);
|
|
581
587
|
}
|
|
582
588
|
if (parsed === null || parsed === void 0) return { ignore: [] };
|
|
583
589
|
if (typeof parsed !== "object" || Array.isArray(parsed)) throw new Error(`${CONFIG_PATH} must be a YAML mapping`);
|
|
@@ -1787,7 +1793,6 @@ const KNOWN_DEFAULTS = {
|
|
|
1787
1793
|
EncryptionOptions: { UseAwsOwnedKey: true },
|
|
1788
1794
|
DataReplicationMode: "NONE"
|
|
1789
1795
|
},
|
|
1790
|
-
"AWS::Chatbot::SlackChannelConfiguration": { GuardrailPolicies: ["arn:aws:iam::aws:policy/AdministratorAccess"] },
|
|
1791
1796
|
"AWS::CloudTrail::Trail": { EventSelectors: [{
|
|
1792
1797
|
IncludeManagementEvents: true,
|
|
1793
1798
|
ReadWriteType: "All",
|
|
@@ -2663,7 +2668,8 @@ const CONTEXT_ARN_DEFAULTS = {
|
|
|
2663
2668
|
"AWS::KinesisVideo::Stream": { KmsKeyId: "arn:{partition}:kms:{region}:{accountId}:alias/aws/kinesisvideo" },
|
|
2664
2669
|
"AWS::AutoScaling::AutoScalingGroup": { ServiceLinkedRoleARN: "arn:{partition}:iam::{accountId}:role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling" },
|
|
2665
2670
|
"AWS::LakeFormation::Tag": { CatalogId: "{accountId}" },
|
|
2666
|
-
"AWS::S3::AccessPoint": { BucketAccountId: "{accountId}" }
|
|
2671
|
+
"AWS::S3::AccessPoint": { BucketAccountId: "{accountId}" },
|
|
2672
|
+
"AWS::Chatbot::SlackChannelConfiguration": { GuardrailPolicies: ["arn:{partition}:iam::aws:policy/AdministratorAccess"] }
|
|
2667
2673
|
};
|
|
2668
2674
|
const ENGINE_DEFAULTS = {
|
|
2669
2675
|
"AWS::RDS::DBInstance": {
|
|
@@ -3788,6 +3794,16 @@ const TRUE_BOOL_TEST = /^(?:[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/;
|
|
|
3788
3794
|
const FALSE_BOOL_TEST = /^(?:[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/;
|
|
3789
3795
|
const BOOL_TAG = "tag:yaml.org,2002:bool";
|
|
3790
3796
|
const TIMESTAMP_TAG = "tag:yaml.org,2002:timestamp";
|
|
3797
|
+
const INT_TAG = "tag:yaml.org,2002:int";
|
|
3798
|
+
const FLOAT_TAG = "tag:yaml.org,2002:float";
|
|
3799
|
+
const EXOTIC_NUMBER_FORMATS = new Set([
|
|
3800
|
+
"OCT",
|
|
3801
|
+
"HEX",
|
|
3802
|
+
"BIN",
|
|
3803
|
+
"TIME"
|
|
3804
|
+
]);
|
|
3805
|
+
const CFN_INT_TEST = /^[-+]?(?:0|[1-9][0-9]*)$/;
|
|
3806
|
+
const CFN_FLOAT_TEST = /^[-+]?(?:(?:0|[1-9][0-9]*)(?:\.[0-9]*)?|\.[0-9]+)(?:[eE][-+]?[0-9]+)?$/;
|
|
3791
3807
|
function restrictYaml11Tags(baseTags) {
|
|
3792
3808
|
const restricted = [];
|
|
3793
3809
|
for (const tag of baseTags) {
|
|
@@ -3803,6 +3819,25 @@ function restrictYaml11Tags(baseTags) {
|
|
|
3803
3819
|
});
|
|
3804
3820
|
continue;
|
|
3805
3821
|
}
|
|
3822
|
+
if (tag.tag === INT_TAG) {
|
|
3823
|
+
const scalar = tag;
|
|
3824
|
+
if (scalar.format && EXOTIC_NUMBER_FORMATS.has(scalar.format)) continue;
|
|
3825
|
+
restricted.push({
|
|
3826
|
+
...scalar,
|
|
3827
|
+
test: CFN_INT_TEST
|
|
3828
|
+
});
|
|
3829
|
+
continue;
|
|
3830
|
+
}
|
|
3831
|
+
if (tag.tag === FLOAT_TAG) {
|
|
3832
|
+
const scalar = tag;
|
|
3833
|
+
const isNaNTag = scalar.test instanceof RegExp && scalar.test.test(".inf");
|
|
3834
|
+
if (scalar.format && EXOTIC_NUMBER_FORMATS.has(scalar.format) || isNaNTag) continue;
|
|
3835
|
+
restricted.push({
|
|
3836
|
+
...scalar,
|
|
3837
|
+
test: CFN_FLOAT_TEST
|
|
3838
|
+
});
|
|
3839
|
+
continue;
|
|
3840
|
+
}
|
|
3806
3841
|
if (tag.tag === BOOL_TAG) {
|
|
3807
3842
|
const scalar = tag;
|
|
3808
3843
|
const isTrueTag = scalar.identify?.(true) === true;
|
|
@@ -5495,9 +5530,12 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
|
|
|
5495
5530
|
}
|
|
5496
5531
|
}
|
|
5497
5532
|
const ctxArnTemplate = CONTEXT_ARN_DEFAULTS[resourceType]?.[k];
|
|
5498
|
-
if (ctxArnTemplate !== void 0 && opts.region !== void 0 && opts.accountId !== void 0
|
|
5533
|
+
if (ctxArnTemplate !== void 0 && opts.region !== void 0 && opts.accountId !== void 0) {
|
|
5499
5534
|
const partition = partitionForRegion(opts.region).partition;
|
|
5500
|
-
|
|
5535
|
+
const region = opts.region;
|
|
5536
|
+
const accountId = opts.accountId;
|
|
5537
|
+
const substitute = (t) => t.replace("{partition}", partition).replace("{region}", region).replace("{accountId}", accountId);
|
|
5538
|
+
if (Array.isArray(ctxArnTemplate) ? deepEqual(v, ctxArnTemplate.map(substitute)) : typeof v === "string" && v === substitute(ctxArnTemplate)) {
|
|
5501
5539
|
findings.push({
|
|
5502
5540
|
tier: "atDefault",
|
|
5503
5541
|
logicalId,
|
|
@@ -7132,7 +7170,8 @@ async function enumerateVpcChildren(ctx) {
|
|
|
7132
7170
|
});
|
|
7133
7171
|
}
|
|
7134
7172
|
function diffRouteTableChildren(input) {
|
|
7135
|
-
const { routeTableId, declaredCidrs, liveRoutes } = input;
|
|
7173
|
+
const { routeTableId, declaredCidrs, liveRoutes, hasUnresolvedDeclaredRoute } = input;
|
|
7174
|
+
if (hasUnresolvedDeclaredRoute) return [];
|
|
7136
7175
|
const declared = new Set(declaredCidrs);
|
|
7137
7176
|
const added = [];
|
|
7138
7177
|
for (const route of liveRoutes) {
|
|
@@ -7160,14 +7199,21 @@ async function enumerateRouteTableChildren(ctx) {
|
|
|
7160
7199
|
const routeTableId = parent.physicalId;
|
|
7161
7200
|
if (!routeTableId) return [];
|
|
7162
7201
|
const declaredCidrs = [];
|
|
7163
|
-
|
|
7202
|
+
let hasUnresolvedDeclaredRoute = false;
|
|
7203
|
+
for (const r of desired.resources) {
|
|
7204
|
+
if (r.resourceType !== "AWS::EC2::Route" || !parentRefMatches(r.declared.RouteTableId, routeTableId)) continue;
|
|
7205
|
+
const cidr = r.declared.DestinationCidrBlock;
|
|
7206
|
+
if (typeof cidr === "string") declaredCidrs.push(cidr);
|
|
7207
|
+
else if (cidr === UNRESOLVED || hasUnresolved(cidr)) hasUnresolvedDeclaredRoute = true;
|
|
7208
|
+
}
|
|
7164
7209
|
return diffRouteTableChildren({
|
|
7165
7210
|
routeTableId,
|
|
7166
7211
|
declaredCidrs,
|
|
7167
7212
|
liveRoutes: (await describeRouteTable(new EC2Client({
|
|
7168
7213
|
region,
|
|
7169
7214
|
...READ_RETRY
|
|
7170
|
-
}), routeTableId)).filter(isEnumerableRoute).map((route) => ({ cidr: route.DestinationCidrBlock }))
|
|
7215
|
+
}), routeTableId)).filter(isEnumerableRoute).map((route) => ({ cidr: route.DestinationCidrBlock })),
|
|
7216
|
+
hasUnresolvedDeclaredRoute
|
|
7171
7217
|
});
|
|
7172
7218
|
}
|
|
7173
7219
|
function diffEcsClusterChildren(input) {
|
|
@@ -7622,7 +7668,10 @@ const readLambdaPermission = async ({ declared, physicalId, region }) => {
|
|
|
7622
7668
|
region,
|
|
7623
7669
|
...READ_RETRY
|
|
7624
7670
|
}).send(new GetPolicyCommand({ FunctionName: fn }))).Policy)?.Statement ?? [];
|
|
7625
|
-
const
|
|
7671
|
+
const sid = str$1(physicalId);
|
|
7672
|
+
const byId = sid ? stmts.find((s) => s.Sid === sid) : void 0;
|
|
7673
|
+
const policyKeysBySid = stmts.some((s) => str$1(s.Sid) !== void 0);
|
|
7674
|
+
if (sid && !byId && policyKeysBySid) throw new ResourceGoneError(`Lambda Permission Sid ${sid} absent from function ${fn}'s policy`);
|
|
7626
7675
|
const want = {
|
|
7627
7676
|
action: str$1(declared.Action),
|
|
7628
7677
|
principal: str$1(declared.Principal)
|
|
@@ -9323,24 +9372,45 @@ async function fetch$1(client, resourceType) {
|
|
|
9323
9372
|
};
|
|
9324
9373
|
}
|
|
9325
9374
|
}
|
|
9375
|
+
function resolveRefNode(node, definitions) {
|
|
9376
|
+
if (!node || typeof node !== "object") return void 0;
|
|
9377
|
+
let n = node;
|
|
9378
|
+
const seen = /* @__PURE__ */ new Set();
|
|
9379
|
+
while (n?.$ref) {
|
|
9380
|
+
const name = n.$ref.replace("#/definitions/", "");
|
|
9381
|
+
if (seen.has(name)) return void 0;
|
|
9382
|
+
seen.add(name);
|
|
9383
|
+
n = definitions[name];
|
|
9384
|
+
}
|
|
9385
|
+
return n;
|
|
9386
|
+
}
|
|
9326
9387
|
function pointerToDotted$1(p) {
|
|
9327
9388
|
return p.replace(/^\/properties\//, "").replace(/\/properties\//g, "/").replace(/\/properties$/, "").replace(/\//g, ".");
|
|
9328
9389
|
}
|
|
9390
|
+
function variantBranches(node) {
|
|
9391
|
+
return [
|
|
9392
|
+
...node.oneOf ?? [],
|
|
9393
|
+
...node.anyOf ?? [],
|
|
9394
|
+
...node.allOf ?? []
|
|
9395
|
+
];
|
|
9396
|
+
}
|
|
9397
|
+
const MAX_VARIANT_DEPTH = 30;
|
|
9329
9398
|
function collectDefaultPaths(definitions, properties) {
|
|
9330
9399
|
const out = {};
|
|
9331
|
-
const walk = (node, path, seen) => {
|
|
9332
|
-
if (!node || typeof node !== "object") return;
|
|
9400
|
+
const walk = (node, path, seen, depth) => {
|
|
9401
|
+
if (!node || typeof node !== "object" || depth > MAX_VARIANT_DEPTH) return;
|
|
9333
9402
|
if (node.$ref) {
|
|
9334
9403
|
const name = node.$ref.replace("#/definitions/", "");
|
|
9335
9404
|
if (seen.has(name)) return;
|
|
9336
|
-
walk(definitions[name], path, new Set(seen).add(name));
|
|
9405
|
+
walk(definitions[name], path, new Set(seen).add(name), depth);
|
|
9337
9406
|
return;
|
|
9338
9407
|
}
|
|
9339
9408
|
if ("default" in node && path) out[path] = node.default;
|
|
9340
|
-
if (node.properties) for (const [k, child] of Object.entries(node.properties)) walk(child, path ? `${path}.${k}` : k, seen);
|
|
9341
|
-
if (node.items) walk(node.items, path ? `${path}.*` : "*", seen);
|
|
9409
|
+
if (node.properties) for (const [k, child] of Object.entries(node.properties)) walk(child, path ? `${path}.${k}` : k, seen, depth);
|
|
9410
|
+
if (node.items) walk(node.items, path ? `${path}.*` : "*", seen, depth);
|
|
9411
|
+
for (const branch of variantBranches(node)) walk(branch, path, seen, depth + 1);
|
|
9342
9412
|
};
|
|
9343
|
-
for (const [k, child] of Object.entries(properties)) walk(child, k, /* @__PURE__ */ new Set());
|
|
9413
|
+
for (const [k, child] of Object.entries(properties)) walk(child, k, /* @__PURE__ */ new Set(), 0);
|
|
9344
9414
|
return out;
|
|
9345
9415
|
}
|
|
9346
9416
|
const SCALAR_TYPES = new Set([
|
|
@@ -9382,7 +9452,8 @@ function collectUnorderedArrayPaths(definitions, properties) {
|
|
|
9382
9452
|
if (propKeys.length === 0) return false;
|
|
9383
9453
|
return !propKeys.some((k) => ITEM_IDENTITY_FIELDS.includes(k));
|
|
9384
9454
|
};
|
|
9385
|
-
const walk = (node, path, seen) => {
|
|
9455
|
+
const walk = (node, path, seen, depth) => {
|
|
9456
|
+
if (depth > MAX_VARIANT_DEPTH) return;
|
|
9386
9457
|
const n = resolve(node, seen);
|
|
9387
9458
|
if (!n) return;
|
|
9388
9459
|
const nextSeen = node?.$ref ? new Set(seen).add(node.$ref.replace("#/definitions/", "")) : seen;
|
|
@@ -9392,11 +9463,12 @@ function collectUnorderedArrayPaths(definitions, properties) {
|
|
|
9392
9463
|
if (isScalarItems(it)) scalar.push(path);
|
|
9393
9464
|
else if (isNonIdentityObjectItems(it)) object.push(path);
|
|
9394
9465
|
}
|
|
9395
|
-
if (n.items) walk(n.items, path ? `${path}.*` : "*", nextSeen);
|
|
9466
|
+
if (n.items) walk(n.items, path ? `${path}.*` : "*", nextSeen, depth);
|
|
9396
9467
|
}
|
|
9397
|
-
if (n.properties) for (const [k, child] of Object.entries(n.properties)) walk(child, path ? `${path}.${k}` : k, nextSeen);
|
|
9468
|
+
if (n.properties) for (const [k, child] of Object.entries(n.properties)) walk(child, path ? `${path}.${k}` : k, nextSeen, depth);
|
|
9469
|
+
for (const branch of variantBranches(n)) walk(branch, path, nextSeen, depth + 1);
|
|
9398
9470
|
};
|
|
9399
|
-
for (const [k, child] of Object.entries(properties)) walk(child, k, /* @__PURE__ */ new Set());
|
|
9471
|
+
for (const [k, child] of Object.entries(properties)) walk(child, k, /* @__PURE__ */ new Set(), 0);
|
|
9400
9472
|
return {
|
|
9401
9473
|
scalar: [...new Set(scalar)].sort(),
|
|
9402
9474
|
object: [...new Set(object)].sort()
|
|
@@ -9405,22 +9477,23 @@ function collectUnorderedArrayPaths(definitions, properties) {
|
|
|
9405
9477
|
function collectFreeFormMapPaths(definitions, properties) {
|
|
9406
9478
|
const out = [];
|
|
9407
9479
|
const isObjectSchema = (v) => typeof v === "object" && v !== null;
|
|
9408
|
-
const walk = (node, path, seen) => {
|
|
9409
|
-
if (!node || typeof node !== "object") return;
|
|
9480
|
+
const walk = (node, path, seen, depth) => {
|
|
9481
|
+
if (!node || typeof node !== "object" || depth > MAX_VARIANT_DEPTH) return;
|
|
9410
9482
|
if (node.$ref) {
|
|
9411
9483
|
const name = node.$ref.replace("#/definitions/", "");
|
|
9412
9484
|
if (seen.has(name)) return;
|
|
9413
|
-
walk(definitions[name], path, new Set(seen).add(name));
|
|
9485
|
+
walk(definitions[name], path, new Set(seen).add(name), depth);
|
|
9414
9486
|
return;
|
|
9415
9487
|
}
|
|
9416
9488
|
const hasFixedProps = node.properties && Object.keys(node.properties).length > 0;
|
|
9417
9489
|
const isMap = node.type === "object" && !hasFixedProps && (node.patternProperties && Object.keys(node.patternProperties).length > 0 || isObjectSchema(node.additionalProperties));
|
|
9418
9490
|
const lastSeg = path.split(".").at(-1);
|
|
9419
9491
|
if (isMap && path && lastSeg !== "Tags") out.push(path);
|
|
9420
|
-
if (node.properties) for (const [k, child] of Object.entries(node.properties)) walk(child, path ? `${path}.${k}` : k, seen);
|
|
9421
|
-
if (node.items) walk(node.items, path ? `${path}.*` : "*", seen);
|
|
9492
|
+
if (node.properties) for (const [k, child] of Object.entries(node.properties)) walk(child, path ? `${path}.${k}` : k, seen, depth);
|
|
9493
|
+
if (node.items) walk(node.items, path ? `${path}.*` : "*", seen, depth);
|
|
9494
|
+
for (const branch of variantBranches(node)) walk(branch, path, seen, depth + 1);
|
|
9422
9495
|
};
|
|
9423
|
-
for (const [k, child] of Object.entries(properties)) walk(child, k, /* @__PURE__ */ new Set());
|
|
9496
|
+
for (const [k, child] of Object.entries(properties)) walk(child, k, /* @__PURE__ */ new Set(), 0);
|
|
9424
9497
|
return [...new Set(out)].sort();
|
|
9425
9498
|
}
|
|
9426
9499
|
/** Exported for unit testing without an AWS call. */
|
|
@@ -9431,11 +9504,15 @@ function parseSchema(schemaJson) {
|
|
|
9431
9504
|
const readOnlyPaths = dotted(schema.readOnlyProperties);
|
|
9432
9505
|
const writeOnlyPaths = dotted(schema.writeOnlyProperties);
|
|
9433
9506
|
const createOnlyPaths = dotted(schema.createOnlyProperties);
|
|
9507
|
+
const definitions = schema.definitions ?? {};
|
|
9434
9508
|
const defaults = {};
|
|
9435
|
-
for (const [k, def] of Object.entries(schema.properties ?? {}))
|
|
9436
|
-
|
|
9437
|
-
|
|
9438
|
-
|
|
9509
|
+
for (const [k, def] of Object.entries(schema.properties ?? {})) {
|
|
9510
|
+
const resolved = resolveRefNode(def, definitions);
|
|
9511
|
+
if (resolved && "default" in resolved) defaults[k] = resolved.default;
|
|
9512
|
+
}
|
|
9513
|
+
const defaultPaths = collectDefaultPaths(definitions, schema.properties ?? {});
|
|
9514
|
+
const unorderedArrayPaths = collectUnorderedArrayPaths(definitions, schema.properties ?? {});
|
|
9515
|
+
const freeFormMapPaths = collectFreeFormMapPaths(definitions, schema.properties ?? {});
|
|
9439
9516
|
const updatable = schema.handlers === void 0 ? void 0 : Object.hasOwn(schema.handlers, "update");
|
|
9440
9517
|
const propertyTransforms = {};
|
|
9441
9518
|
for (const [ptr, expr] of Object.entries(schema.propertyTransform ?? {})) if (typeof expr === "string") propertyTransforms[pointerToDotted$1(ptr)] = expr;
|
|
@@ -10042,6 +10119,7 @@ async function loadBaseline(stackName, accountId, region) {
|
|
|
10042
10119
|
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`);
|
|
10043
10120
|
if (!Array.isArray(parsed.recorded)) throw new Error(`baseline file ${path} is malformed: \`recorded\` is missing or not an array`);
|
|
10044
10121
|
parsed.recorded.forEach((entry, i) => validateRecordedEntry(entry, i, path));
|
|
10122
|
+
validateRecordedUniqueness(parsed.recorded, path);
|
|
10045
10123
|
validateCompleteResources(parsed.completeResources, path);
|
|
10046
10124
|
validateRecordedPhysicalIds(parsed.recordedPhysicalIds, path);
|
|
10047
10125
|
return parsed;
|
|
@@ -10066,6 +10144,34 @@ function validateRecordedEntry(entry, index, path) {
|
|
|
10066
10144
|
]) if (typeof obj[k] !== "string") throw new Error(`${at}: "${k}" is required and must be a string`);
|
|
10067
10145
|
}
|
|
10068
10146
|
/**
|
|
10147
|
+
* #1047: reject duplicate `recorded` identity keys at load. The baseline is git-committed,
|
|
10148
|
+
* hand-editable, and merge-conflictable, so a bad merge / hand-edit can leave TWO entries
|
|
10149
|
+
* sharing the SAME identity — `(logicalId, path, resourceType)` — with DIFFERENT values. The
|
|
10150
|
+
* #794 shape validation above proves each element is well-FORMED but never cross-checks
|
|
10151
|
+
* identity, so such a file loads cleanly and then misbehaves: every match site
|
|
10152
|
+
* (`recorded.find(...)` in applyBaseline / splitRecordedByBaseline) silently first-wins — so
|
|
10153
|
+
* if LIVE equals the SECOND duplicate the finding is NOT suppressed and false-surfaces as
|
|
10154
|
+
* confirmed drift — AND the removed-since-record loop iterates ALL entries, emitting TWO
|
|
10155
|
+
* identical "baseline value removed since record" findings for the one path (an inflated
|
|
10156
|
+
* drift count). The identity here is exactly the one the match sites compare on (see
|
|
10157
|
+
* `entryMatches` / splitRecordedByBaseline's `.find`), so a collision is genuinely
|
|
10158
|
+
* ambiguous — the file is corrupt. Fail LOUDLY (naming the duplicated identity) rather than
|
|
10159
|
+
* silently pick the first, mirroring #794's loud-vs-silent principle. Entries are all
|
|
10160
|
+
* shape-validated by this point, so `logicalId`/`resourceType`/`path` are known strings.
|
|
10161
|
+
*/
|
|
10162
|
+
function validateRecordedUniqueness(recorded, path) {
|
|
10163
|
+
const seen = /* @__PURE__ */ new Set();
|
|
10164
|
+
recorded.forEach((entry, i) => {
|
|
10165
|
+
const key = JSON.stringify([
|
|
10166
|
+
entry.logicalId,
|
|
10167
|
+
entry.path,
|
|
10168
|
+
entry.resourceType
|
|
10169
|
+
]);
|
|
10170
|
+
if (seen.has(key)) throw new Error(`baseline file ${path}: \`recorded\`[${i}] is a duplicate of an earlier entry with the same identity (logicalId=${JSON.stringify(entry.logicalId)}, path=${JSON.stringify(entry.path)}, resourceType=${JSON.stringify(entry.resourceType)}). Two recorded entries with the same identity are ambiguous (a bad merge or hand-edit) — remove the stale one, or restore the correct file from git.`);
|
|
10171
|
+
seen.add(key);
|
|
10172
|
+
});
|
|
10173
|
+
}
|
|
10174
|
+
/**
|
|
10069
10175
|
* #794: validate `completeResources` (optional; absent on v1 files). When present it must
|
|
10070
10176
|
* be an array of strings — a bare string would have `new Set(...)` iterate its CHARACTERS
|
|
10071
10177
|
* (silently mis-scoping completeness), and a number would crash with an opaque
|
|
@@ -14315,10 +14421,15 @@ function sanitizeForTerminal(s) {
|
|
|
14315
14421
|
let out = "";
|
|
14316
14422
|
for (const ch of s) {
|
|
14317
14423
|
const code = ch.charCodeAt(0);
|
|
14318
|
-
|
|
14424
|
+
if (code < 32 || code === 127) out += `\\x${code.toString(16).padStart(2, "0")}`;
|
|
14425
|
+
else if (isBidiOrZeroWidth(code)) out += `\\u{${code.toString(16).toUpperCase()}}`;
|
|
14426
|
+
else out += ch;
|
|
14319
14427
|
}
|
|
14320
14428
|
return out;
|
|
14321
14429
|
}
|
|
14430
|
+
function isBidiOrZeroWidth(code) {
|
|
14431
|
+
return code >= 8234 && code <= 8238 || code >= 8294 && code <= 8297 || code >= 8203 && code <= 8207 || code === 65279;
|
|
14432
|
+
}
|
|
14322
14433
|
function jPair(a, b) {
|
|
14323
14434
|
const as = JSON.stringify(a) ?? String(a);
|
|
14324
14435
|
const bs = JSON.stringify(b) ?? String(b);
|
|
@@ -14927,6 +15038,23 @@ function hasBaselineForStack(stackName, region) {
|
|
|
14927
15038
|
return lower.startsWith(prefix) && lower.endsWith(suffix);
|
|
14928
15039
|
});
|
|
14929
15040
|
}
|
|
15041
|
+
function safeStringifyJson(value) {
|
|
15042
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
15043
|
+
const replacer = (_key, v) => {
|
|
15044
|
+
if (typeof v === "bigint") return v.toString();
|
|
15045
|
+
if (typeof v === "object" && v !== null) {
|
|
15046
|
+
if (seen.has(v)) return "[Circular]";
|
|
15047
|
+
seen.add(v);
|
|
15048
|
+
}
|
|
15049
|
+
return v;
|
|
15050
|
+
};
|
|
15051
|
+
try {
|
|
15052
|
+
return JSON.stringify(value, replacer, 2);
|
|
15053
|
+
} catch (e) {
|
|
15054
|
+
console.error(`error: could not serialize --json output: ${e.message} — emitting [] instead`);
|
|
15055
|
+
return "[]";
|
|
15056
|
+
}
|
|
15057
|
+
}
|
|
14930
15058
|
async function runCheck(args) {
|
|
14931
15059
|
const a = parseCommonArgs(args, "check");
|
|
14932
15060
|
if (a.profile) process.env.AWS_PROFILE = a.profile;
|
|
@@ -15135,7 +15263,7 @@ async function runCheck(args) {
|
|
|
15135
15263
|
worst = Math.max(worst, 2);
|
|
15136
15264
|
}
|
|
15137
15265
|
}
|
|
15138
|
-
if (a.json) console.log(
|
|
15266
|
+
if (a.json) console.log(safeStringifyJson(jsonReports));
|
|
15139
15267
|
if (anyDrift && !a.fail && !a.json) console.error("note: drift found — exit 0 (report-only). Pass --fail to make drift fail this command.");
|
|
15140
15268
|
return worst;
|
|
15141
15269
|
}
|