Repository navigation
fix(iam): publish the caller's unique ID and tags as condition keys (#771) - #800
Merged
Merged
Conversation
…771) `authzPrincipalContext` published `aws:PrincipalArn` and `aws:username` and nothing else, so a policy conditioning on `aws:userid` or `aws:PrincipalTag/<key>` was evaluated against a context that did not hold the key: a `StringEquals` on either silently refused a caller who should have been allowed, and a `Deny` guarded by one silently allowed a caller it was written to stop. Both keys are now recorded rather than derived, per #745's rule. `aws:userid` arrives in AWS's documented per-kind form — an IAM user's `AIDA…`, and `<role-id>:<session-name>` for an assumed role — because the pairing is known only to the `AssumeRole` call that made it: the session's ARN carries the role's *name*, so nothing downstream could reassemble it. `IAMAccessKey.UserID` and `STSSessionCredentials.PrincipalID` carry the value from where the credential is minted to where it is resolved. Tags are read from the entity's own record on each request instead, because `TagUser` and `UntagUser` change them after a key exists: a snapshot taken at `CreateAccessKey` time would authorize a long-lived key against tags its user no longer has. That costs one extra `Get` on a signed request that resolves to an IAM entity, and `resolvePrincipal`'s doc comment — which claimed one Get — now says so. An empty value publishes *no key*, which is the #737/#745 fallback shape: a record written before this change, and a credential with no IAM entity behind it, leave the key absent where a policy can test it with `Null`, rather than guessing a value that would silently match or silently refuse. Two limits are stated rather than implied. Substrate models no account-root principal, so AWS's root form has no site here — an unauthenticated caller is a nil `*Principal`, which `CheckAccess` leaves unenforced. And session tags are not modeled: `AssumeRole` reads no `Tags` parameter, so an assumed role's `aws:PrincipalTag` is the *role's* own tags. Both authorization doors get the keys from the single existing `authzPrincipalContext` call site, and policy-variable substitution needed no change — `${aws:PrincipalTag/team}` resolves through `condResolveKey` like any other single-valued key. A test asserts each of those rather than claiming it. Closes #771.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
authzPrincipalContextpublishedaws:PrincipalArnandaws:usernameand nothing else, so a policy conditioning onaws:useridoraws:PrincipalTag/<key>was evaluated against a context that did not hold the key. That fails in both directions: aStringEqualson either silently refused a caller who should have been allowed, and aDenyguarded by one silently allowed a caller it was written to stop.Recorded, not derived
Per #745's rule, each value is written where it is known and read where it is resolved — never parsed back out of a principal ARN.
aws:useridarrives in AWS's documented per-kind form: an IAM user'sAIDA…, and<role-id>:<session-name>for an assumed role. The pairing is known only to theAssumeRolecall that made it — the session's ARN carries the role's name, not its ID, and the role record it would have to be read back from may since have been deleted or replaced with a new ID. SoAssumeRolerecords the value it already computes forAssumedRoleId, andGetSessionTokenrecords the calling user's ownAIDA…, since its principal is that user unchanged.IAMAccessKey.UserIDandSTSSessionCredentials.PrincipalIDcarry it from the mint to the gate.Tags go the other way — read per request, not recorded.
TagUserandUntagUserchange them after a key exists, so a snapshot taken atCreateAccessKeytime would authorize a long-lived key against tags its user no longer has.iamPrincipalTagsreads the entity's own record instead. That costs one extraGeton a signed request that resolves to an IAM entity, andresolvePrincipal's doc comment — which claimed one Get — now says two and why. A read that fails yields no tags and therefore denies a statement conditioned on one: the opposite direction fromresolveIAMEntity, deliberately, because a tag substrate could not read is a grant it cannot justify.Absent is not empty
An empty value publishes no key at all — the #737/#745 fallback shape. A record written before this change, and a credential resolved from the registry with no IAM entity behind it, leave the key absent, where a policy can test it with
Null. A guessed value would silently match or silently refuse.Two limits, stated
aws:useridas the account ID, but substrate models no root caller: an unauthenticated request is a nil*Principal, whichCheckAccessleaves unenforced, andsts:GetCallerIdentitysynthesizes…:rootfor that one response. So the plan's root arm has no implementation site, and the gap is documented inPrincipal.UserID,docs/services.mdand the CHANGELOG rather than invented.AssumeRolereads noTagsparameter, so an assumed role'saws:PrincipalTagis the role's own tags where AWS would also publish whatever the session passed. A narrowing, in the subset direction.aws:PrincipalAccountis still deliberately absent — it is the one caller key needing a derivation this function cannot make honestly, since a cross-account credential makes "the principal's account" ambiguous between the ARN's and the one the request resolved to. Tracked separately rather than left as an unstated gap.Both doors, and substitution
authzPrincipalContextis the single call site both authorization doors share, soAuthController.CheckAccessandIAMPlugin.authorizeWithget the keys together; a table test drives both and asserts they agree. Policy-variable substitution needed no code change —${aws:PrincipalTag/team}resolves throughcondResolveKeylike any other single-valued key — and a test asserting an S3 ARN ofreports-${aws:PrincipalTag/team}/*proves it rather than the PR claiming it.Provenance
The per-kind forms come from AWS's IAM policy elements: Variables and tags reference, quoted in the code and in the test file so they are cited rather than asserted. Publishing no key for a credential with no IAM entity is substrate's own choice, on #745's stated principle.
Tests
11 new tests in
emulator/principal_userid_tags_test.go, including: the exact key set published per principal kind (asserted by length, so no extra key can appear); theAIDA…matching whatGetUserrenders; the assumed-role pairing matchingAssumedRoleUser.AssumedRoleId; tags following the entity acrossTagUser/UntagUserwith one unchanged access key; a pre-#771 record publishing nothing;Nullseeing the newly published keys; and both doors agreeing.Verification
gofmt -l .,go build ./...,go vet ./...,golangci-lint run ./...clean;make testandGOTOOLCHAIN=go1.26.6 make testpass (0 failures);GOTOOLCHAIN=go1.26.6 make coverageholds emulator at 83.5%;make docs-reference-check docs-versions authz-reference-check,npm --prefix docs run build, andgo vet -C test/e2e ./... && go test -C test/e2e ./...all pass.Closes #771.