Skip to content

Make cross-account reads act as the caller, not as the Lambda - #857

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/815-caller-credentials
Oct 11, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/815-caller-credentials

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Closes #815. Security audit 2026-10. Option (B) from the recommendation, per your
approval.

It needs no IAM change — both halves were already correct

The member-account role's trust names Cognito_SpawnDashboard_Auth_Role, and that role
already 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.go built one aws.Config from this Lambda's own
credentials and passed it to every handler, so getEC2ClientForRegion's AssumeRole was
attributed to the Lambda:

$ aws iam simulate-principal-policy --action-names sts:AssumeRole \
    --resource-arns arn:aws:iam::435415984226:role/SpawnDashboardCrossAccountReadRole
  Cognito_SpawnDashboard_Auth_Role -> allowed
  SpawnDashboardLambdaRole         -> implicitDeny

That is why the feature has never worked. getUserFromCredentialsHeader already validated
the 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 in
the 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 errNoCallerCredentials
rather 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:

revert caught by
STS built with the Lambda's credentials again TestAssumeRoleUsesTheCallerNotTheLambda
nil guard removed TestCrossAccountReadRefusesWithoutCallerCredentials
provider declared after the first early return TestUnvalidatedCallersAreNotActableAs
provider built before the JSON is parsed same

The 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 nil and the
declaration 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, semgrep 0 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.

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
@scttfrdmn scttfrdmn added this to the Security audit 2026-10 milestone Oct 11, 2026
@codecov

codecov Bot commented Oct 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit ac6207a into main Oct 11, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the fix/815-caller-credentials branch October 11, 2026 23:50
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.

Dashboard cross-account EC2 reads have never worked: the role it assumes is not granted

1 participant