cdk-real-drift 0.12.86 → 0.12.88

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
@@ -293,6 +293,8 @@ needs `--remove-unrecorded`).
293
293
  - **AppConfig**: application environments, configuration profiles
294
294
  - **EFS**: file system mount targets
295
295
  - **RDS**: database cluster instances
296
+ - **S3**: bucket resource policies (an out-of-band `put-bucket-policy` on a bucket
297
+ with no declared `AWS::S3::BucketPolicy`)
296
298
 
297
299
  </details>
298
300
 
@@ -1008,6 +1010,10 @@ covers them. **If you never run `revert`, cdkrd needs no write permissions at al
1008
1010
  `appconfig:ListConfigurationProfiles`
1009
1011
  - `AWS::EFS::FileSystem`: `elasticfilesystem:DescribeMountTargets`
1010
1012
  - `AWS::RDS::DBCluster`: `rds:DescribeDBClusters`, `rds:DescribeDBInstances`
1013
+ - `AWS::S3::Bucket`: `s3:GetBucketPolicy` (the same action listed as an SDK
1014
+ override-reader permission above — here it enumerates a bucket's out-of-band
1015
+ resource policy as a child `AWS::S3::BucketPolicy`, so it is required for the
1016
+ `added` tier too; `NoSuchBucketPolicy` is the normal no-policy case)
1011
1017
 
1012
1018
  The `added` tier also needs `cloudformation:DescribeStackResources` (grouped with
1013
1019
  the other CloudFormation actions above): before flagging a live child as
