Skip to content

fix(lambda): read the execution role's trust policy in the role's account - #2637

Merged
vieiralucas merged 6 commits into
mainfrom
fix-lambda-role-trust-account
Oct 1, 2026
Merged

vieiralucas merged 6 commits into
mainfrom
fix-lambda-role-trust-account

Conversation

@vieiralucas

@vieiralucas vieiralucas commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Summary

  • validate_execution_role looked the role's trust policy up in the caller's account. For another account's role ARN (accepted with IAM off or --iam soft), a same-named role in the caller's account was checked instead of the role the ARN names. It now resolves the role in the account its ARN names (falling back to the caller's when it names none), mirroring fakecloud_ecs::validate_task_role from ECS credentials endpoint returns static credentials instead of a task-role session #2601.
  • Lambda, unlike ECS, mints the execution session in the function's account (session_role_arn, deliberate since feat(lambda): give function containers the AWS environment #2562 so 000000000000 templates route SDK calls to the function's account). So for a cross-account role the same-named role in the function's account, the one actually assumed, must also trust Lambda. Both checks run; the re-homing (role_in_account) is shared between the check and the minting so they cannot drift.
  • CreateFunction, UpdateFunctionConfiguration and CloudFormation AWS::Lambda::Function share the function, so all three are fixed.
  • --iam strict is unchanged and matches ECS's structure: another account's role is refused before any trust policy is read (Lambda's AccessDeniedException: Cross-account pass role is not allowed.); soft audits and allows.
  • Swept other services: only Lambda and ECS call RoleTrustValidator::validate; no other service has this bug.
  • Lambda service docs say which trust policies are read.

Test plan

  • cargo test -p fakecloud-lambda --lib: another_accounts_role_is_checked_against_its_own_trust_policy (two accounts, same-named role, each trust combination, strict mode asserts the validator is never consulted), create_and_update_function_check_both_accounts_roles (CreateFunction + UpdateFunctionConfiguration handlers), trust_check_runs_in_the_roles_account (lookup accounts + no-account fallback), role_in_account_rehomes_only_arns_naming_an_account, session_is_minted_in_the_function_account
  • cargo test -p fakecloud-cloudformation --lib lambda_function_role: lambda_function_role_trust_is_read_in_both_accounts with real IAM state holding role/app in two accounts; confirmed the foreign-untrusting case fails with the old lookup
  • cargo clippy --workspace --all-targets -- -D warnings, cargo fmt --all --check

Closes #2634

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation matches the established ECS behavior and includes focused regression coverage for every affected Lambda path.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes Lambda cross-account execution-role validation by reading the trust policy from the role owner’s account.

Changes:

  • Resolves trust validation using the role ARN’s account.
  • Adds Lambda and CloudFormation regression coverage.
  • Clarifies Lambda service documentation.
File Description
website/​content/​docs/​services/​lambda.md Documents trust-policy account resolution.
crates/​fakecloud-lambda/​src/​service/​mod.rs Fixes execution-role validation.
crates/​fakecloud-lambda/​src/​service/​functions.rs Updates PassRole commentary.
crates/​fakecloud-lambda/​src/​service_tests.rs Tests create, update, strict, and cross-account behavior.
crates/​fakecloud-cloudformation/​src/​resource_provisioner/​mod.rs Tests CloudFormation’s cross-account role handling.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 5 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread crates/fakecloud-lambda/src/service_tests.rs Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation consistently validates both relevant roles and includes focused coverage for all affected paths.

Review effort: Balanced
Findings: None

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 5 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread crates/fakecloud-lambda/src/service_tests.rs Outdated
Comment thread crates/fakecloud-lambda/src/service_tests.rs

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation consistently fixes all shared Lambda paths and includes focused regression coverage.

Review effort: Balanced
Findings: None

…ount

validate_execution_role looked a role's trust policy up in the caller's
account, so for another account's role ARN (allowed with IAM off or
soft) a same-named role in the caller's account was checked instead of
the role the ARN names. Resolve the role in the account its ARN names,
falling back to the caller's when it names none, as ECS's
validate_task_role does. CreateFunction, UpdateFunctionConfiguration and
CloudFormation AWS::Lambda::Function share the check. Strict mode still
refuses another account's role before the trust policy is read.

Closes #2634
A cross-account execution role is minted in the function's account (as
the same-named role there), so with IAM off or soft that role's trust
policy must allow Lambda too, not only the one the ARN names. Share the
re-homing between the trust check and the session minting.
@vieiralucas
vieiralucas force-pushed the fix-lambda-role-trust-account branch from 1341913 to 5b2218f Compare October 1, 2026 17:20
@vieiralucas
vieiralucas requested a balanced review from Copilot October 1, 2026 17:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Accountless role ARNs still cause validation and credential minting to use different accounts.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)

Comment thread crates/fakecloud-lambda/src/service/mod.rs Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation is consistent and well tested; only a non-blocking inline documentation mismatch remains.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
Resolved since last review (1)

Comment thread crates/fakecloud-lambda/src/service/functions.rs Outdated
@vieiralucas
vieiralucas requested a balanced review from Copilot October 1, 2026 17:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@vieiralucas
vieiralucas merged commit 2de5564 into main Oct 1, 2026
158 checks passed
@vieiralucas
vieiralucas deleted the fix-lambda-role-trust-account branch October 1, 2026 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lambda execution-role trust check looks up cross-account roles in the caller's account

2 participants