-
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): for SSE topics, add KMS permissions in grantPublish #32794
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -5,6 +5,7 @@ import { ITopicSubscription } from './subscriber'; | |||||||||||
import { Subscription } from './subscription'; | ||||||||||||
import * as notifications from '../../aws-codestarnotifications'; | ||||||||||||
import * as iam from '../../aws-iam'; | ||||||||||||
import { IKey } from '../../aws-kms'; | ||||||||||||
import { IResource, Resource, ResourceProps, Token } from '../../core'; | ||||||||||||
|
||||||||||||
/** | ||||||||||||
|
@@ -25,6 +26,17 @@ export interface ITopic extends IResource, notifications.INotificationRuleTarget | |||||||||||
*/ | ||||||||||||
readonly topicName: string; | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* A KMS Key, either managed by this CDK app, or imported. | ||||||||||||
* | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added, thanks! |
||||||||||||
* This property applies only to server-side encryption. | ||||||||||||
* | ||||||||||||
* @see https://docs.aws.amazon.com/sns/latest/dg/sns-server-side-encryption.html | ||||||||||||
* | ||||||||||||
* @default None | ||||||||||||
*/ | ||||||||||||
readonly masterKey?: IKey; | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Enables content-based deduplication for FIFO topics. | ||||||||||||
* | ||||||||||||
|
@@ -72,6 +84,8 @@ export abstract class TopicBase extends Resource implements ITopic { | |||||||||||
|
||||||||||||
public abstract readonly topicName: string; | ||||||||||||
|
||||||||||||
public abstract readonly masterKey?: IKey; | ||||||||||||
|
||||||||||||
public abstract readonly fifo: boolean; | ||||||||||||
|
||||||||||||
public abstract readonly contentBasedDeduplication: boolean; | ||||||||||||
|
@@ -173,12 +187,16 @@ export abstract class TopicBase extends Resource implements ITopic { | |||||||||||
* Grant topic publishing permissions to the given identity | ||||||||||||
*/ | ||||||||||||
public grantPublish(grantee: iam.IGrantable) { | ||||||||||||
return iam.Grant.addToPrincipalOrResource({ | ||||||||||||
const ret = iam.Grant.addToPrincipalOrResource({ | ||||||||||||
grantee, | ||||||||||||
actions: ['sns:Publish'], | ||||||||||||
resourceArns: [this.topicArn], | ||||||||||||
resource: this, | ||||||||||||
}); | ||||||||||||
if (this.masterKey) { | ||||||||||||
this.masterKey.grant(grantee, 'kms:Decrypt', 'kms:GenerateDataKey*'); | ||||||||||||
} | ||||||||||||
return ret; | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
|
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.
Couldn't we import
topic2
instead?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.
Sorry, not sure I understand the suggestion, do you mean
topic
? I can try to provide some of my thinking here:importedTopic
isn't aware there's a KMS key sograntPublish
doesn't work.topic2
, so that importing withfromTopicArn
and callinggrantPublish
does work.topic3
and usedfromTopicAttributes
, testing the same basic flow.topic
is encrypted and could be used for importing... it's just created up higher, and it felt like we'd moved on from it flow-wise.I'm not totally sure what the norm is here, so your guidance is appreciated!
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.
Thanks for clarifying 👍 Your implementation makes sense as is