package/dist/cli.js CHANGED
@@ -28,6 +28,7 @@ import { DescribeEventBusCommand, EventBridgeClient, ListRulesCommand, PutPermis
28
28
  import { GetFunctionCommand, GetPolicyCommand, LambdaClient, ListAliasesCommand as ListAliasesCommand$1, ListEventSourceMappingsCommand, ListFunctionUrlConfigsCommand, ListVersionsByFunctionCommand } from "@aws-sdk/client-lambda";
29
29
  import { DescribeDomainConfigCommand, DescribeDomainsCommand, ListDomainNamesCommand, OpenSearchClient, UpdateDomainConfigCommand } from "@aws-sdk/client-opensearch";
30
30
  import { ChangeResourceRecordSetsCommand, ListResourceRecordSetsCommand, Route53Client } from "@aws-sdk/client-route-53";
31
+ import { DeleteBucketPolicyCommand, GetBucketPolicyCommand, GetObjectCommand, PutBucketPolicyCommand, S3Client } from "@aws-sdk/client-s3";
31
32
  import { GetTopicAttributesCommand, ListSubscriptionsByTopicCommand, SNSClient, SetTopicAttributesCommand } from "@aws-sdk/client-sns";
32
33
  import { ACMClient, DescribeCertificateCommand, ListTagsForCertificateCommand } from "@aws-sdk/client-acm";
33
34
  import { BudgetsClient, DescribeBudgetCommand } from "@aws-sdk/client-budgets";
@@ -38,7 +39,6 @@ import { DescribeDBClustersCommand as DescribeDBClustersCommand$1, DescribeDBIns
38
39
  import { DAXClient, DescribeClustersCommand, DescribeParameterGroupsCommand, DescribeParametersCommand as DescribeParametersCommand$1, DescribeSubnetGroupsCommand, ListTagsCommand, UpdateClusterCommand, UpdateParameterGroupCommand } from "@aws-sdk/client-dax";
39
40
  import { GetClassifierCommand, GetConnectionCommand, GetJobCommand, GetSecurityConfigurationCommand, GetTableCommand, GetTagsCommand, GetWorkflowCommand, GlueClient, UpdateClassifierCommand, UpdateConnectionCommand, UpdateJobCommand, UpdateTableCommand, UpdateWorkflowCommand } from "@aws-sdk/client-glue";
40
41
  import { AttachGroupPolicyCommand, AttachRolePolicyCommand, AttachUserPolicyCommand, CreatePolicyVersionCommand, DeletePolicyVersionCommand, DeleteRolePolicyCommand, DetachGroupPolicyCommand, DetachRolePolicyCommand, DetachUserPolicyCommand, GetGroupPolicyCommand, GetPolicyCommand as GetPolicyCommand$1, GetPolicyVersionCommand, GetRolePolicyCommand, GetUserPolicyCommand, IAMClient, ListAccessKeysCommand, ListEntitiesForPolicyCommand, ListPolicyVersionsCommand, PutGroupPolicyCommand, PutRolePolicyCommand, PutUserPolicyCommand } from "@aws-sdk/client-iam";
41
- import { DeleteBucketPolicyCommand, GetBucketPolicyCommand, GetObjectCommand, PutBucketPolicyCommand, S3Client } from "@aws-sdk/client-s3";
42
42
  import { DescribeCacheClustersCommand, DescribeCacheParameterGroupsCommand, DescribeCacheParametersCommand, DescribeReplicationGroupsCommand, DescribeUsersCommand, ElastiCacheClient, ListTagsForResourceCommand as ListTagsForResourceCommand$1, ModifyCacheParameterGroupCommand, ResetCacheParameterGroupCommand } from "@aws-sdk/client-elasticache";
43
43
  import { DescribeParameterGroupsCommand as DescribeParameterGroupsCommand$1, DescribeParametersCommand as DescribeParametersCommand$2, DescribeUsersCommand as DescribeUsersCommand$1, MemoryDBClient, ResetParameterGroupCommand, UpdateParameterGroupCommand as UpdateParameterGroupCommand$1 } from "@aws-sdk/client-memorydb";
44
44
  import { CloudWatchClient, DescribeAnomalyDetectorsCommand, PutAnomalyDetectorCommand } from "@aws-sdk/client-cloudwatch";
@@ -2517,6 +2517,7 @@ const KNOWN_DEFAULTS = {
2517
2517
  ManageMasterUserPassword: false,
2518
2518
  MultiAZ: false,
2519
2519
  StorageEncrypted: false,
2520
+ BackupRetentionPeriod: 1,
2520
2521
  CACertificateIdentifier: "rds-ca-rsa2048-g1"
2521
2522
  },
2522
2523
  "AWS::RDS::DBCluster": {
@@ -3124,7 +3125,7 @@ const CONTEXT_ARN_DEFAULTS = {
3124
3125
  };
3125
3126
  const ENGINE_DEFAULTS = {
3126
3127
  "AWS::RDS::DBInstance": {
3127
- StorageType: (e) => e.startsWith("aurora") ? "aurora" : void 0,
3128
+ StorageType: (e) => e.startsWith("aurora") ? "aurora" : "gp2",
3128
3129
  AllocatedStorage: (e) => e.startsWith("aurora") ? 1 : void 0,
3129
3130
  Port: rdsDefaultPort,
3130
3131
  LicenseModel: rdsDefaultLicense
@@ -3367,6 +3368,7 @@ const VALUE_INDEPENDENT_DEFAULT_TOPLEVEL_PATHS = {
3367
3368
  "AWS::ApiGateway::Authorizer": new Set(["AuthType"]),
3368
3369
  "AWS::RDS::DBCluster": new Set([
3369
3370
  "KmsKeyId",
3371
+ "EngineVersion",
3370
3372
  "PerformanceInsightsKmsKeyId",
3371
3373
  "AvailabilityZones",
3372
3374
  "PreferredMaintenanceWindow",
@@ -3375,6 +3377,7 @@ const VALUE_INDEPENDENT_DEFAULT_TOPLEVEL_PATHS = {
3375
3377
  ]),
3376
3378
  "AWS::RDS::DBInstance": new Set([
3377
3379
  "KmsKeyId",
3380
+ "EngineVersion",
3378
3381
  "PerformanceInsightsKMSKeyId",
3379
3382
  "AvailabilityZone",
3380
3383
  "PreferredMaintenanceWindow",
@@ -3423,7 +3426,11 @@ const VALUE_INDEPENDENT_DEFAULT_TOPLEVEL_PATHS = {
3423
3426
  "AWS::EC2::Instance": new Set([
3424
3427
  "PrivateIpAddress",
3425
3428
  "CpuOptions",
3426
- "SubnetId"
3429
+ "SubnetId",
3430
+ "AvailabilityZone",
3431
+ "SecurityGroups",
3432
+ "Volumes",
3433
+ "BlockDeviceMappings"
3427
3434
  ]),
3428
3435
  "AWS::EC2::NetworkInterface": new Set(["PrivateIpAddress", "PrivateIpAddresses"]),
3429
3436
  "AWS::EC2::Volume": new Set(["KmsKeyId", "AvailabilityZoneId"]),
@@ -7138,6 +7145,17 @@ function classifyResource(resource, liveRaw, schema, opts = {}) {
7138
7145
  });
7139
7146
  continue;
7140
7147
  }
7148
+ if (resourceType === "AWS::EC2::Instance" && k === "NetworkInterfaces" && Array.isArray(v)) {
7149
+ const allPrimary = v.every((el) => el != null && typeof el === "object" && String(el.DeviceIndex) === "0");
7150
+ findings.push({
7151
+ tier: allPrimary ? "atDefault" : "undeclared",
7152
+ logicalId,
7153
+ resourceType,
7154
+ path: k,
7155
+ actual: v
7156
+ });
7157
+ continue;
7158
+ }
7141
7159
  const ctxKind = CONTEXT_DEFAULTS[resourceType]?.[k];
7142
7160
  if (ctxKind !== void 0 && opts.region !== void 0) {
7143
7161
  if (deepEqual(v, ctxKind === "region" ? opts.region : [opts.region])) {
@@ -7416,6 +7434,7 @@ function lambdaFunctionRefMatches(declaredValue, ...candidates) {
7416
7434
  return parentRefMatches(unqualifiedFunctionRef(declaredValue), ...candidates.map((c) => c === void 0 ? void 0 : unqualifiedFunctionRef(c)));
7417
7435
  }
7418
7436
  const CHILD_ENUMERATORS = {
7437
+ "AWS::S3::Bucket": enumerateS3BucketChildren,
7419
7438
  "AWS::ApiGateway::RestApi": enumerateRestApiChildren,
7420
7439
  "AWS::ApiGatewayV2::Api": enumerateHttpApiChildren,
7421
7440
  "AWS::SNS::Topic": enumerateSnsTopicChildren,
@@ -8381,6 +8400,59 @@ async function enumerateLambdaFunctionChildren(ctx) {
8381
8400
  ...policyAdded
8382
8401
  ];
8383
8402
  }
8403
+ function diffS3BucketPolicy(input) {
8404
+ if (input.hasDeclaredPolicy) return [];
8405
+ if (!input.livePolicy) return [];
8406
+ return [{
8407
+ resourceType: "AWS::S3::BucketPolicy",
8408
+ identifier: input.bucketName,
8409
+ siblingLookupId: input.bucketName,
8410
+ label: `bucket policy ${input.bucketName}`,
8411
+ live: {
8412
+ Bucket: input.bucketName,
8413
+ PolicyDocument: input.livePolicy
8414
+ }
8415
+ }];
8416
+ }
8417
+ async function readS3BucketPolicyDocument(client, bucket) {
8418
+ let policyJson;
8419
+ try {
8420
+ policyJson = (await client.send(new GetBucketPolicyCommand({ Bucket: bucket })))?.Policy;
8421
+ } catch (e) {
8422
+ if (e.name === "NoSuchBucketPolicy") return void 0;
8423
+ throw e;
8424
+ }
8425
+ if (!policyJson) return void 0;
8426
+ let parsed;
8427
+ try {
8428
+ parsed = JSON.parse(policyJson);
8429
+ } catch {
8430
+ return;
8431
+ }
8432
+ return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : void 0;
8433
+ }
8434
+ async function enumerateS3BucketChildren(ctx) {
8435
+ const { parent, desired, region } = ctx;
8436
+ const bucketName = parent.physicalId;
8437
+ if (!bucketName) return [];
8438
+ let hasDeclaredPolicy = false;
8439
+ for (const r of desired.resources) {
8440
+ if (r.resourceType !== "AWS::S3::BucketPolicy") continue;
8441
+ const b = r.declared.Bucket;
8442
+ if (typeof b === "string") {
8443
+ if (b === bucketName) hasDeclaredPolicy = true;
8444
+ } else if (b !== void 0 && hasUnresolved(b)) hasDeclaredPolicy = true;
8445
+ }
8446
+ const livePolicy = await readS3BucketPolicyDocument(new S3Client({
8447
+ region,
8448
+ ...READ_RETRY
8449
+ }), bucketName);
8450
+ return diffS3BucketPolicy({
8451
+ bucketName,
8452
+ hasDeclaredPolicy,
8453
+ livePolicy
8454
+ });
8455
+ }
8384
8456
  function diffEventBusChildren(input) {
8385
8457
  const declared = new Set(input.declaredRuleNames);
8386
8458
  const added = [];