-
Notifications
You must be signed in to change notification settings - Fork 4.1k
fix(events): now EventBus.grantPutEventsTo
correctly handles service principals (under feature flag)
#33729
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(events): now EventBus.grantPutEventsTo
correctly handles service principals (under feature flag)
#33729
Changes from 2 commits
bf31013
50bd792
e6ab1d2
f5e39e7
70772a4
5541e98
3216adf
3da7c75
2848d53
af3f621
ae9cee6
c5740b3
df93608
a5c8b30
19e5f48
303ff44
6900b61
8040d6b
96717bb
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.
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.
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Template } from '../../assertions'; | ||
import * as iam from '../../aws-iam'; | ||
import { Stack } from '../../core'; | ||
import { EventBus } from '../lib'; | ||
|
||
describe('EventBus grants', () => { | ||
test('grantPutEventsTo creates EventBusPolicy for service principal', () => { | ||
// GIVEN | ||
const stack = new Stack(); | ||
const eventBus = new EventBus(stack, 'EventBus'); | ||
const servicePrincipal = new iam.ServicePrincipal('states.amazonaws.com'); | ||
|
||
// WHEN | ||
eventBus.grantPutEventsTo(servicePrincipal); | ||
|
||
// THEN | ||
Template.fromStack(stack).hasResourceProperties('AWS::Events::EventBusPolicy', { | ||
Action: 'events:PutEvents', | ||
Principal: 'states.amazonaws.com', | ||
StatementId: 'AllowPutEvents-EventBus', | ||
EventBusName: { Ref: 'EventBus7B8748AA' }, | ||
}); | ||
}); | ||
|
||
test('grantPutEventsTo creates IAM policy for IAM principal', () => { | ||
// GIVEN | ||
const stack = new Stack(); | ||
const eventBus = new EventBus(stack, 'EventBus'); | ||
const role = new iam.Role(stack, 'Role', { | ||
assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'), | ||
}); | ||
|
||
// WHEN | ||
eventBus.grantPutEventsTo(role); | ||
|
||
// THEN | ||
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { | ||
PolicyDocument: { | ||
Statement: [{ | ||
Action: 'events:PutEvents', | ||
Effect: 'Allow', | ||
Resource: { | ||
'Fn::GetAtt': ['EventBus7B8748AA', 'Arn'], | ||
}, | ||
}], | ||
Version: '2012-10-17', | ||
}, | ||
}); | ||
}); | ||
}); |
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.
this is not a generic solution. We still have issues with other Principle types that does not implement
addToPrincipalPolicy
(or it can not linked to a Policy resource), like AccountPrincipal, AnyPrincipal.EventBus resource supports the ResourcePolicy (AWS::Events::EventBusPolicy) .. so we should make the EventBus L2 to implement the interface IResourceWithPolicy, and to implements
addToResourcePolicy
function which looks it is already there.Then you can change the implementation of this function from
iam.Grant.addToPrincipal
to beiam.Grant.addToPrincipalOrResource
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.
one more thing, I am not sure if it is Ok to create multiple EventBusPolicy resources for the same EventBus or not .. we need to have an integ test case for that.