cdk-real-drift 0.12.91 → 0.12.92

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
@@ -297,6 +297,8 @@ needs `--remove-unrecorded`).
297
297
  with no declared `AWS::S3::BucketPolicy`)
298
298
  - **SQS**: queue access policies (an out-of-band `set-queue-attributes Policy` on a
299
299
  queue with no declared `AWS::SQS::QueuePolicy`)
300
+ - **Secrets Manager**: secret resource policies (an out-of-band `put-resource-policy`
301
+ on a secret with no declared `AWS::SecretsManager::ResourcePolicy`)
300
302
 
301
303
  </details>
302
304
 
@@ -1027,6 +1029,11 @@ covers them. **If you never run `revert`, cdkrd needs no write permissions at al
1027
1029
  access policy as a child `AWS::SQS::QueuePolicy`; a queue with no policy simply
1028
1030
  returns no `Policy` attribute). Reverting a detected one also needs
1029
1031
  `sqs:SetQueueAttributes` (the SDK deleter clears the `Policy`).
1032
+ - `AWS::SecretsManager::Secret`: `secretsmanager:GetResourcePolicy` (enumerates a
1033
+ secret's out-of-band resource policy as a child
1034
+ `AWS::SecretsManager::ResourcePolicy`; a secret with no policy returns none).
1035
+ Reverting a detected one also needs `secretsmanager:DeleteResourcePolicy` (the
1036
+ SDK deleter detaches the policy).
1030
1037
 
1031
1038
  The `added` tier also needs `cloudformation:DescribeStackResources` (grouped with
1032
1039
  the other CloudFormation actions above): before flagging a live child as
