Skip to content

fix(iam): publish the caller's unique ID and tags as condition keys (#771) - #800

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/iam-principal-id-and-tags
Sep 11, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/iam-principal-id-and-tags

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

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. That fails in both directions: 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.

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:userid arrives in AWS's documented per-kind form: an IAM user's AIDA…, and <role-id>:<session-name> for an assumed role. The pairing is known only to the AssumeRole call 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. So AssumeRole records the value it already computes for AssumedRoleId, and GetSessionToken records the calling user's own AIDA…, since its principal is that user unchanged. IAMAccessKey.UserID and STSSessionCredentials.PrincipalID carry it from the mint to the gate.

Tags go the other way — read per request, not recorded. TagUser and UntagUser change them after a key exists, so a snapshot taken at CreateAccessKey time would authorize a long-lived key against tags its user no longer has. iamPrincipalTags reads the entity's own record instead. 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 two and why. A read that fails yields no tags and therefore denies a statement conditioned on one: the opposite direction from resolveIAMEntity, 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

  • No account-root principal. AWS documents root's aws:userid as the account ID, but substrate models no root caller: an unauthenticated request is a nil *Principal, which CheckAccess leaves unenforced, and sts:GetCallerIdentity synthesizes …:root for that one response. So the plan's root arm has no implementation site, and the gap is documented in Principal.UserID, docs/services.md and the CHANGELOG rather than invented.
  • Session tags are not modeled. AssumeRole reads no Tags parameter, so an assumed role's aws:PrincipalTag is the role's own tags where AWS would also publish whatever the session passed. A narrowing, in the subset direction.

aws:PrincipalAccount is 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

authzPrincipalContext is the single call site both authorization doors share, so AuthController.CheckAccess and IAMPlugin.authorizeWith get the keys together; a table test drives both and asserts they agree. Policy-variable substitution needed no code change — ${aws:PrincipalTag/team} resolves through condResolveKey like any other single-valued key — and a test asserting an S3 ARN of reports-${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); the AIDA… matching what GetUser renders; the assumed-role pairing matching AssumedRoleUser.AssumedRoleId; tags following the entity across TagUser/UntagUser with one unchanged access key; a pre-#771 record publishing nothing; Null seeing the newly published keys; and both doors agreeing.

Verification

gofmt -l ., go build ./..., go vet ./..., golangci-lint run ./... clean; make test and GOTOOLCHAIN=go1.26.6 make test pass (0 failures); GOTOOLCHAIN=go1.26.6 make coverage holds emulator at 83.5%; make docs-reference-check docs-versions authz-reference-check, npm --prefix docs run build, and go vet -C test/e2e ./... && go test -C test/e2e ./... all pass.

Closes #771.

…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.
@scttfrdmn scttfrdmn added this to the v0.111.0 milestone Sep 11, 2026
@codecov

codecov Bot commented Sep 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.61905% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/authz.go 94.11% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit d089802 into main Sep 11, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the feat/iam-principal-id-and-tags branch September 11, 2026 04:06
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.

iam: produce aws:userid and aws:PrincipalTag/, the two caller keys still without a producer

1 participant