-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix(dynamodb): throw error when grantee is an unsupported ServicePrincipal #37335
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
34f8f12
fix(dynamodb): drop grant with warning when grantee is a ServicePrinc…
kumsmrit 09e51b5
added integration test
kumsmrit 7de1197
fix check
kumsmrit 818b4a6
fix(dynamodb): throw error instead of warning when granting to Servic…
Abogical 36f7407
fix(dynamodb): allowlist known-valid service principals for grant met…
Abogical 87b9099
test(dynamodb): add integ test for allowlisted service principal grants
Abogical 6fd29d4
Merge branch 'main' into fix-dynamo-grants
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
packages/aws-cdk-lib/aws-dynamodb/lib/private/principal-utils.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import type { IPrincipal } from '../../../aws-iam'; | ||
|
|
||
| /** | ||
| * Returns true if the principal resolves to a Service principal in the policy document. | ||
| * Checks the policyFragment output to handle wrapped principals | ||
| * (e.g. PrincipalWithConditions, SessionTagsPrincipal). | ||
| */ | ||
| export function isServicePrincipal(principal: IPrincipal): boolean { | ||
| const principalJson = principal.policyFragment.principalJson; | ||
| return Object.keys(principalJson).length === 1 && 'Service' in principalJson; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Kinda sounds like that SPs are never allowed here, but elsewhere you have stated at a small limited list of SPs is actually allowed. I don't think we should drop all SPs, but have a allow list.
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.
Yes, there are few SPs documented for DynamoDB resource policies, but they are integration-specific and require their own actions/conditions (e.g. replication.dynamodb.amazonaws.com). The generic
grant*methods add standard data actions (dynamodb:GetItem, dynamodb:PutItem, etc.), which are not the right action set for those service-principal resource policies.So even if we had an allowlist of permitted SPs, the actions being granted by
grant*methods could produce incorrect resource policy which might not fail deployment, but it could still be functionally incorrect.Because of that, I think the right path for SPs is the explicit
addToResourcePolicyAPI, where the caller can provide the correct integration-specific principal, actions, and conditions.