-
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
aws-events: Cannot grant putEvents
to Service Principals
#22080
Comments
This should have worked the way you said. Investigation is required. |
It also does not work for a cross-account scenario. The Example: const eventBus = new cdk.aws_events.EventBus(this, 'Bus');
eventBus.grantPutEventsTo(new cdk.aws_iam.AccountPrincipal('123456789012')); Workaround (from StackOverflow): const eventBus = new cdk.aws_events.EventBus(this, 'Bus');
new cdk.aws_events.CfnEventBusPolicy(this, 'XAccountPolicy', {
statementId: 'AllowXAccountPushEvents',
action: 'events:PutEvents',
eventBusName: eventBus.eventBusName,
principal: '123456789012,
}); Any recommendation @rix0rrr how this should be implemented? Not sure if |
It seems like the fix for this would be for grantPutEvents() to use iam.Grant.addToPrincipalOrResource() instead of iam.Grant.addToPrincipal(). |
If what you want to do is that put EventBusPolicy to your custom EventBus, it seems currently L2 construct not support this use case. Needs to use CfnEventBusPolicy (same as this comments indicates). (Below is my idea about how this use case could be implemented..) According to other service that has resouce based policy such as SNS and SQS, service specific (resource based) Policy class is available and service class provides "addToResourcePolicy()" method. e.x) addToResourcePolicy method in Topic class and TopicPolicy class
Follow the above, like SNS and SQS, I think it would be a good idea to provide an addToResourcePolicy method for EventBus. |
Looks like this is a bug for several
But that also results in no changes. I'll use resource policy for now, but it would be awesome if this worked as intended. |
is there a workaround like this that works with service principals? @pgarbe Edit: This const policyStatementId = `...`;
const policyStatement = new PolicyStatement({
sid: policyStatementId,
effect: Effect.ALLOW,
actions: ['events:PutEvents'],
resources: [eventsBus.eventBusArn],
principals: [new ServicePrincipal(`...`)],
});
new CfnEventBusPolicy(this, policyStatementId, {
statementId: policyStatementId,
statement: policyStatement.toStatementJson(),
eventBusName: `...`,
}); worked for me |
Describe the bug
When trying to
grantPutEventsTo
an AWS SP, there is a no-op, and no warnings or errors. I would expect if we added a grant to aiam.ServicePrincipal
that the underlying grant/policy would be created. We can add an SP to the event bus in the console. Tracing back code I myself didn't necessary find a place where this would have failed, or I would have expected if this was not possible to give a failure message.Expected Behavior
I would expect the template to have grant policies attached. If for some reason you weren't allowed to add SPs, I would expect a failure message and error.
Current Behavior
Nothing is logged to the terminal when synthing the template snippet is
Reproduction Steps
Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
2.23.0
Framework Version
No response
Node.js Version
14
OS
MacOs/Linux
Language
Typescript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: