Skip to content

STS: AssumeRole does not evaluate the role's trust policy, so no ExternalId or Principal condition is enforced #593

Closed

Description

@scttfrdmn

Summary

STSPlugin.AssumeRole (emulator/sts_plugin.go) checks that the named role exists in IAM state, and nothing else about the request against it. It never reads the role's AssumeRolePolicyDocument (stored by CreateRole/UpdateAssumeRolePolicy and already used for drift comparison in CloudFormation's policyDocumentsEqual), and never evaluates the calling principal or an sts:ExternalId condition against it.

Net effect: any caller, with any or no ExternalId, can assume any role that exists — the trust policy is stored but decorative.

This is distinct from #411 (closed), which authorizes calls made with an assumed session against the role's permissions policy. That half works. The half missing here is the assumption itself: whether this caller, with this ExternalId, is even allowed to become that role.

Why this matters (concrete, from a real consumer)

A cross-account broker pattern — module A creates a narrow IAM role in account B with a trust policy naming module A's account and requiring a specific sts:ExternalId (the standard confused-deputy defense for third-party/cross-account access) — is untestable against Substrate today for the one property that defense exists to provide: that assumption fails for the wrong caller or the wrong ExternalId. Every AssumeRole call succeeds regardless, so a test exercising this against Substrate would pass whether or not the trust policy's Principal/Condition block was ever rendered correctly, malformed, or omitted entirely.

Proposed capability

  • AssumeRole reads the target role's AssumeRolePolicyDocument and evaluates it as a resource policy against the calling principal (same evaluator IAM/S3-bucket-policy paths already use, presumably), before minting session credentials.
  • sts:ExternalId, evaluated via StringEquals/StringNotEquals conditions the way IAM already evaluates other condition operators, against the ExternalId parameter on the request.
  • A caller that fails the trust check gets AccessDenied — the same undifferentiated denial real AWS gives for "not trusted" and "wrong ExternalId", so a consumer test can assert on that non-distinction rather than on a distinction AWS itself doesn't provide.

Acceptance

  • A role created with a trust policy naming a specific account/principal and an sts:ExternalId condition refuses AssumeRole from a different principal, or with a missing/wrong ExternalId, with AccessDeniedException.
  • The same role accepts AssumeRole from the named principal with the correct ExternalId, and the returned session credentials work as they do today.
  • A role with an unconditional principal trust policy (no ExternalId) continues to accept assumption from that principal, unchanged.

Scope note

Same shape as #411: higher-fidelity emulation of an existing observable (the trust decision + error code AWS actually returns), not workload execution.

Activity

  1. scttfrdmn commented on Aug 9, 2026

    @scttfrdmn
    OwnerAuthor

    Reproduced and fixed. Three of the issue's premises turned out to be false, and each one changed the work materially, so recording them here.

    1. The evaluator this issue assumes exists does not. The issue suggests reusing "the same evaluator IAM/S3-bucket-policy paths already use, presumably". Evaluate in emulator/iam_eval.go never read req.Principal — statementMatches consulted action ∧ resource ∧ condition only. EvaluationRequest.Principal was populated by all four call sites and read by none, which is exactly why a trust policy could name one account and still admit every caller. No principal matcher existed anywhere in the codebase, so building one (Principal/NotPrincipal, "*", exact ARN, bare account ID and account-root delegation, Service, Federated) is the bulk of this fix rather than a wiring exercise.

    The load-bearing constraint: absent Principal must match, because all four existing Evaluate call sites are identity/permission-boundary paths whose documents carry no Principal element — IAM rejects the element there. A mutant flipping that guard to false turns TestAuthController_AssumedRole and TestIAMAuthorize_AgreesWithCheckAccess red, which is the proof it's tested rather than incidental.

    2. UpdateAssumeRolePolicy does not exist in substrate. The issue describes the document as "stored by CreateRole/UpdateAssumeRolePolicy"; there is no such case in the IAM operation switch, so CreateRole is the only way to set a trust policy today and there is no way to change one afterwards. Out of scope here — filed as a follow-up.

    3. The wire code is AccessDenied, not the AccessDeniedException the Acceptance section names. AWS's own CLI output reads An error occurred (AccessDenied) when calling the AssumeRole operation. The botocore STS model documents no access-denied error for AssumeRole at all (only MalformedPolicyDocument, PackedPolicyTooLarge, RegionDisabled, ExpiredToken), so this code is observed behaviour, not modelled, and it gets a ## Provenance note at release. AWS's two documented message forms map exactly onto substrate's two deny decisions:

    • implicit → …is not authorized to perform: sts:AssumeRole because no role trust policy allows the sts:AssumeRole action (DecisionImplicitDeny)
    • explicit → …is not authorized to perform: sts:AssumeRole with an explicit deny in the role trust policy (DecisionDeny)

    A separate follow-up covers the pre-existing generic AccessDeniedException from CheckAccess, which stays as it is — narrowing it for STS is a service-wide consumer-visible change, not part of this fix.

    The four paths, reproduced then re-run against the fix

    Measured with a live server and the real CLI. A role trusting account 111111111111 with StringEquals sts:ExternalId secret-123, assumed as a signed IAM user already granted sts:AssumeRole (so the #411 identity gate passes first — that success was precisely the defect: the identity gate passed and there was no trust gate behind it). Before: all four returned ASIA… credentials. After:

    path before after
    no ExternalId ASIA… AccessDenied, implicit-deny wording
    wrong ExternalId ASIA… AccessDenied
    right ExternalId, caller outside the trusted account ASIA… AccessDenied
    {"Effect":"Deny","Principal":"*","Action":"sts:AssumeRole"} ASIA… AccessDenied, explicit-deny wording
    negative control — policy admitting this caller, right ExternalId ASIA… ASIA… (still works)

    Without that last row the suite would pass for a rule that denies everything.

    Decisions worth knowing

    A trust policy is the opt-in; a role without one stays unenforced. A zero-value AssumeRolePolicyDocument means "not configured", so AssumeRole on such a role behaves exactly as before. This is the documented docs/testing-guide.md rule — existence in state is the opt-in — one level down: there enforcement starts when the principal exists, here when the role carries a trust policy. Strict fidelity would treat an empty document as an implicit deny, but AWS's CreateRole requires a trust policy, a state substrate permits, so denying it would refuse roles that cannot exist on AWS. A nil ctx.Principal is unenforced for the same reason CheckAccess returns nil on one: an unauthenticated caller resolves to no ARN, so there is nothing for a Principal element to be true of.

    The trust policy is evaluated before any credential is minted. Checking after would leave a usable session in state behind a 403; there's a test asserting the session store is empty after a denial.

    CFN is unaffected — cfnAttribution.resolve uses a service role ARN directly rather than running through AssumeRole, so no stack deploy passes the new gate.

    Blast radius is narrow. No existing test both set a trust policy and assumed that role; all five pre-existing sts_plugin_test.go AssumeRole tests pass unchanged, which is the opt-in decision stated as an executable claim.

    Verification

    gofmt, go build, go vet, golangci-lint (0 issues), make test (race), make coverage (emulator 81.5%, total 80.7%), make docs-reference-check docs-versions, the docs site build, and go test -C test/e2e all green. A real-SDK e2e journey asserts AccessDenied without the ExternalId and ASIA… credentials with it on the same role. Eight mutants — including one restoring this bug exactly — were all CAUGHT.

  2. added
    type: bug
    area: iam
    area: server
    on Aug 9, 2026
  3. added this to the v0.95.0 milestone on Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: iamarea: servertype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions