Skip to content

Conversation

badmintoncryer
Copy link
Contributor

@badmintoncryer badmintoncryer commented Mar 21, 2025

Issue # (if applicable)

Closes #16271.

Reason for this change

To create S3 subscriptions for CMK encrypted SNS topic, we have to configure key policy to trust S3.
https://docs.aws.amazon.com/AmazonS3/latest/userguide/grant-destinations-permissions-to-s3.html#key-policy-sns-sqs

AWS CDK doesn't automatically configure CMK resource policy to receive s3 messages for CMK encrypted SNS subscriptions. Therefore, we have to configure it by ourselves.

Description of changes

  • Add feature flag S3_TRUST_KEY_POLICY_FOR_SNS_SUBSCRIPTIONS
  • Add key policy for encrypted subscription
      const statement = new iam.PolicyStatement({
        principals: [new iam.ServicePrincipal('s3.amazonaws.com')],
        actions: ['kms:GenerateDataKey', 'kms:Decrypt'],
        resources: ['*'],
      });
      const addResult = this.topic.masterKey.addToResourcePolicy(statement, true);

Describe any new or updated permissions being added

  • Add S3 trust policy to KMS key policy

Description of how you validated changes

Add both unit and integ tests

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation aws-cdk-automation requested a review from a team March 21, 2025 07:29
@github-actions github-actions bot added feature-request A feature should be added or improved. p1 distinguished-contributor [Pilot] contributed 50+ PRs to the CDK labels Mar 21, 2025
@badmintoncryer badmintoncryer changed the title feat(s3-notifications): add s3 trust to key for SNS event subscription feat(s3-notifications): add s3 trust to KMS key policy for SNS event subscription Mar 21, 2025
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This review is outdated)

@badmintoncryer badmintoncryer changed the title feat(s3-notifications): add s3 trust to KMS key policy for SNS event subscription feat(s3-notifications): add s3 trust to KMS key policy for SNS event subscription (under feature flag) Mar 21, 2025
@badmintoncryer badmintoncryer marked this pull request as ready for review March 21, 2025 08:37
@badmintoncryer badmintoncryer changed the title feat(s3-notifications): add s3 trust to KMS key policy for SNS event subscription (under feature flag) fix(s3-notifications): add s3 trust to KMS key policy for SNS event subscription (under feature flag) Mar 21, 2025
Copy link

codecov bot commented Mar 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.98%. Comparing base (74cbe27) to head (4f8c393).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #33858   +/-   ##
=======================================
  Coverage   83.98%   83.98%           
=======================================
  Files         120      120           
  Lines        6976     6976           
  Branches     1178     1178           
=======================================
  Hits         5859     5859           
  Misses       1005     1005           
  Partials      112      112           
Flag Coverage Δ
suite.unit 83.98% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk ∅ <ø> (∅)
packages/aws-cdk-lib/core 83.98% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aws-cdk-automation aws-cdk-automation dismissed their stale review March 21, 2025 08:51

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@badmintoncryer badmintoncryer changed the title fix(s3-notifications): add s3 trust to KMS key policy for SNS event subscription (under feature flag) fix(s3-notifications): add s3 trust policy to KMS key policy for encrypted SNS event subscription (under feature flag) Mar 22, 2025
Copy link
Contributor

mergify bot commented May 5, 2025

update

✅ Branch has been successfully updated

@paulhcsun
Copy link
Contributor

Looks like one integ test needs to be updated. I will re-approve after that has been pushed!

@badmintoncryer
Copy link
Contributor Author

@paulhcsun I'll update snapshot files later, thanks!

@mergify mergify bot dismissed paulhcsun’s stale review May 6, 2025 14:27

Pull request has been modified.

paulhcsun
paulhcsun previously approved these changes May 6, 2025
@paulhcsun
Copy link
Contributor

@Mergifyio update

Thanks @badmintoncryer!!

Copy link
Contributor

mergify bot commented May 6, 2025

update

✅ Branch has been successfully updated

Copy link
Contributor

mergify bot commented May 6, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

Copy link
Contributor

mergify bot commented May 6, 2025

This pull request has been removed from the queue for the following reason: pull request dequeued.

Pull request #33858 has been dequeued. The pull request could not be merged. This could be related to an activated branch protection or ruleset rule that prevents us from merging. (details: 2 of 2 required status checks are expected.).

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio requeue comment.

Copy link
Contributor

mergify bot commented May 6, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label May 6, 2025
Copy link
Contributor

mergify bot commented May 6, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot dismissed paulhcsun’s stale review May 6, 2025 20:44

Pull request has been modified.

@paulhcsun
Copy link
Contributor

@Mergifyio update

Copy link
Contributor

mergify bot commented May 6, 2025

update

✅ Branch has been successfully updated

Copy link
Contributor

mergify bot commented May 6, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 28a5a7e
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Copy link
Contributor

mergify bot commented May 6, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 1e87861 into aws:main May 6, 2025
13 of 15 checks passed
Copy link
Contributor

github-actions bot commented May 6, 2025

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 6, 2025
@badmintoncryer badmintoncryer deleted the 16271-s3-notification branch May 7, 2025 03:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
distinguished-contributor [Pilot] contributed 50+ PRs to the CDK feature-request A feature should be added or improved. needs-security-review Related to feature or issues that needs security review p1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws-s3-notifications): add s3 trust to key for SNS event subscription
4 participants