-
Notifications
You must be signed in to change notification settings - Fork 4.1k
aws-events: Cannot grant putEvents
to Service Principals
#22080
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
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 |
…vice principals (issue aws#22080)
…principals (fixes aws#22080)
…principals (fixes aws#22080)
Comments on closed issues and PRs are hard for our team to see. |
1 similar comment
Comments on closed issues and PRs are hard for our team to see. |
…e principals (under feature flag) (aws#33729) ### Issue aws#22080 Closes aws#22080. ### Reason for this change When trying to grant PutEvents permissions to an AWS Service Principal using `grantPutEventsTo`, the method performed a no-op without any warnings or errors. This prevented users from properly granting permissions to service principals, even though this is a valid use case that can be done through the AWS Console. The change implements the correct behavior by creating an EventBusPolicy when dealing with service principals. ### Description of changes - Added special handling for service principals in `EventBus.grantPutEventsTo` method - When granting permissions to a service principal, creates an EventBusPolicy instead of attempting to modify IAM policies - Returns `iam.Grant.drop()` for service principals to indicate permissions are handled via EventBusPolicy - Added test cases to verify both service principal and IAM principal scenarios ### Describe any new or updated permissions being added The change introduces the creation of EventBusPolicy resources with `events:PutEvents` permission when granting access to service principals. This is not a new permission, but rather a different way of granting the same permission through resource-based policies instead of identity-based policies. ### Description of how you validated changes Added new test cases that verify: - EventBusPolicy is correctly created when granting permissions to service principals - IAM policies are correctly created when granting permissions to IAM roles/users ### Checklist - [X] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
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: