Repository navigation
fix(iam): resolve a signed request to the principal it actually is (#411) - #570
Merged
Merged
Conversation
) The server derived a caller's principal ARN from its access key ID, yielding arn:aws:iam::123456789012:user/AKIATEST12345678901 — a name nothing is ever stored under. A user alice holding an inline sqs:* Allow was allowed as user/alice and denied as user/AKIATEST…, so authorization could not find any real principal's policies even where it ran. #411's acceptance ("create a role with a scoped policy, make a call as that role") was unreachable in principle, not merely unwired. A caller is now resolved from state: iam:accesskey:<id> names the user whose policies apply — the record CreateAccessKey has always written — and sts:session:<id> names the assumed-role ARN AssumeRole mints, a key substrate wrote from the beginning and nothing had ever read. Resolution is deliberately independent of ServerOptions.Credentials. That registry also gates SigV4 verification, and a key absent from it is rejected with InvalidClientTokenId; identifying callers through it would have 403'd every credential substrate documents. Reading state costs one Get on a request that carries an Authorization header, and refuses nothing. An STS session also now carries the account it was issued for: account resolution recognizes only an AKIA prefix as the test account, so an ASIA session key was filed under 000000000000 — a different partition from the resources the caller who assumed the role had just created. Two STS operations are exempted from evaluation, which is only reachable now. AWS documents GetCallerIdentity as answering even against an explicit Deny (a denial returns the same information) and GetSessionToken as authenticating via MFA, which policies cannot gate. A sweep of every botocore service model finds the phrase on these two and nothing else. Before this change no caller resolved to a principal, so the evaluator never ran and neither was denied; the first credential naming a real IAM user had `aws sts get-caller-identity` return AccessDeniedException. A key belonging to no IAM entity resolves to no principal and is enforced against nothing: existence in state is the opt-in, so no flag turns this on and every caller that never touched IAM is unaffected. Ten mutants CAUGHT, including the fixed bug itself (the IAM branch renamed to buildCallerARN), the STS branch dropped, the session account not adopted, and the registry fallback applied unconditionally — which 403s AKIAIOSFODNN7EXAMPLE at the first call, the hazard the registry-hit gate exists for.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 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.
First of four PRs for v0.92.0. This one makes a signed request resolve to the principal it actually is; the evaluator fixes, CloudFormation's service role, and the docs follow in B, C and D.
Refs #411.
The defect
buildCallerARNderived a principal ARN from the access key ID, producingarn:aws:iam::123456789012:user/AKIATEST12345678901. Nothing is ever stored under that name — IAM writes policies underuser_policies:<UserName>— so a useraliceholding an inlinesqs:*Allow was:arn:aws:iam::123456789012:user/alicearn:aws:iam::123456789012:user/AKIATEST…Authorization therefore could not find any real principal's policies even on the one path where it ran. #411 has been deferred six times as "wire a principal into a test"; it was not reachable in principle.
The fix
A caller is resolved from state, in
resolvePrincipal:iam:accesskey:<id>→IAMAccessKey.UserName→arn:aws:iam::<acct>:user/<UserName>. This is the recordCreateAccessKeyhas always written.sts:session:<id>→STSSessionCredentials.PrincipalARN, theassumed-roleARNAssumeRolemints. Substrate wrote that key from the beginning and nothing had ever read it, which is why STS session credentials authorized as nothing in particular.Why this is decoupled from
CredentialRegistryThe obvious fix — wire
Credentialsinto the server so it can identify callers — is the trap.VerifySigV4runs wheneverCredentials != nil, and an access key the registry does not hold is rejected withInvalidClientTokenId(403).AKIAIOSFODNN7EXAMPLEis not registered, so a server that identifies callers that way is a server that 403s the README, the testing guide and every e2e check.So the two jobs stay split, the same separation as #529's state-vs-wire types: the registry answers "which account, and is this signature valid"; state answers "which principal". Reading state costs one
Geton a request that carries anAuthorizationheader, and refuses nothing.An STS session's account
extractAccountrecognizes only anAKIAprefix as substrate's test account, so anASIAsession key was filed under000000000000— a different partition from the resources the caller who assumed the role had just created. The session record names the account it was issued for; that is now adopted, unless a wired registry already spoke.sts:GetCallerIdentityandsts:GetSessionTokenneed no permissionsFound by running this change, not by reading a reference. With a real principal resolving for the first time,
aws sts get-caller-identityas a policy-less IAM user returnedAccessDeniedException. AWS documents both operations as requiring none:A sweep of every botocore service model finds the phrase "no permissions are required" on these two operations and nothing else, so the exemption is that pair rather than a general carve-out. It was unreachable before this PR: with every caller resolving to no principal, the evaluator never ran.
What changes for a consumer
A call made with an access key minted by
CreateAccessKeyis now authorized against that user's policies, and can returnAccessDeniedExceptionwhere it previously succeeded. That is real IAM behaviour and the point of the release — the "forgot a permission / policy too narrow" class that spore-host/spawn#70 needed a paid real-AWS smoke to catch.Everything else is unchanged. Existence in state is the opt-in, so there is no configuration flag: a key belonging to no IAM entity resolves to no principal and is enforced against nothing. That covers
AKIAIOSFODNN7EXAMPLE,test/test, the built-in test key, a deleted key, every in-processClientcall, and every test that does not create an IAM principal. Anassumed-roleprincipal is also not yet enforced — that fail-open is PR B.Tests
emulator/principal_resolution_test.go, table-driven, no wall-clock or network dependency. The two positive gates were run against unmodifiedmainin a worktree and both fail there:CreateAccessKeyreaches the plugin asarn:aws:iam::123456789012:user/alice— asserted on the ARN, because a test that only checked non-nil passed before the fix;ASIAkey fromAssumeRolereaches it asarn:aws:sts::123456789012:assumed-role/worker/sess1, in account123456789012;AKIAIOSFODNN7EXAMPLE, the built-in test key, a never-minted key, no header) resolve to no principal and still succeed — these pass onmaintoo, which is what makes them regression gates;sts:AssumeRoleis denied, so the exemption is that pair and not all of STS.Mutation testing
Ten mutants, all CAUGHT. Two earlier attempts were BROKEN (a
perl s///that choked on slashes in the pattern, and agrep -cthat counted lines rather than occurrences) and were rewritten before being counted — a BROKEN mutant measures nothing.buildCallerARN(the fixed bug, restored)registryHitreq.Operationinstead of the actionstsThe unconditional-fallback mutant fails at the setup call with a 403, which is the mechanism worth naming: it makes
AKIAIOSFODNN7EXAMPLEan enforced principal with no policies, so it denies everything. That is exactly the hazard the registry-hit gate exists for.Verification
gofmt -l .,go build ./...,go vet ./...,golangci-lint run ./...→ 0 issues;make test(race) green;make docs-reference docs-reference-check docs-versionsclean (65 plugins, no change);go vet -C test/e2e ./...andgo test -C test/e2e ./...green.Live against
substrate server, with the AWS CLI:The last one is the fail-open this release's PR B closes:
loadPoliciesForPrincipalerrors on any entity type outsideuser/roleandCheckAccessfails open on that error, so an assumed-role is allowed with no policies at all — whileIAMPlugin.authorizedenies in the same case. Two loaders, two opposite answers, one ARN.Not in this PR
PluginRegistry.RouteRequeststill never callsCheckAccess, so a CloudFormation stack's resource calls remain unauthorized. That is PR C, together with #562'sRoleARN.