Repository navigation
fix(iam): evaluate the principals that exist, and stop guessing at the rest (#411) - #571
Merged
Merged
Conversation
…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 Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This was referenced Aug 5, 2026
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.
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 (
RouteRequestnever callsCheckAccess, so the whole IaC path is unauthorized) lands in PR C.The fail-open
arn:aws:sts::123456789012:assumed-role/worker/sess1was allowed with nopolicies at all.
loadPoliciesForPrincipalreturned an error for any entitytype outside
user/role, andCheckAccessfails open on an error, so the twolines 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
AssumeRolemints,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
mainafter PR A:AWS_ACCESS_KEY_ID=ASIA… aws sqs list-queueswith no rolepolicy returned
{"QueueUrls": []}.A session now resolves to its role, as IAM does. The session name has to be
split off:
parsePrincipalARNsplits on the first slash, so without that thelookup is
role_policies:worker/sess1— a key nothing is ever stored under, whichwould 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.authorizedenied an entity type it did not handle whereAuthController.CheckAccessallowed it, so a caller's permission depended onwhich service it happened to call. Both now route through one
resolveIAMEntity,which separates three cases the old single error had conflated:
CheckAccessallowed,authorizedeniedDebugWarnWarn— unchangedThe 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
AccessDeniedExceptionwould hand a consumer's retry loop a permanent-lookinganswer 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_StateFailureFailsOpenexists.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.sqs:ListQueuesrole policy it is allowed; and it is denied
sqs:CreateQueueuserthat exists with no policies is denied;user/rolethat do notexist, an account root, a service principal and a federated user are all
unenforced
IAMPlugin.authorizeandCheckAccessagree on the same ARN in all three casesBaselined at PR A's merge commit (
3916ef6) in a throwaway worktree: 9 of 14subtests 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_NoPermissionsRequiredActionsnowbuilds state where
aliceexists, because a jointly-empty state manager wouldmake every case pass for the wrong reason once absence means unenforced.
Mutation testing — 8/8 caught
Occurrence-count asserted before applying,
gofmt+go vetgate,-race,green-baseline pre-flight.
assumed-rolecase removed (fail-open restored)role_policies:worker/sess1IAMPlugin.authorizedenies whereCheckAccessallowsTwo 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 vetrejected it as unreachable code, and a mutant that does not build measuresnothing, so it was rewritten to mutate the condition rather than insert a return.
Verification
gofmt -l .,go build ./...,go vet ./...,golangci-lint run ./...→ 0issues,
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:Refs #411.