-
Notifications
You must be signed in to change notification settings - Fork 4k
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(sns-subscriptions): SQS queue encrypted by AWS managed KMS key is allowed to be specified as subscription and dead-letter queue #26110
Conversation
… allowed to be specified as subscription and dead-letter queue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.
A comment requesting an exemption should contain the text Exemption Request
. Additionally, if clarification is needed add Clarification Request
to a comment.
Exemption Request because this change includes only additional validations. Please let me know if adding integration test is needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Just 1 comment
@@ -38,6 +38,18 @@ export class SqsSubscription implements sns.ITopicSubscription { | |||
} | |||
const snsServicePrincipal = new iam.ServicePrincipal('sns.amazonaws.com'); | |||
|
|||
// if the queue is encrypted by AWS managed KMS key (alias/aws/sqs), | |||
// throw error message | |||
if ((this.queue.node.defaultChild as sqs.CfnQueue).kmsMasterKeyId == 'alias/aws/sqs') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to handle the case where the queue is imported IQueue
in which
case there will not be a default child.
I think we may want to add a new attribute to the IQueue
, something like
encryptionType
that holds the type of encryption.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @corymhall, thank you for your review! I understand your concern.
If users import the queue via fromQueueArn
method, CDK cannot determine whether the queue is encrypted by AWS managed KMS key or not.
aws-cdk/packages/aws-cdk-lib/aws-sqs/lib/queue.ts
Lines 268 to 287 in f8a94d8
public static fromQueueArn(scope: Construct, id: string, queueArn: string): IQueue { | |
return Queue.fromQueueAttributes(scope, id, { queueArn }); | |
} | |
/** | |
* Import an existing queue | |
*/ | |
public static fromQueueAttributes(scope: Construct, id: string, attrs: QueueAttributes): IQueue { | |
const stack = Stack.of(scope); | |
const parsedArn = stack.splitArn(attrs.queueArn, ArnFormat.NO_RESOURCE_NAME); | |
const queueName = attrs.queueName || parsedArn.resource; | |
const queueUrl = attrs.queueUrl || `https://sqs.${parsedArn.region}.${stack.urlSuffix}/${parsedArn.account}/${queueName}`; | |
class Import extends QueueBase { | |
public readonly queueArn = attrs.queueArn; // arn:aws:sqs:us-east-1:123456789012:queue1 | |
public readonly queueUrl = queueUrl; | |
public readonly queueName = queueName; | |
public readonly encryptionMasterKey = attrs.keyArn | |
? kms.Key.fromKeyArn(this, 'Key', attrs.keyArn) | |
: undefined; |
So in my understanding, we can't validate it completely in that case. I think one possible solution is skipping the validation if encryptionMasterKey
is undefined to prevent error due to missing default child. Does it make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe users can provide the key in fromQueueAttributes
so if the encryptionType
is undefined then we don't do the validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please let me clarify. In you assumption, what type of value encryptionType
has? Is the same value as QueueEncryption enum?
https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_sqs.QueueEncryption.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think so.
|
||
// if the dead-letter queue is encrypted by AWS managed KMS key (alias/aws/sqs), | ||
// throw error message | ||
if (this.props.deadLetterQueue && (this.props.deadLetterQueue.node.defaultChild as sqs.CfnQueue).kmsMasterKeyId == 'alias/aws/sqs') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above
@tam0ri Are you still able to address the outstanding comments? |
@mrgrain |
Yes of course! Take as much time you need. If the automation closes this PR, just open a new one and feel free to tag me in it. 😃 |
This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week. |
@corymhall Sorry for delay, I made some changes per your suggestion. Could you review it again? |
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
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 CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
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). |
… allowed to be specified as subscription and dead-letter queue (aws#26110) To send message to SQS queues encrypted by KMS from SNS, we need to grant SNS service-principal access to the key by key policy. From this reason, we need to use customer managed key because we can't edit key policy for AWS managed key. However, CDK makes it easy to create such a non-functional subscription. To prevent CDK from making such a subscription, I added the validation which throw an error when SQS queue encrypted by AWS managed KMS key is specified as subscription or dead-letter queue. Closes aws#19796 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
To send message to SQS queues encrypted by KMS from SNS, we need to grant SNS service-principal access to the key by key policy. From this reason, we need to use customer managed key because we can't edit key policy for AWS managed key. However, CDK makes it easy to create such a non-functional subscription.
To prevent CDK from making such a subscription, I added the validation which throw an error when SQS queue encrypted by AWS managed KMS key is specified as subscription or dead-letter queue.
Closes #19796
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license