Repository navigation
Make cross-account reads act as the caller, not as the Lambda - #857
Merged
Merged
Conversation
The dashboard's cross-account instance listing has never worked, and the fix needs no IAM change: both halves of the intended design were already deployed and correct, and only the code had drifted. The member-account role's trust names Cognito_SpawnDashboard_Auth_Role — the identity-pool role the browser assumes — and that role already carries sts:AssumeRole scoped to exactly the one role ARN. But main.go built a single aws.Config from this Lambda's own credentials and passed it to every handler, so getEC2ClientForRegion's AssumeRole was attributed to the Lambda. Measured: Cognito_SpawnDashboard_Auth_Role -> allowed SpawnDashboardLambdaRole -> implicitDeny getUserFromCredentialsHeader already validates the caller's credentials against STS and then threw them away. They are threaded through now, and the STS client is built with them. That one line is the fix. The obvious repair — add the Lambda role to the trust, grant it sts:AssumeRole — was rejected deliberately. It would create a standing role able to read EVERY onboarded tenant's instances, assumed by a Lambda behind a public API, growing in reach as accounts onboard. That is the shape of GHSA-qc2h-6qqf-wcm4's fail-open ownership check and GHSA-7pm4-cqjg-vh2q's open front door, both fixed earlier in this audit. Acting as the caller inverts it: each user reads their own account with their own permissions and this Lambda holds no cross-tenant access at all. A request that authenticated without usable credentials — the API Gateway IAM path identifies a caller but yields nothing to act with — gets a named refusal instead of falling through to the ambient credential chain, which is this Lambda's role. The role session name carries the caller, so CloudTrail in the member account shows which dashboard user read it rather than one shared identity. Four gates, each watched failing against a compiling revert. One is partly enforced by the compiler already: declaring the credentials provider after the first early return does not build, because those returns reference it — so the gate targets the compiling variant, where the early returns use a literal nil and the declaration drifts later. Closes #815
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Closes #815.
Security audit 2026-10. Option (B) from the recommendation, per yourapproval.
It needs no IAM change — both halves were already correct
The member-account role's trust names
Cognito_SpawnDashboard_Auth_Role, and that rolealready carries the grant, scoped to exactly one ARN:
{ "Sid": "AssumeRoleCrossAccount", "Effect": "Allow", "Action": ["sts:AssumeRole"], "Resource": "arn:aws:iam::435415984226:role/SpawnDashboardCrossAccountReadRole" }Only the code had drifted.
main.gobuilt oneaws.Configfrom this Lambda's owncredentials and passed it to every handler, so
getEC2ClientForRegion's AssumeRole wasattributed to the Lambda:
That is why the feature has never worked.
getUserFromCredentialsHeaderalready validatedthe caller's credentials against STS and then discarded them; they are threaded through
now and the STS client is built with them. One line.
Why not simply add the Lambda grant
That was option (A), and I recommended against it. It would create a standing role able
to read every onboarded tenant's instances, assumed by a Lambda behind a public API, and
growing in reach with each account onboarded.
That is the shape of the two findings this audit fixed earlier: GHSA-qc2h-6qqf-wcm4's
fail-open watch-ownership check, and GHSA-7pm4-cqjg-vh2q's
Principal: "*"DNS front door.Acting as the caller inverts it — each user reads their own account with their own
permissions, and this Lambda holds no cross-tenant access at all.
The role session name carries the caller too (
spawn-dashboard-caller), so CloudTrail inthe member account shows which dashboard user read it rather than one shared identity.
Failing closed
A request that authenticated without usable credentials — the API Gateway IAM path
identifies a caller but yields nothing to act with — gets a named
errNoCallerCredentialsrather than falling through to the ambient credential chain, which is this Lambda's role.
The nil guard is the load-bearing part: without it, a nil provider silently becomes "the
Lambda's default credentials".
Gates
Four, each watched failing against a revert that compiles:
TestAssumeRoleUsesTheCallerNotTheLambdaTestCrossAccountReadRefusesWithoutCallerCredentialsTestUnvalidatedCallersAreNotActableAsThe third is worth a note: the straightforward revert does not compile, because the
early returns reference the variable — so the compiler already enforces it. The gate
targets the compiling variant, where the early returns use a literal
niland thedeclaration drifts later. I checked that rather than claiming a revert that proved nothing.
The last property matters in its own right: handing back a half-built provider from a path
where validation failed would let an unverified caller be acted as — the inverse of the
original bug, and worse.
Verification
make check(all nested modules),make check-docs, changelog gate,semgrep0 findings,Tier 0 e2e with
-count=1, plus the IAM simulations above.No live AWS change in this PR, and none needed — which is the most useful thing it
establishes.