Skip to content

fix(iam): evaluate the principals that exist, and stop guessing at the rest (#411) - #571

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/411-assumed-role-evaluator
Aug 5, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/411-assumed-role-evaluator

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Second of four PRs for v0.92.0. PR A (#570) made a signed request resolve to the
principal it actually is; this makes the evaluator answer correctly for the
principals that resolve, and refuse to guess about the rest.

Does not close #411 — the CloudFormation half (RouteRequest never calls
CheckAccess, so the whole IaC path is unauthorized) lands in PR C.

The fail-open

arn:aws:sts::123456789012:assumed-role/worker/sess1 was allowed with no
policies at all
. loadPoliciesForPrincipal returned an error for any entity
type outside user/role, and CheckAccess fails open on an error, so the two
lines conspired to invert the safe default for exactly the callers a scoped role
exists to constrain. This is not an obscure shape: it is what AssumeRole mints,
so every "call as a role" reduced to it — and PR A, by making STS session
credentials resolve at all, turned it from unreachable into live. Measured against
main after PR A: AWS_ACCESS_KEY_ID=ASIA… aws sqs list-queues with no role
policy returned {"QueueUrls": []}.

A session now resolves to its role, as IAM does. The session name has to be
split off: parsePrincipalARN splits on the first slash, so without that the
lookup is role_policies:worker/sess1 — a key nothing is ever stored under, which
would have made every session of a role a distinct nameless entity. A permission
boundary resolves through the same path, because otherwise switching enforcement
on for these principals would have switched their boundaries off.

One ARN, one answer

IAMPlugin.authorize denied an entity type it did not handle where
AuthController.CheckAccess allowed it, so a caller's permission depended on
which service it happened to call. Both now route through one resolveIAMEntity,
which separates three cases the old single error had conflated:

case before after
entity resolves and exists in state evaluated evaluated (no policies → implicit deny, as on AWS)
entity resolves to nothing in state CheckAccess allowed, authorize denied not enforced, Debug
a state read genuinely fails (I/O) fails open, Warn fails open, Warn — unchanged

The last row is the one worth being deliberate about. It stays permissive and
loud: a storage fault is not an unknown caller, and reporting it as
AccessDeniedException would hand a consumer's retry loop a permanent-looking
answer to a transient problem. That distinction is only worth anything if it is
tested, so it is — see M5 below, which survived the first mutation run and is why
TestAuthController_StateFailureFailsOpen exists.

Existence in state remains the opt-in, so a session naming a role substrate does
not hold is unenforced, and every caller that never touched IAM is unaffected.

Tests

emulator/authz_assumed_role_test.go, table-driven, no clock or network.

  • an assumed-role whose role holds no policy is denied; with an sqs:ListQueues
    role policy it is allowed; and it is denied sqs:CreateQueue
  • a dotted/slashed session name still resolves to the role
  • a permission boundary applies through the role
  • a session whose role does not exist is not enforced (the opt-in)
  • a user that exists with no policies is denied; user/role that do not
    exist, an account root, a service principal and a federated user are all
    unenforced
  • IAMPlugin.authorize and CheckAccess agree on the same ARN in all three cases
  • a state-store failure fails open

Baselined at PR A's merge commit (3916ef6) in a throwaway worktree: 9 of 14
subtests fail there.
The five that pass at baseline pass vacuously — the
fail-open allowed them — which is what the mutation set below is for.

One existing test changed: TestCheckAccess_NoPermissionsRequiredActions now
builds state where alice exists, because a jointly-empty state manager would
make every case pass for the wrong reason once absence means unenforced.

Mutation testing — 8/8 caught

Occurrence-count asserted before applying, gofmt+go vet gate, -race,
green-baseline pre-flight.

# mutant verdict
1 the assumed-role case removed (fail-open restored) CAUGHT
2 session not split off the name → loads role_policies:worker/sess1 CAUGHT
3 "entity does not exist" denies instead of not enforcing CAUGHT
4 the existence check dropped entirely CAUGHT
5 a state-read failure denies instead of failing open CAUGHT (after a rewrite — see below)
6 boundary loaded under the wrong entity kind CAUGHT
7 IAMPlugin.authorize denies where CheckAccess allows CAUGHT (after a rewrite)
8 the policy-list key drops the entity kind CAUGHT

Two needed a second pass, both worth recording. M5 SURVIVED the first run:
nothing covered the I/O fail-open, so the arm this PR deliberately preserves was
untested — the test above was written in response. M7 was BROKEN, not caught:
go vet rejected it as unreachable code, and a mutant that does not build measures
nothing, so it was rewritten to mutate the condition rather than insert a return.

Verification

gofmt -l ., go build ./..., go vet ./..., golangci-lint run ./... → 0
issues
, make test (race) green, make docs-reference docs-reference-check docs-versions (no plugin added or removed), go vet -C test/e2e ./...,
go test -C test/e2e ./....

Live against substrate server --address :4655, one server, both callers:

AKIAIOSFODNN7EXAMPLE      sqs create-queue plain     → 200          (unenforced, unchanged)
assumed-role/worker/sess1 sqs list-queues            → AccessDeniedException   (was 200)
assumed-role/reader/sess2 sqs list-queues            → 200          (inline role policy allows)
assumed-role/reader/sess2 sqs create-queue           → AccessDeniedException
assumed-role/worker/sess1 sts get-caller-identity    → 200          (no permissions required)

Refs #411.

…e rest (#411)

An assumed-role principal was allowed with no policies at all.
loadPoliciesForPrincipal treated any entity type outside user/role as an error
and CheckAccess failed open on an error, so arn:aws:sts::…:assumed-role/worker/
sess1 — the shape STS itself mints, and therefore what every "call as a role"
reduces to — was authorized unconditionally. The safe default was inverted for
exactly the callers a scoped role exists to constrain.

A session now resolves to its role, as real IAM resolves one: the session name is
split off so managed and inline role policies are found under the keys IAM writes,
rather than under a per-session name nothing is stored beneath. A permission
boundary resolves through the same path, else switching enforcement on for these
principals would have switched their boundaries off.

The two loaders also disagreed about one ARN: IAMPlugin.authorize denied an
entity type it did not handle where CheckAccess allowed it, so a caller's
permission depended on which service it happened to call. Both now route through
one resolver, which distinguishes the three cases the old error had conflated —
an entity that exists is evaluated (no policies is an implicit deny, as on AWS),
one that resolves to nothing is unenforced and logged at debug, and a state read
that genuinely fails still fails open with a warning. Only the last is a broken
backend, and only it should be loud.

Existence in state stays the opt-in, so a session naming a role substrate does
not hold is unenforced and every caller that never touched IAM is unaffected.

Verified over the wire: a session of a policy-less role is denied where PR A left
it allowed, the same session with an sqs:ListQueues role policy is allowed and is
denied sqs:CreateQueue, and AKIAIOSFODNN7EXAMPLE still passes unenforced against
the same server. 8/8 mutants caught, including the fail-open restored, the
session not split off the name, and the I/O arm denying instead of failing open.
@codecov

codecov Bot commented Aug 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.58333% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/authz.go 91.89% 1 Missing and 2 partials ⚠️
emulator/iam_plugin.go 81.81% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

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.

Principal-aware test mode: enforce IAM authorization in composition tests

1 participant