fix(secretsmanager): add fallback grants for cross-account secrets#35478
fix(secretsmanager): add fallback grants for cross-account secrets#35478puretension wants to merge 5 commits intoaws:mainfrom
Conversation
Signed-off-by: puretension <rlrlfhtm5@gmail.com>
…t secrets Signed-off-by: puretension <rlrlfhtm5@gmail.com>
…secrets Signed-off-by: puretension <rlrlfhtm5@gmail.com>
…grants Signed-off-by: puretension <rlrlfhtm5@gmail.com>
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
|
Hi team — just a gentle follow-up on this PR (#35478). |
From my analysis, this PR does nothing (i.e. the resulting template is the same as before). See my comment on the issue: #35476 (comment) |
Issue # (if applicable)
Closes #35476
Reason for this change
When using
Secret.fromSecretAttributesfor cross-account registry credentials in ECS, the standardgrantReadmechanism fails to attach policies to the task execution role, causing authentication failures when pulling container images.Description of changes
Added fallback logic in Secret.grantRead() and Secret.grantWrite() methods:
• When autoCreatePolicy is false and no principal statement is created, use Grant.addToPrincipal() as fallback
• Ensures cross-account secrets can grant permissions to ECS task execution roles
• Maintains backward compatibility - only activates for imported secrets when standard grants fail
Describe any new or updated permissions being added
No new permissions added. The fallback uses the same IAM actions as the standard grant:
• Read:
secretsmanager:GetSecretValue,secretsmanager:DescribeSecret• Write:
secretsmanager:PutSecretValue,secretsmanager:UpdateSecret,secretsmanager:UpdateSecretVersionStageDescription of how you validated changes
Unit Tests:
• Added cross-account-grants.test.ts with tests for grantRead() and grantWrite()
• Tests verify managed policy creation for cross-account scenarios
• All tests pass: yarn jest --testPathPattern
aws-secretsmanager/test/cross-account-grants.test.tsVerification:
• Fallback triggers when autoCreatePolicy is false and !result.principalStatement
• Generated CloudFormation includes correct AWS::IAM::Policy resources
• Cross-account secrets now properly grant permissions to ECS task execution roles
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license