Add condition for sts:AssumeRole of the lambda principal to be from within the correct source account#13125
Add condition for sts:AssumeRole of the lambda principal to be from within the correct source account#13125gligorkot wants to merge 3 commits intoserverless:mainfrom
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
…ithin the correct source account
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughA Condition was added to the IAM role trust policy requiring Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/serverless/lib/plugins/aws/package/lib/iam-role-lambda-execution-template.json (1)
13-17: Add regression tests to lock in the new trust-policy guard.Good security hardening, but there’s no unit assertion proving this
Conditionsurvives downstream trust-policy mutations (notably inpackages/serverless/lib/plugins/aws/package/lib/roles-per-function-permissions.js, Line 336-377). Please add/extend tests to assertaws:SourceAccountis present after role construction paths.Suggested test assertion shape
AssumeRolePolicyDocument: { Statement: [ { Effect: 'Allow', Principal: { Service: 'lambda.amazonaws.com' }, Action: 'sts:AssumeRole', + Condition: { + StringEquals: { + 'aws:SourceAccount': { Ref: 'AWS::AccountId' }, + }, + }, }, ], }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/serverless/lib/plugins/aws/package/lib/iam-role-lambda-execution-template.json` around lines 13 - 17, Add unit tests that assert the trust-policy Condition "StringEquals":{"aws:SourceAccount":{ "Ref":"AWS::AccountId"}} is retained after role construction and any downstream mutations; specifically extend or add tests around the role construction pipeline that exercises the code in roles-per-function-permissions.js (the logic around Line 336-377) and the template defined in iam-role-lambda-execution-template.json so the final generated role/trust policy contains aws:SourceAccount in the Condition. In the test, construct the role via the same function/class used in packaging (invoke the role creation path that consumes iam-role-lambda-execution-template.json and passes through roles-per-function-permissions.js), then assert the resulting CloudFormation trust policy JSON includes the aws:SourceAccount Condition on the principal/sts:AssumeRole statements; fail the test if that key is missing or altered.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@packages/serverless/lib/plugins/aws/package/lib/iam-role-lambda-execution-template.json`:
- Around line 13-17: Add unit tests that assert the trust-policy Condition
"StringEquals":{"aws:SourceAccount":{ "Ref":"AWS::AccountId"}} is retained after
role construction and any downstream mutations; specifically extend or add tests
around the role construction pipeline that exercises the code in
roles-per-function-permissions.js (the logic around Line 336-377) and the
template defined in iam-role-lambda-execution-template.json so the final
generated role/trust policy contains aws:SourceAccount in the Condition. In the
test, construct the role via the same function/class used in packaging (invoke
the role creation path that consumes iam-role-lambda-execution-template.json and
passes through roles-per-function-permissions.js), then assert the resulting
CloudFormation trust policy JSON includes the aws:SourceAccount Condition on the
principal/sts:AssumeRole statements; fail the test if that key is missing or
altered.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 669c0133-a843-4bcd-87d9-d5add7c0fb9f
📒 Files selected for processing (1)
packages/serverless/lib/plugins/aws/package/lib/iam-role-lambda-execution-template.json
This PR implements the change to update the default IAM Lambda execution role, by adding a condition that the assumer of the role comes from within the same AWS Account that the role is deployed in. From a security point of view this seems like a good idea for this to be the default option.
Closes: #13124
Summary by CodeRabbit
Bug Fixes
Tests