cdk-real-drift 0.12.96 → 0.12.98

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 CHANGED
@@ -288,10 +288,15 @@ needs `--remove-unrecorded`).
288
288
  - **AppSync**: data sources, resolvers, functions
289
289
  - **CloudWatch Logs**: metric filters, subscription filters
290
290
  - **ELBv2**: listeners, listener rules
291
- - **EC2**: VPC subnets, VPC endpoints, VPC route tables, VPC network ACLs, route
292
- table routes
291
+ - **EC2**: VPC subnets, VPC endpoints, VPC route tables, VPC network ACLs, VPC
292
+ security groups (an out-of-band `create-security-group` — a rogue firewall in a
293
+ declared VPC; the VPC default SG and AWS-service-created SGs, e.g. an EKS cluster
294
+ SG, are folded so only a user-created group surfaces), route table routes
293
295
  - **ECS**: cluster services
294
- - **KMS**: key aliases
296
+ - **KMS**: key aliases, key grants (an out-of-band `kms create-grant` on a key —
297
+ grants are not a CloudFormation type, so cdkrd surfaces them as a synthetic
298
+ `AWS::KMS::Grant`; AWS-service-created grants, e.g. a Lambda env-encryption key's
299
+ grant, are folded so only a human/IAM-principal grant surfaces)
295
300
  - **AppConfig**: application environments, configuration profiles
296
301
  - **EFS**: file system mount targets
297
302
  - **RDS**: database cluster instances
@@ -1017,14 +1022,19 @@ covers them. **If you never run `revert`, cdkrd needs no write permissions at al
1017
1022
  - `AWS::EC2::VPC` + `AWS::EC2::RouteTable`: `ec2:DescribeSubnets`,
1018
1023
  `ec2:DescribeRouteTables` (plus `ec2:DescribeInternetGateways` and
1019
1024
  `ec2:DescribeVpcs` for the VPC's out-of-band IGW attachment and secondary
1020
- CIDR sub-resources)
1025
+ CIDR sub-resources, and `ec2:DescribeSecurityGroups` for a VPC's out-of-band
1026
+ security groups — a rogue `AWS::EC2::SecurityGroup`; the default SG and
1027
+ AWS-service-created SGs are folded)
1021
1028
  - `AWS::EC2::NetworkAcl`: `ec2:DescribeNetworkAcls` (enumerates a declared
1022
1029
  NACL's out-of-band entries — a rogue `AWS::EC2::NetworkAclEntry`)
1023
1030
  - `AWS::ECS::Cluster`: `ecs:ListServices` (distinct from the
1024
1031
  `ecs:DescribeServices` override reader listed above)
1025
1032
  - `AWS::KMS::Key`: `kms:ListAliases` (the same action listed as optional
1026
1033
  above — here it enumerates a key's aliases as child resources, so it is
1027
- required, not optional, for the `added` tier)
1034
+ required, not optional, for the `added` tier), `kms:ListGrants` (enumerates a
1035
+ key's out-of-band grants as synthetic `AWS::KMS::Grant` children; AWS-service
1036
+ grants are folded, so only a human/IAM-principal grant surfaces). Reverting a
1037
+ detected one also needs `kms:RevokeGrant` (the SDK deleter revokes the grant).
1028
1038
  - `AWS::AppConfig::Application`: `appconfig:ListEnvironments`,
1029
1039
  `appconfig:ListConfigurationProfiles`
1030
1040
  - `AWS::EFS::FileSystem`: `elasticfilesystem:DescribeMountTargets`
@@ -1057,9 +1067,10 @@ covers them. **If you never run `revert`, cdkrd needs no write permissions at al
1057
1067
  `cloudcontrol:UpdateResource` (which resolves to each type's own update
1058
1068
  permissions), `cloudcontrol:DeleteResource` (to delete an out-of-band `added`
1059
1069
  resource; a type Cloud Control cannot delete goes through its own SDK action
1060
- instead — `appsync:DeleteApiKey` for an out-of-band `AWS::AppSync::ApiKey`, or
1070
+ instead — `appsync:DeleteApiKey` for an out-of-band `AWS::AppSync::ApiKey`,
1061
1071
  `route53:ChangeResourceRecordSets` (a DELETE change) for an out-of-band
1062
- `AWS::Route53::RecordSet`), and
1072
+ `AWS::Route53::RecordSet`, or `kms:RevokeGrant` for an out-of-band
1073
+ `AWS::KMS::Grant`), and
1063
1074
  `cloudcontrol:GetResourceRequestStatus` (to poll the async Cloud
1064
1075
  Control request to completion). Plus, for the SDK-written types:
