Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bucketNotificationDestination: SnsDestination does not give S3 service principal KMS access when Topic is encrypted under KMS key #29511

Open
vcattoir opened this issue Mar 15, 2024 · 5 comments
Labels
@aws-cdk/aws-s3 Related to Amazon S3 bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@vcattoir
Copy link

Describe the bug

In https://github.com/aws/aws-cdk/blob/v2.133.0/packages/aws-cdk-lib/aws-s3-notifications/lib/sns.ts, creating SnsDestination sets up topic access policy for S3 Service principal to publish to SNS topic.

But if topic has KMS key encryption, nothing is added and S3 cannot verify the notification destination configuration is valid.
Similar to what is done in SqsDestination https://github.com/aws/aws-cdk/blob/v2.133.0/packages/aws-cdk-lib/aws-s3-notifications/lib/sqs.ts#L27-L37

Expected Behavior

I was expecting the KMS key access to be given automatically when creating Sns notification destination.

Current Behavior

The SNS does not receive any notification as S3 is not able to verify destination is valid when SNS has KMS encryption.

Reproduction Steps

Creating an SNS topic using KSM encryption.
Creating an S3 bucket.
Adding SNS notification destination for S3 bucket events.

Possible Solution

Do similar as what is done in SqsDestination https://github.com/aws/aws-cdk/blob/v2.133.0/packages/aws-cdk-lib/aws-s3-notifications/lib/sqs.ts#L27-L37

Additional Information/Context

No response

CDK CLI Version

v2.133

Framework Version

No response

Node.js Version

18

OS

MacOS

Language

TypeScript

Language Version

No response

Other information

No response

@vcattoir vcattoir added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 15, 2024
@github-actions github-actions bot added the @aws-cdk/aws-s3 Related to Amazon S3 label Mar 15, 2024
@msambol
Copy link
Contributor

msambol commented Mar 16, 2024

I'll take this.

@msambol
Copy link
Contributor

msambol commented Mar 17, 2024

This one is tricky because with SQS, if you specify KMS and don't specify a key, CDK will create a new KMS key and can update the policy. However, if you specify the KMS key, CDK cannot update the key policy. See these lines.

With SNS, CDK does not create the KMS key for you. You must specify the KMS key. And we can't update the key policy of an imported key. I suppose the options are:

  1. Update SNS to create a KMS if you don't specify one.
  2. Throw a warning that the KMS key policy cannot be updated for an imported KMS key.

I will wait for import from the team to proceed.

@pahud pahud added p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Mar 19, 2024
@pahud
Copy link
Contributor

pahud commented Mar 19, 2024

Thank you @msambol we probably can do both but we need the input from the maintainers.

@vcattoir
Copy link
Author

@msambol I have a question about this

This one is tricky because with SQS, if you specify KMS and don't specify a key, CDK will create a new KMS key and can update the policy. However, if you specify the KMS key, CDK cannot update the key policy. See these lines.

Is this a documented behavior ?
I do have examples where a specific KMS key was given to an SQS and the key policy was updated when creating an SNS subscription to the SQS ( code adding to the key here).
My example was with both resources being in same account and same stack. I would have imagined the error message mentioned there should not exclude any imported KMS but those owned by another account or stack which it obviously cannot update.

@paulhcsun
Copy link
Contributor

Hey @msambol, since the queue.encryptionMasterKey is a kms.IKey the same as the sns.masterKey is, we can implement this the same way for SNS as is done in SQS by both updating SNS to create a KMS if you don't specify one and also throwing a warning that the KMS key policy cannot be updated for an imported KMS key.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-s3 Related to Amazon S3 bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

No branches or pull requests

4 participants