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

fix(sqs) KMS-Managed SQS encryption generate valid IAM Policy for gra… #3133

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-s3-notifications/test/queue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,6 @@ test('fails if trying to subscribe to a queue with managed kms encryption', () =
const bucket = new s3.Bucket(stack, 'Bucket');
expect(() => {
bucket.addObjectRemovedNotification(new notif.SqsDestination(queue));
}).toThrow('Unable to add statement to IAM resource policy for KMS key: "alias/aws/sqs"');
}).toThrow('Unable to add statement to IAM resource policy for KMS key:\
{\"Fn::Join\":[\"\",[\"arn:aws:kms:\",{\"Ref\":\"AWS::Region\"},\":\",{\"Ref\":\"AWS::AccountId\"},\":alias/aws/sqs\"]]}');
});
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-sqs/lib/queue.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import kms = require('@aws-cdk/aws-kms');
import { Construct, Duration, Stack, Token } from '@aws-cdk/core';
import { Aws, Construct, Duration, Stack, Token } from '@aws-cdk/core';
import { IQueue, QueueAttributes, QueueBase } from './queue-base';
import { CfnQueue } from './sqs.generated';
import { validateProps } from './validate-props';
Expand Down Expand Up @@ -277,7 +277,7 @@ export class Queue extends QueueBase {
}

if (encryption === QueueEncryption.KMS_MANAGED) {
const masterKey = kms.Key.fromKeyArn(this, 'Key', 'alias/aws/sqs');
const masterKey = kms.Key.fromKeyArn(this, 'Key', `arn:aws:kms:${Aws.REGION}:${Aws.ACCOUNT_ID}:alias/aws/sqs`);
Copy link
Contributor

Choose a reason for hiding this comment

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

This grant isn't even necessary. The AWS-managed key will allow appropriate usage anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense and I've should have noticed this we are dealing with the default key here. :D

Thank you for fixing this!


return {
encryptionMasterKey: masterKey,
Expand Down