1065
1076
  `s3:PutBucketPolicy` /
package/dist/cli.js CHANGED
@@ -15,7 +15,7 @@ import { DescribeServicesCommand, ECSClient, ListAccountSettingsCommand, ListSer
15
15
  import { DescribeCertificatesCommand, DescribeDBClustersCommand, DescribeDBInstancesCommand, DescribeOptionGroupOptionsCommand, RDSClient } from "@aws-sdk/client-rds";
16
16
  import { DescribeParametersCommand, GetParametersCommand, GetServiceSettingCommand, SSMClient } from "@aws-sdk/client-ssm";
17
17
  import jsonata from "jsonata";
18
- import { KMSClient, ListAliasesCommand } from "@aws-sdk/client-kms";
18
+ import { KMSClient, ListAliasesCommand, ListGrantsCommand, RevokeGrantCommand } from "@aws-sdk/client-kms";
19
19
  import { APIGatewayClient, GetAuthorizersCommand, GetGatewayResponsesCommand, GetModelsCommand, GetRequestValidatorsCommand, GetResourcesCommand, GetStagesCommand, UpdateIntegrationCommand, UpdateIntegrationResponseCommand, UpdateMethodResponseCommand, UpdateRestApiCommand } from "@aws-sdk/client-api-gateway";
20
20
  import { AppConfigClient, ListConfigurationProfilesCommand, ListEnvironmentsCommand } from "@aws-sdk/client-appconfig";
21
21
  import { AppSyncClient, DeleteApiKeyCommand, ListApiKeysCommand, ListDataSourcesCommand, ListFunctionsCommand, ListResolversCommand, ListTypesCommand } from "@aws-sdk/client-appsync";
@@ -7301,6 +7301,18 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
7301
7301
  });
7302
7302
  continue;
7303
7303
  }
7304
+ if (resourceType === "AWS::Kinesis::Stream" && k === "ShardCount") {
7305
+ if ((declared.StreamModeDetails?.StreamMode ?? live.StreamModeDetails?.StreamMode) === "ON_DEMAND") {
7306
+ findings.push({
7307
+ tier: "atDefault",
7308
+ logicalId,
7309
+ resourceType,
7310
+ path: k,
7311
+ actual: v
7312
+ });
7313
+ continue;
7314
+ }
7315
+ }
7304
7316
  const namePattern = DEFAULT_MANAGED_NAME_PATHS[resourceType]?.[k];
