fix(secretsmanager): grant KMS decrypt/encrypt directly to grantee in grantRead/grantWrite#37243
Open
saurav61091 wants to merge 4 commits intoaws:mainfrom
Open
fix(secretsmanager): grant KMS decrypt/encrypt directly to grantee in grantRead/grantWrite#37243saurav61091 wants to merge 4 commits intoaws:mainfrom
saurav61091 wants to merge 4 commits intoaws:mainfrom
Conversation
…ndition When creating a CloudTrail Trail with an SNS topic from another account, the deployment fails with InsufficientSnsTopicPolicyException. The previous implementation used grantPublish which doesn't add the required aws:SourceArn condition. Replace grantPublish with an explicit addToResourcePolicy that includes the aws:SourceArn condition, enabling cross-account CloudTrail-to-SNS publishing while also improving security for same-account scenarios. Fixes aws#11387
When using Secret.fromSecretAttributes with an encryptionKey, calling grantRead only granted kms:Decrypt via the ViaServicePrincipal but not directly to the grantee. This meant the grantee's IAM policy lacked the kms:Decrypt permission needed to access the secret. Add grantDecrypt/grantEncrypt directly to the grantee in addition to the existing ViaServicePrincipal grants. Fixes aws#20087
aws-cdk-automation
previously requested changes
Mar 13, 2026
Add integration test verifying that grantRead on a secret with a KMS encryption key correctly adds kms:Decrypt to the grantee's IAM policy.
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
Contributor
|
|
||||||||||||||
Contributor
|
|
||||||||||||||||||
…S guard in integ test The integ test for grantRead with KMS uses AccountRootPrincipal as the assumed-by principal for a test role, which triggered the security guard rule IAM_ROLE_ROOT_PRINCIPAL_NEEDS_CONDITIONS. Added the guard suppression metadata to both the integ test source and the snapshot since the root principal is intentional for this test-only role.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
When using
Secret.fromSecretAttributeswith anencryptionKey, callingsecret.grantRead(role)only grantedkms:DecryptviaViaServicePrincipalbut not directly to the grantee's IAM policy. This meant the IAM role lacked thekms:Decryptpermission needed to actually read the secret value.Fix
Added
this.encryptionKey.grantDecrypt(grantee)ingrantReadandthis.encryptionKey.grantEncrypt(grantee)ingrantWrite, in addition to the existingViaServicePrincipalgrants. This mirrors how DynamoDB'sgrantReadDatahandles KMS keys.Testing
Updated existing tests to verify the KMS policy statements are added to the grantee's IAM policy.
Fixes #20087
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license