cdk-real-drift 0.8.0 → 0.9.1
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 +8 -2
- package/dist/cli.js +133 -26
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -283,7 +283,7 @@ snapshots its full live model and watches it, `ignore` accepts it, or `revert`
|
|
|
283
283
|
- **AppSync**: data sources, resolvers, functions
|
|
284
284
|
- **CloudWatch Logs**: metric filters, subscription filters
|
|
285
285
|
- **ELBv2**: listeners, listener rules
|
|
286
|
-
- **EC2**: VPC subnets, route table routes
|
|
286
|
+
- **EC2**: VPC subnets, VPC endpoints, route table routes
|
|
287
287
|
- **ECS**: cluster services
|
|
288
288
|
- **KMS**: key aliases
|
|
289
289
|
- **AppConfig**: application environments, configuration profiles
|
|
@@ -831,7 +831,13 @@ covers them. **If you never run `revert`, cdkrd needs no write permissions at al
|
|
|
831
831
|
`glue:GetClassifier` + `glue:GetWorkflow` + `glue:GetConnection`
|
|
832
832
|
(`glue:GetConnection` is issued with `HidePassword` so NO credential enters the
|
|
833
833
|
baseline — read an `AWS::Glue::Classifier` / `Workflow` / `Connection`, the rest
|
|
834
|
-
of the Glue family that has no Cloud Control handler)
|
|
834
|
+
of the Glue family that has no Cloud Control handler),
|
|
835
|
+
`rds:DescribeOptionGroupOptions` (reads an `AWS::RDS::OptionGroup`'s option-default
|
|
836
|
+
catalog — the `DefaultValue` AWS materializes for every plugin setting the template
|
|
837
|
+
did not declare — so the service default-fill folds to `atDefault` instead of
|
|
838
|
+
flooding a clean first check with undeclared settings; equality-gated, so an
|
|
839
|
+
out-of-band setting change is still detected. Without the permission cdkrd warns
|
|
840
|
+
once and those default-fill settings surface as first-run drift)
|
|
835
841
|
- Optional: `elasticloadbalancing:GetTrustStoreCaCertificatesBundle` records a
|
|
836
842
|
content hash of an `AWS::ElasticLoadBalancingV2::TrustStore`'s live mTLS CA
|
|
837
843
|
bundle (`CaCertificatesBundleSha256`) so an out-of-band CA-bundle swap
|
package/dist/cli.js
CHANGED
|
@@ -8,6 +8,7 @@ import { CloudControlClient, DeleteResourceCommand, GetResourceCommand, GetResou
|
|
|
8
8
|
import { homedir } from "node:os";
|
|
9
9
|
import { BaseCredentials, CdkAppMultiContext, NonInteractiveIoHost, StackSelectionStrategy, Toolkit } from "@aws-cdk/toolkit-lib";
|
|
10
10
|
import { CloudFormationClient, DescribeStackResourcesCommand, DescribeStacksCommand, DescribeTypeCommand, GetTemplateCommand, ListExportsCommand, ListStackResourcesCommand } from "@aws-sdk/client-cloudformation";
|
|
11
|
+
import { DescribeDBClustersCommand, DescribeDBInstancesCommand, DescribeOptionGroupOptionsCommand, RDSClient } from "@aws-sdk/client-rds";
|
|
11
12
|
import jsonata from "jsonata";
|
|
12
13
|
import { KMSClient, ListAliasesCommand } from "@aws-sdk/client-kms";
|
|
13
14
|
import { createCredentialChain, fromEnv, fromNodeProviderChain } from "@aws-sdk/credential-providers";
|
|
@@ -17,13 +18,12 @@ import { AppSyncClient, ListApiKeysCommand, ListDataSourcesCommand, ListFunction
|
|
|
17
18
|
import { ApiGatewayV2Client, DeleteAccessLogSettingsCommand, DeleteRouteSettingsCommand, GetAuthorizersCommand as GetAuthorizersCommand$1, GetIntegrationsCommand, GetRoutesCommand, GetStagesCommand as GetStagesCommand$1, UpdateStageCommand } from "@aws-sdk/client-apigatewayv2";
|
|
18
19
|
import { CloudWatchLogsClient, DescribeMetricFiltersCommand, DescribeSubscriptionFiltersCommand, PutBearerTokenAuthenticationCommand, PutMetricFilterCommand } from "@aws-sdk/client-cloudwatch-logs";
|
|
19
20
|
import { CognitoIdentityProviderClient, ListGroupsCommand, ListResourceServersCommand, ListUserPoolClientsCommand } from "@aws-sdk/client-cognito-identity-provider";
|
|
20
|
-
import { DescribeAddressesCommand, DescribeClientVpnAuthorizationRulesCommand, DescribeClientVpnEndpointsCommand, DescribeClientVpnTargetNetworksCommand, DescribeLaunchTemplateVersionsCommand, DescribeNetworkAclsCommand, DescribeRouteTablesCommand, DescribeSubnetsCommand, EC2Client, ModifyClientVpnEndpointCommand } from "@aws-sdk/client-ec2";
|
|
21
|
+
import { DescribeAddressesCommand, DescribeClientVpnAuthorizationRulesCommand, DescribeClientVpnEndpointsCommand, DescribeClientVpnTargetNetworksCommand, DescribeLaunchTemplateVersionsCommand, DescribeNetworkAclsCommand, DescribeRouteTablesCommand, DescribeSubnetsCommand, DescribeVpcEndpointsCommand, EC2Client, ModifyClientVpnEndpointCommand } from "@aws-sdk/client-ec2";
|
|
21
22
|
import { DescribeServicesCommand, ECSClient, ListServicesCommand, UpdateServiceCommand } from "@aws-sdk/client-ecs";
|
|
22
23
|
import { DescribeMountTargetsCommand, EFSClient } from "@aws-sdk/client-efs";
|
|
23
24
|
import { DescribeListenersCommand, DescribeRulesCommand, ElasticLoadBalancingV2Client, GetTrustStoreCaCertificatesBundleCommand, ModifyLoadBalancerAttributesCommand, ModifyTargetGroupAttributesCommand } from "@aws-sdk/client-elastic-load-balancing-v2";
|
|
24
25
|
import { DescribeEventBusCommand, EventBridgeClient, ListRulesCommand, PutPermissionCommand } from "@aws-sdk/client-eventbridge";
|
|
25
26
|
import { GetPolicyCommand, LambdaClient, ListAliasesCommand as ListAliasesCommand$1, ListEventSourceMappingsCommand, ListFunctionUrlConfigsCommand, ListVersionsByFunctionCommand } from "@aws-sdk/client-lambda";
|
|
26
|
-
import { DescribeDBClustersCommand, DescribeDBInstancesCommand, RDSClient } from "@aws-sdk/client-rds";
|
|
27
27
|
import { ChangeResourceRecordSetsCommand, ListResourceRecordSetsCommand, Route53Client } from "@aws-sdk/client-route-53";
|
|
28
28
|
import { GetTopicAttributesCommand, ListSubscriptionsByTopicCommand, SNSClient, SetTopicAttributesCommand } from "@aws-sdk/client-sns";
|
|
29
29
|
import { ACMClient, DescribeCertificateCommand, ListTagsForCertificateCommand } from "@aws-sdk/client-acm";
|
|
@@ -1634,6 +1634,7 @@ function buildCorpusCase(resource, liveRaw, schema, opts, findings) {
|
|
|
1634
1634
|
const sgSibling = resource.resourceType === "AWS::EC2::SecurityGroup" && resource.physicalId ? opts.siblingSgRules?.[resource.physicalId] : void 0;
|
|
1635
1635
|
const bucketNotif = resource.physicalId && opts.bucketNotificationManaged?.has(resource.physicalId) ? [resource.physicalId] : void 0;
|
|
1636
1636
|
const echoModel = resource.physicalId && opts.clusterEchoModel?.[resource.physicalId] ? opts.clusterEchoModel[resource.physicalId] : void 0;
|
|
1637
|
+
const rdsOptCatalog = resource.physicalId && opts.rdsOptionSettingDefaults?.[resource.physicalId] ? opts.rdsOptionSettingDefaults[resource.physicalId] : void 0;
|
|
1637
1638
|
return sanitizeAccountId({
|
|
1638
1639
|
corpusVersion: 1,
|
|
1639
1640
|
resource: {
|
|
@@ -1665,7 +1666,8 @@ function buildCorpusCase(resource, liveRaw, schema, opts, findings) {
|
|
|
1665
1666
|
oaiCanonicalIds: opts.oaiCanonicalIds,
|
|
1666
1667
|
...sgSibling && resource.physicalId ? { siblingSgRules: { [resource.physicalId]: sgSibling } } : {},
|
|
1667
1668
|
...bucketNotif ? { bucketNotificationManaged: bucketNotif } : {},
|
|
1668
|
-
...echoModel && resource.physicalId ? { clusterEchoModel: { [resource.physicalId]: echoModel } } : {}
|
|
1669
|
+
...echoModel && resource.physicalId ? { clusterEchoModel: { [resource.physicalId]: echoModel } } : {},
|
|
1670
|
+
...rdsOptCatalog && resource.physicalId ? { rdsOptionSettingDefaults: { [resource.physicalId]: rdsOptCatalog } } : {}
|
|
1669
1671
|
},
|
|
1670
1672
|
expected: findings
|
|
1671
1673
|
}, opts.accountId);
|
|
@@ -2978,7 +2980,11 @@ const VALUE_INDEPENDENT_DEFAULT_TOPLEVEL_PATHS = {
|
|
|
2978
2980
|
"AWS::EC2::SecurityGroupEgress": new Set(["DestinationSecurityGroupName"]),
|
|
2979
2981
|
"AWS::DocDB::DBCluster": new Set(["PreferredMaintenanceWindow", "PreferredBackupWindow"]),
|
|
2980
2982
|
"AWS::DocDB::DBInstance": new Set(["PreferredMaintenanceWindow"]),
|
|
2981
|
-
"AWS::Neptune::DBCluster": new Set([
|
|
2983
|
+
"AWS::Neptune::DBCluster": new Set([
|
|
2984
|
+
"PreferredMaintenanceWindow",
|
|
2985
|
+
"PreferredBackupWindow",
|
|
2986
|
+
"EngineVersion"
|
|
2987
|
+
]),
|
|
2982
2988
|
"AWS::Neptune::DBInstance": new Set(["PreferredMaintenanceWindow", "AvailabilityZone"]),
|
|
2983
2989
|
"AWS::ElastiCache::CacheCluster": new Set([
|
|
2984
2990
|
"PreferredMaintenanceWindow",
|
|
@@ -5077,18 +5083,18 @@ function isSelfEchoTrivialEmpty(v, physicalId) {
|
|
|
5077
5083
|
const rest = entries.filter(([, val]) => val !== physicalId);
|
|
5078
5084
|
return rest.length < entries.length && rest.every(([, val]) => isTrivialEmpty(val));
|
|
5079
5085
|
}
|
|
5080
|
-
const RDS_OPTION_SETTING_DEFAULTS = {
|
|
5081
|
-
SERVER_AUDIT: "FORCE_PLUS_PERMANENT",
|
|
5082
|
-
SERVER_AUDIT_LOGGING: "ON",
|
|
5083
|
-
SERVER_AUDIT_FILE_PATH: "/rdsdbdata/log/audit/"
|
|
5084
|
-
};
|
|
5085
5086
|
function isIdentityOnlyHusk(el, idField) {
|
|
5086
5087
|
return Object.entries(el).every(([k, v]) => k === idField || isTrivialEmpty(v));
|
|
5087
5088
|
}
|
|
5088
|
-
function
|
|
5089
|
-
if (
|
|
5090
|
-
|
|
5091
|
-
|
|
5089
|
+
function rdsMaterializedDefault(catalog, physicalId, declared, path, settingName) {
|
|
5090
|
+
if (!catalog || physicalId === void 0) return void 0;
|
|
5091
|
+
const m = /OptionConfigurations\.(\d+)\.OptionSettings$/.exec(path);
|
|
5092
|
+
if (!m) return void 0;
|
|
5093
|
+
const configs = declared?.OptionConfigurations;
|
|
5094
|
+
const optName = Array.isArray(configs) ? configs[Number(m[1])]?.OptionName : void 0;
|
|
5095
|
+
if (typeof optName !== "string") return void 0;
|
|
5096
|
+
const perOption = catalog[physicalId]?.[optName];
|
|
5097
|
+
return perOption && settingName in perOption ? perOption[settingName] : void 0;
|
|
5092
5098
|
}
|
|
5093
5099
|
function isEmptyPolicyShell(v) {
|
|
5094
5100
|
if (v === null || typeof v !== "object" || Array.isArray(v)) return false;
|
|
@@ -5785,7 +5791,12 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
|
|
|
5785
5791
|
const loName = String(loRec[nvSubsetSpec.nameField]);
|
|
5786
5792
|
const loValue = loRec[nvSubsetSpec.valueField];
|
|
5787
5793
|
const isFirehoseRetriesDefault = resourceType === "AWS::KinesisFirehose::DeliveryStream" && loName === "NumberOfRetries" && loValue === "3";
|
|
5788
|
-
|
|
5794
|
+
let isRdsOptionDefault = false;
|
|
5795
|
+
if (resourceType === "AWS::RDS::OptionGroup") if (isIdentityOnlyHusk(loRec, nvSubsetSpec.nameField)) isRdsOptionDefault = true;
|
|
5796
|
+
else {
|
|
5797
|
+
const matDefault = rdsMaterializedDefault(opts.rdsOptionSettingDefaults, physicalId, declaredIn, d.path, loName);
|
|
5798
|
+
isRdsOptionDefault = matDefault != null && matDefault === loValue;
|
|
5799
|
+
}
|
|
5789
5800
|
findings.push({
|
|
5790
5801
|
tier: isFirehoseRetriesDefault || isRdsOptionDefault ? "atDefault" : "undeclared",
|
|
5791
5802
|
logicalId,
|
|
@@ -7433,6 +7444,20 @@ function diffVpcChildren(input) {
|
|
|
7433
7444
|
}
|
|
7434
7445
|
return added;
|
|
7435
7446
|
}
|
|
7447
|
+
function diffVpcEndpointChildren(input) {
|
|
7448
|
+
const declared = new Set(input.declaredEndpointIds);
|
|
7449
|
+
const added = [];
|
|
7450
|
+
for (const e of input.liveEndpoints) {
|
|
7451
|
+
if (declared.has(e.id)) continue;
|
|
7452
|
+
added.push({
|
|
7453
|
+
resourceType: "AWS::EC2::VPCEndpoint",
|
|
7454
|
+
identifier: e.id,
|
|
7455
|
+
label: e.label ?? e.id,
|
|
7456
|
+
live: { Id: e.id }
|
|
7457
|
+
});
|
|
7458
|
+
}
|
|
7459
|
+
return added;
|
|
7460
|
+
}
|
|
7436
7461
|
async function pageSubnets(client, vpcId) {
|
|
7437
7462
|
const out = [];
|
|
7438
7463
|
let next;
|
|
@@ -7449,22 +7474,52 @@ async function pageSubnets(client, vpcId) {
|
|
|
7449
7474
|
} while (next);
|
|
7450
7475
|
return out;
|
|
7451
7476
|
}
|
|
7477
|
+
async function pageVpcEndpoints(client, vpcId) {
|
|
7478
|
+
const out = [];
|
|
7479
|
+
let next;
|
|
7480
|
+
do {
|
|
7481
|
+
const res = await client.send(new DescribeVpcEndpointsCommand({
|
|
7482
|
+
Filters: [{
|
|
7483
|
+
Name: "vpc-id",
|
|
7484
|
+
Values: [vpcId]
|
|
7485
|
+
}],
|
|
7486
|
+
NextToken: next
|
|
7487
|
+
}));
|
|
7488
|
+
out.push(...res.VpcEndpoints ?? []);
|
|
7489
|
+
next = res.NextToken;
|
|
7490
|
+
} while (next);
|
|
7491
|
+
return out;
|
|
7492
|
+
}
|
|
7452
7493
|
async function enumerateVpcChildren(ctx) {
|
|
7453
7494
|
const { parent, desired, region } = ctx;
|
|
7454
7495
|
const vpcId = parent.physicalId;
|
|
7455
7496
|
if (!vpcId) return [];
|
|
7456
7497
|
const declaredSubnetIds = [];
|
|
7457
|
-
|
|
7458
|
-
|
|
7459
|
-
|
|
7460
|
-
|
|
7461
|
-
|
|
7462
|
-
|
|
7463
|
-
|
|
7464
|
-
|
|
7465
|
-
|
|
7466
|
-
}))
|
|
7498
|
+
const declaredEndpointIds = [];
|
|
7499
|
+
for (const r of desired.resources) {
|
|
7500
|
+
if (!parentRefMatches(r.declared.VpcId, vpcId) || !r.physicalId) continue;
|
|
7501
|
+
if (r.resourceType === "AWS::EC2::Subnet") declaredSubnetIds.push(r.physicalId);
|
|
7502
|
+
else if (r.resourceType === "AWS::EC2::VPCEndpoint") declaredEndpointIds.push(r.physicalId);
|
|
7503
|
+
}
|
|
7504
|
+
const client = new EC2Client({
|
|
7505
|
+
region,
|
|
7506
|
+
...READ_RETRY
|
|
7467
7507
|
});
|
|
7508
|
+
const liveSubnets = (await pageSubnets(client, vpcId)).filter((s) => typeof s.SubnetId === "string").map((s) => ({
|
|
7509
|
+
id: s.SubnetId,
|
|
7510
|
+
label: s.CidrBlock ? `${s.CidrBlock}` : s.SubnetId
|
|
7511
|
+
}));
|
|
7512
|
+
const liveEndpoints = (await pageVpcEndpoints(client, vpcId)).filter((e) => typeof e.VpcEndpointId === "string").map((e) => ({
|
|
7513
|
+
id: e.VpcEndpointId,
|
|
7514
|
+
label: e.ServiceName ?? e.VpcEndpointId
|
|
7515
|
+
}));
|
|
7516
|
+
return [...diffVpcChildren({
|
|
7517
|
+
declaredSubnetIds,
|
|
7518
|
+
liveSubnets
|
|
7519
|
+
}), ...diffVpcEndpointChildren({
|
|
7520
|
+
declaredEndpointIds,
|
|
7521
|
+
liveEndpoints
|
|
7522
|
+
})];
|
|
7468
7523
|
}
|
|
7469
7524
|
function diffRouteTableChildren(input) {
|
|
7470
7525
|
const { routeTableId, declaredCidrs, liveRoutes, hasUnresolvedDeclaredRoute } = input;
|
|
@@ -10456,6 +10511,56 @@ function buildClusterEchoModels(desired) {
|
|
|
10456
10511
|
}
|
|
10457
10512
|
return map;
|
|
10458
10513
|
}
|
|
10514
|
+
async function buildRdsOptionSettingDefaults(desired, region) {
|
|
10515
|
+
const groups = desired.resources.filter((r) => r.resourceType === "AWS::RDS::OptionGroup" && r.physicalId);
|
|
10516
|
+
if (groups.length === 0) return {};
|
|
10517
|
+
const client = new RDSClient({
|
|
10518
|
+
region,
|
|
10519
|
+
...READ_RETRY
|
|
10520
|
+
});
|
|
10521
|
+
const catalogCache = /* @__PURE__ */ new Map();
|
|
10522
|
+
const out = {};
|
|
10523
|
+
let warned = false;
|
|
10524
|
+
for (const r of groups) {
|
|
10525
|
+
const decl = r.declared;
|
|
10526
|
+
const engine = typeof decl?.EngineName === "string" ? decl.EngineName : void 0;
|
|
10527
|
+
const version = decl?.MajorEngineVersion != null ? String(decl.MajorEngineVersion) : void 0;
|
|
10528
|
+
if (!engine || !version || !r.physicalId) continue;
|
|
10529
|
+
const key = `${engine}:${version}`;
|
|
10530
|
+
let catalog = catalogCache.get(key);
|
|
10531
|
+
if (!catalog) try {
|
|
10532
|
+
catalog = await fetchOptionCatalog(client, engine, version);
|
|
10533
|
+
catalogCache.set(key, catalog);
|
|
10534
|
+
} catch (e) {
|
|
10535
|
+
if (!warned) {
|
|
10536
|
+
console.error(`warning: describe-option-group-options failed for ${engine} ${version} (${e.name}) — RDS OptionGroup default-fill settings may surface as first-run drift; grant rds:DescribeOptionGroupOptions`);
|
|
10537
|
+
warned = true;
|
|
10538
|
+
}
|
|
10539
|
+
continue;
|
|
10540
|
+
}
|
|
10541
|
+
out[r.physicalId] = catalog;
|
|
10542
|
+
}
|
|
10543
|
+
return out;
|
|
10544
|
+
}
|
|
10545
|
+
async function fetchOptionCatalog(client, engineName, majorEngineVersion) {
|
|
10546
|
+
const catalog = {};
|
|
10547
|
+
let marker;
|
|
10548
|
+
do {
|
|
10549
|
+
const resp = await client.send(new DescribeOptionGroupOptionsCommand({
|
|
10550
|
+
EngineName: engineName,
|
|
10551
|
+
MajorEngineVersion: majorEngineVersion,
|
|
10552
|
+
Marker: marker
|
|
10553
|
+
}));
|
|
10554
|
+
for (const opt of resp.OptionGroupOptions ?? []) {
|
|
10555
|
+
if (!opt.Name) continue;
|
|
10556
|
+
const settings = catalog[opt.Name] ?? {};
|
|
10557
|
+
for (const s of opt.OptionGroupOptionSettings ?? []) if (s.SettingName) settings[s.SettingName] = s.DefaultValue ?? null;
|
|
10558
|
+
catalog[opt.Name] = settings;
|
|
10559
|
+
}
|
|
10560
|
+
marker = resp.Marker;
|
|
10561
|
+
} while (marker);
|
|
10562
|
+
return catalog;
|
|
10563
|
+
}
|
|
10459
10564
|
const OAI_TYPE = "AWS::CloudFront::CloudFrontOriginAccessIdentity";
|
|
10460
10565
|
function buildOaiCanonicalIds(desired) {
|
|
10461
10566
|
const map = {};
|
|
@@ -10593,7 +10698,8 @@ async function gatherFindings(stackName, region, templateOverride, recoveryTempl
|
|
|
10593
10698
|
siblingManagedPolicyAttachments: buildSiblingManagedPolicyAttachments(desired),
|
|
10594
10699
|
siblingUserGroups: buildSiblingUserGroups(desired),
|
|
10595
10700
|
bucketNotificationManaged: buildBucketNotificationManaged(desired),
|
|
10596
|
-
clusterEchoModel: buildClusterEchoModels(desired)
|
|
10701
|
+
clusterEchoModel: buildClusterEchoModels(desired),
|
|
10702
|
+
rdsOptionSettingDefaults: await buildRdsOptionSettingDefaults(desired, region)
|
|
10597
10703
|
};
|
|
10598
10704
|
const corpusDir = process.env[CORPUS_DIR_ENV];
|
|
10599
10705
|
for (const r of desired.resources) {
|
|
@@ -10654,7 +10760,8 @@ async function regatherTouched(gathered, touched, region) {
|
|
|
10654
10760
|
siblingManagedPolicyAttachments: buildSiblingManagedPolicyAttachments(desired),
|
|
10655
10761
|
siblingUserGroups: buildSiblingUserGroups(desired),
|
|
10656
10762
|
bucketNotificationManaged: buildBucketNotificationManaged(desired),
|
|
10657
|
-
clusterEchoModel: buildClusterEchoModels(desired)
|
|
10763
|
+
clusterEchoModel: buildClusterEchoModels(desired),
|
|
10764
|
+
rdsOptionSettingDefaults: await buildRdsOptionSettingDefaults(desired, region)
|
|
10658
10765
|
};
|
|
10659
10766
|
const fresh = [];
|
|
10660
10767
|
for (const r of targets) fresh.push(...await classifyRead(cfn, r, reads.get(r.logicalId), schemas, classifyOpts));
|