fix(events): serialize EventBusPolicy statements#37884
Conversation
There was a problem hiding this comment.
The pull request linter fails with the following errors:
❌ Fixes must contain a change to an integration test file and the resulting snapshot.
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.
✅ A exemption request has been requested. Please wait for a maintainer's review.
|
Exemption Request: this fix is limited to serializing EventBusPolicyProps.statement before synthesis. The regression test covers the failing direct EventBusPolicy path with an AccountPrincipal and asserts the synthesized statement JSON. An integration test would only snapshot the same synthesized policy shape, so the unit regression is the targeted coverage for this bug. |
Issue
Closes #24031.
Reason for this change
EventBusPolicyProps.statementis typed asiam.PolicyStatement, butEventBusPolicypassed thePolicyStatementinstance directly into the underlyingCfnEventBusPolicy. When that statement includes principals, CloudFormation synthesis can walk thegrantPrincipalobject graph and fail with a circular reference.EventBus.addToResourcePolicy()already avoids this by passingstatement.toJSON()intoEventBusPolicy. DirectEventBusPolicyusage should do the same thing.Description of changes
EventBusPolicyProps.statementwithtoJSON()before passing it toCfnEventBusPolicy.EventBusPolicyusage with anAccountPrincipal.Description of how you validated changes
git diff --checkpasses.jest aws-events/test/event-bus.test.ts --runInBandusing the existing local AWS CDK toolchain. The test runner could not start in the fresh worktree because generatedcore/distartifacts were missing (../dist/core/cfn-utils-provider.generated).Checklist