7305
7317
  if (namePattern !== void 0 && typeof v === "string" && namePattern.test(v)) {
7306
7318
  findings.push({
@@ -9532,6 +9544,39 @@ function diffVpcCidrBlockChildren(input) {
9532
9544
  }
9533
9545
  return added;
9534
9546
  }
9547
+ function isAwsManagedSecurityGroup(tags) {
9548
+ return (tags ?? []).some((t) => typeof t.Key === "string" && (t.Key.startsWith("aws:") || t.Key.startsWith("kubernetes.io/cluster/")));
9549
+ }
9550
+ function diffVpcSecurityGroupChildren(input) {
9551
+ const declared = new Set(input.declaredSecurityGroupIds);
9552
+ const added = [];
9553
+ for (const g of input.liveSecurityGroups) {
9554
+ if (declared.has(g.id)) continue;
9555
+ added.push({
9556
+ resourceType: "AWS::EC2::SecurityGroup",
9557
+ identifier: g.id,
9558
+ label: g.label ?? g.id,
9559
+ live: { Id: g.id }
9560
+ });
9561
+ }
9562
+ return added;
9563
+ }
9564
+ async function pageSecurityGroups(client, vpcId) {
9565
+ const out = [];
9566
+ let next;
9567
+ do {
9568
+ const res = await client.send(new DescribeSecurityGroupsCommand({
9569
+ Filters: [{
9570
+ Name: "vpc-id",
9571
+ Values: [vpcId]
9572
+ }],
9573
+ NextToken: next
9574
+ }));
9575
+ out.push(...res.SecurityGroups ?? []);
9576
+ next = res.NextToken;
9577
+ } while (next);
9578
+ return out;
9579
+ }
9535
9580
  async function pageSubnets(client, vpcId) {
9536
9581
  const out = [];
9537
9582
  let next;
@@ -9623,12 +9668,14 @@ async function enumerateVpcChildren(ctx) {
9623
9668
  const declaredEndpointIds = [];
9624
9669
  const declaredRouteTableIds = [];
9625
9670
  const declaredNaclIds = [];
9671
+ const declaredSecurityGroupIds = [];
9626
9672
  for (const r of desired.resources) {
9627
9673
  if (!parentRefMatches(r.declared.VpcId, vpcId) || !r.physicalId) continue;
9628
9674
  if (r.resourceType === "AWS::EC2::Subnet") declaredSubnetIds.push(r.physicalId);
9629
9675
  else if (r.resourceType === "AWS::EC2::VPCEndpoint") declaredEndpointIds.push(r.physicalId);
9630
9676
  else if (r.resourceType === "AWS::EC2::RouteTable") declaredRouteTableIds.push(r.physicalId);
9631
9677
  else if (r.resourceType === "AWS::EC2::NetworkAcl") declaredNaclIds.push(r.physicalId);
9678
+ else if (r.resourceType === "AWS::EC2::SecurityGroup") declaredSecurityGroupIds.push(r.physicalId);
9632
9679
  }
9633
9680
  const declaredAssociationIds = [];
9634
9681
  let hasDeclaredIgwAttachment = false;
@@ -9685,6 +9732,10 @@ async function enumerateVpcChildren(ctx) {
9685
9732
  cidr: b.Ipv6CidrBlock
9686
9733
  });
9687
9734
  }
9735
+ const liveSecurityGroups = (await pageSecurityGroups(client, vpcId)).filter((g) => typeof g.GroupId === "string" && g.GroupName !== "default" && !isAwsManagedSecurityGroup(g.Tags)).map((g) => ({
9736
+ id: g.GroupId,
9737
+ label: g.GroupName ?? g.GroupId
9738
+ }));
9688
9739
  return [
9689
9740
  ...diffVpcChildren({
9690
9741
  declaredSubnetIds,
@@ -9715,6 +9766,10 @@ async function enumerateVpcChildren(ctx) {
9715
9766
  vpcId,
9716
9767
  declaredCidrs,
9717
9768
  liveCidrBlocks
9769
+ }),
9770
+ ...diffVpcSecurityGroupChildren({
9771
+ declaredSecurityGroupIds,
9772
+ liveSecurityGroups
9718
9773
  })
9719
9774
  ];
9720
9775
  }
@@ -9917,13 +9972,59 @@ async function enumerateKmsKeyChildren(ctx) {
9917
9972
  const name = typeof r.declared.AliasName === "string" ? r.declared.AliasName : r.physicalId;
9918
9973
  if (name) declaredAliasNames.push(name);
9919
9974
  }
9975
+ const client = new KMSClient({
9976
+ region,
9977
+ ...READ_RETRY
9978
+ });
9979
+ const liveAliases = (await pageAliases(client, keyId)).filter((a) => typeof a.AliasName === "string").map((a) => ({ name: a.AliasName }));
9980
+ const liveGrants = (await pageGrants(client, keyId)).filter((g) => typeof g.GrantId === "string").map((g) => ({
9981
+ grantId: g.GrantId,
9982
+ name: g.Name,
9983
+ granteePrincipal: g.GranteePrincipal,
9984
+ retiringPrincipal: g.RetiringPrincipal,
9985
+ operations: g.Operations
9986
+ }));
9920
9987
  return diffKmsKeyChildren({
9921
9988
  declaredAliasNames,
9922
- liveAliases: (await pageAliases(new KMSClient({
9923
- region,
9924
- ...READ_RETRY
9925
- }), keyId)).filter((a) => typeof a.AliasName === "string").map((a) => ({ name: a.AliasName }))
9926
- });
9989
+ liveAliases
9990
+ }).concat(diffKmsKeyGrants({ liveGrants }));
9991
+ }
9992
+ function isAwsServicePrincipal(principal) {
9993
+ if (typeof principal !== "string" || principal.startsWith("arn:")) return false;
9994
+ return /^[a-z0-9-]+(\.[a-z0-9-]+)*\.amazonaws\.com$/.test(principal);
9995
+ }
9996
+ function diffKmsKeyGrants(input) {
9997
+ const added = [];
9998
+ for (const g of input.liveGrants) {
9999
+ if (isAwsServicePrincipal(g.granteePrincipal) || isAwsServicePrincipal(g.retiringPrincipal)) continue;
10000
+ added.push({
10001
+ resourceType: "AWS::KMS::Grant",
10002
+ identifier: g.grantId,
10003
+ siblingLookupId: g.grantId,
10004
+ label: g.name ? `grant ${g.name} (${g.grantId.slice(0, 12)}…)` : `grant ${g.grantId}`,
10005
+ live: {
10006
+ GrantId: g.grantId,
10007
+ ...g.name !== void 0 ? { GrantName: g.name } : {},
10008
+ ...g.granteePrincipal !== void 0 ? { GranteePrincipal: g.granteePrincipal } : {},
10009
+ ...g.retiringPrincipal !== void 0 ? { RetiringPrincipal: g.retiringPrincipal } : {},
10010
+ ...g.operations !== void 0 ? { Operations: g.operations } : {}
10011
+ }
10012
+ });
10013
+ }
10014
+ return added;
10015
+ }
10016
+ async function pageGrants(client, keyId) {
10017
+ const out = [];
10018
+ let marker;
10019
+ do {
10020
+ const res = await client.send(new ListGrantsCommand({
10021
+ KeyId: keyId,
10022
+ Marker: marker
10023
+ }));
10024
+ out.push(...res.Grants ?? []);
10025
+ marker = res.NextMarker;
10026
+ } while (marker);
10027
+ return out;
9927
10028
  }