package/dist/cli.js CHANGED
@@ -29,6 +29,7 @@ import { GetFunctionCommand, GetPolicyCommand, LambdaClient, ListAliasesCommand
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
31
  import { DeleteBucketPolicyCommand, GetBucketPolicyCommand, GetObjectCommand, PutBucketPolicyCommand, S3Client } from "@aws-sdk/client-s3";
32
+ import { DeleteResourcePolicyCommand, GetResourcePolicyCommand, SecretsManagerClient } from "@aws-sdk/client-secrets-manager";
32
33
  import { GetTopicAttributesCommand, ListSubscriptionsByTopicCommand, SNSClient, SetTopicAttributesCommand } from "@aws-sdk/client-sns";
33
34
  import { GetQueueAttributesCommand, SQSClient, SetQueueAttributesCommand } from "@aws-sdk/client-sqs";
34
35
  import { ACMClient, DescribeCertificateCommand, ListTagsForCertificateCommand } from "@aws-sdk/client-acm";
@@ -7500,6 +7501,7 @@ function lambdaFunctionRefMatches(declaredValue, ...candidates) {
7500
7501
  const CHILD_ENUMERATORS = {
7501
7502
  "AWS::S3::Bucket": enumerateS3BucketChildren,
7502
7503
  "AWS::SQS::Queue": enumerateSqsQueueChildren,
7504
+ "AWS::SecretsManager::Secret": enumerateSecretsManagerSecretChildren,
7503
7505
  "AWS::ApiGateway::RestApi": enumerateRestApiChildren,
7504
7506
  "AWS::ApiGatewayV2::Api": enumerateHttpApiChildren,
7505
7507
  "AWS::SNS::Topic": enumerateSnsTopicChildren,
@@ -8569,6 +8571,53 @@ async function enumerateSqsQueueChildren(ctx) {
8569
8571
  livePolicy
8570
8572
  });
8571
8573
  }
8574
+ function diffSecretsManagerResourcePolicy(input) {
8575
+ if (input.hasDeclaredPolicy) return [];
8576
+ if (!input.livePolicy) return [];
8577
+ return [{
8578
+ resourceType: "AWS::SecretsManager::ResourcePolicy",
8579
+ identifier: input.secretId,
8580
+ siblingLookupId: input.secretId,
8581
+ label: `secret resource policy ${input.secretId}`,
8582
+ live: {
8583
+ SecretId: input.secretId,
8584
+ ResourcePolicy: input.livePolicy
8585
+ }
8586
+ }];
8587
+ }
8588
+ async function readSecretsManagerResourcePolicyDocument(client, secretId) {
8589
+ const policyJson = (await client.send(new GetResourcePolicyCommand({ SecretId: secretId }))).ResourcePolicy;
8590
+ if (!policyJson) return void 0;
8591
+ let parsed;
8592
+ try {
8593
+ parsed = JSON.parse(policyJson);
8594
+ } catch {
8595
+ return;
8596
+ }
8597
+ return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : void 0;
8598
+ }
8599
+ async function enumerateSecretsManagerSecretChildren(ctx) {
8600
+ const { parent, desired, region } = ctx;
8601
+ const secretId = parent.physicalId;
8602
+ if (!secretId) return [];
8603
+ let hasDeclaredPolicy = false;
8604
+ for (const r of desired.resources) {
8605
+ if (r.resourceType !== "AWS::SecretsManager::ResourcePolicy") continue;
8606
+ const sid = r.declared.SecretId;
8607
+ if (typeof sid === "string") {
8608
+ if (sid === secretId) hasDeclaredPolicy = true;
8609
+ } else if (sid !== void 0 && hasUnresolved(sid)) hasDeclaredPolicy = true;
8610
+ }
8611
+ const livePolicy = await readSecretsManagerResourcePolicyDocument(new SecretsManagerClient({
8612
+ region,
8613
+ ...READ_RETRY
8614
+ }), secretId);
8615
+ return diffSecretsManagerResourcePolicy({
8616
+ secretId,
8617
+ hasDeclaredPolicy,
8618
+ livePolicy
8619
+ });
8620
+ }
8572
8621
  function diffEventBusChildren(input) {
8573
8622
  const declared = new Set(input.declaredRuleNames);
8574
8623
  const added = [];
@@ -12960,7 +13009,11 @@ function addedFinding(parent, c, read) {
12960
13009
  ...read.ok ? {} : { modelReadFailed: true }
12961
13010
  };
12962
13011
  }
12963
- const CC_GET_UNSUPPORTED_ADDED_TYPES = new Set(["AWS::Route53::RecordSet", "AWS::SQS::QueuePolicy"]);
13012
+ const CC_GET_UNSUPPORTED_ADDED_TYPES = new Set([
13013
+ "AWS::Route53::RecordSet",
13014
+ "AWS::SQS::QueuePolicy",
13015
+ "AWS::SecretsManager::ResourcePolicy"
13016
+ ]);
12964
13017
  async function readAddedModel(cc, cfn, c, schemas, oaiCanonicalIds) {
12965
13018
  const normalizeWith = async (raw) => {
12966
13019
  let schema = schemas.get(c.resourceType);
@@ -17154,10 +17207,17 @@ const deleteSqsQueuePolicy = async (ctx) => {
17154
17207
  Attributes: { Policy: "" }
17155
17208
  }));
17156
17209
  };
17210
+ const deleteSecretsManagerResourcePolicy = async (ctx) => {
17211
+ await new SecretsManagerClient({
17212
+ region: ctx.region,
17213
+ ...CLIENT_TIMEOUTS
17214
+ }).send(new DeleteResourcePolicyCommand({ SecretId: ctx.physicalId }));
17215
+ };
17157
17216
  const SDK_DELETERS = {
17158
17217
  "AWS::AppSync::ApiKey": deleteAppSyncApiKey,
17159
17218
  "AWS::Route53::RecordSet": deleteRoute53RecordSet,
17160
- "AWS::SQS::QueuePolicy": deleteSqsQueuePolicy
17219
+ "AWS::SQS::QueuePolicy": deleteSqsQueuePolicy,
17220
+ "AWS::SecretsManager::ResourcePolicy": deleteSecretsManagerResourcePolicy
17161
17221
  };
17162
17222
 
17163
17223
  //#endregion