9928
10029
  function diffAppConfigApplicationChildren(input) {
9929
10030
  const { applicationId, declaredEnvironmentIds, liveEnvironments } = input;
@@ -13124,7 +13225,8 @@ const CC_GET_UNSUPPORTED_ADDED_TYPES = new Set([
13124
13225
  "AWS::Route53::RecordSet",
13125
13226
  "AWS::SQS::QueuePolicy",
13126
13227
  "AWS::SecretsManager::ResourcePolicy",
13127
- "AWS::SNS::TopicPolicy"
13228
+ "AWS::SNS::TopicPolicy",
13229
+ "AWS::KMS::Grant"
13128
13230
  ]);
13129
13231
  async function readAddedModel(cc, cfn, c, schemas, oaiCanonicalIds) {
13130
13232
  const normalizeWith = async (raw) => {
@@ -17363,12 +17465,24 @@ const deleteSnsTopicPolicy = async (ctx) => {
17363
17465
  AttributeValue: defaultPolicy
17364
17466
  }));
17365
17467
  };
17468
+ const deleteKmsGrant = async (ctx) => {
17469
+ const keyId = ctx.parentPhysicalId;
17470
+ if (!keyId) throw new Error("cannot resolve the parent KMS Key id for the grant revoke");
17471
+ await new KMSClient({
17472
+ region: ctx.region,
17473
+ ...CLIENT_TIMEOUTS
17474
+ }).send(new RevokeGrantCommand({
17475
+ KeyId: keyId,
17476
+ GrantId: ctx.physicalId
17477
+ }));
17478
+ };
17366
17479
  const SDK_DELETERS = {
17367
17480
  "AWS::AppSync::ApiKey": deleteAppSyncApiKey,
17368
17481
  "AWS::Route53::RecordSet": deleteRoute53RecordSet,
17369
17482
  "AWS::SQS::QueuePolicy": deleteSqsQueuePolicy,
17370
17483
  "AWS::SecretsManager::ResourcePolicy": deleteSecretsManagerResourcePolicy,
17371
- "AWS::SNS::TopicPolicy": deleteSnsTopicPolicy
17484
+ "AWS::SNS::TopicPolicy": deleteSnsTopicPolicy,
17485
+ "AWS::KMS::Grant": deleteKmsGrant
17372
17486
  };
17373
17487
 
17374
17488
  //#endregion