Skip to content

Authenticate people with OIDC, alongside the service tokens - #12

Merged
sahilkalgutkar merged 1 commit into
mainfrom
feature/oidc-identity
Aug 31, 2026
Merged

sahilkalgutkar merged 1 commit into
mainfrom
feature/oidc-identity

Conversation

@sahilkalgutkar

Copy link
Copy Markdown
Owner

Closes the "no per-user identity" limitation. Static tokens answer which service is calling; they cannot answer which person changed the model scoring production traffic, because everybody holding the credential looks identical.

{"msg":"authorised change","actor":"sahil@example.com","method":"POST",
 "path":"/v1/models","subject":"sub-sahil@example.com",
 "issuer":"https://idp.example.com","kind":"user"}

Both the readable name and the stable sub are recorded — an email makes that line answerable without a directory lookup, a subject still joins correctly after somebody's surname changes.

Why I used a library here and wrote the scorer myself

This repo's whole premise is writing things from the wire up, so the inconsistency is worth defending rather than glossing.

A bug in the XGBoost scorer produces a wrong number, and a differential test against XGBoost catches it. A bug in JWT verification is a total authentication bypass — alg:none, RSA-versus-HMAC confusion, an unchecked kid — and its failure mode is that everything works perfectly while anybody can forge an admin identity. That is not a place to demonstrate that I can write code.

So the tests verify the wiring, not that RSA works: a real RSA key, a real JWKS endpoint served over HTTP, real signed tokens, and assertions that each of these is refused —

  • a token signed with an attacker's key, presented with the real kid
  • a token with claims swapped in under a valid signature
  • an alg:none unsecured token
  • an expired token
  • a token minted for a different audience

A stub returning valid: true would pass a feature-shaped suite while leaving the server forgeable.

The audience is mandatory

There is no "any audience" setting. Skipping it is the classic confused-deputy bug: a provider mints tokens for many services, and one issued for the expense tool would otherwise be a valid credential here. The user is real, the token is real, and they never intended to authenticate against this.

A bug the end-to-end test caught

A user in no mapped group is refused — the alternative is every employee getting whatever the fallback is, on the service that decides which model answers production traffic.

That refusal was returning 401, which is wrong. The holder's signature checked out and their provider vouched for them; telling them to re-authenticate sends a real employee round a loop against a provider that is working perfectly, when the fix is somebody adding them to a group. It is a 403 now, and like a scope failure it does not spend rate-limit budget — a permission problem is not somebody guessing. A forged token does spend budget, and there are tests for both.

Coexistence

A service scoring a thousand requests a second wants a credential it holds, not an interactive login. Both work at once, told apart by shape — a JWS has three dot-separated segments, a minted token has none — so a mistyped static token never has an RSA verification attempted against it.

An OIDC-only deployment (no static tokens at all) is also valid, and tested.

Availability

Discovery runs in the background with backoff. A provider unreachable at startup degrades logins — the process still boots, static credentials still work, the serving path still serves, and JWTs get a clean refusal until discovery succeeds. Refusing to start because an identity provider is down would be a much larger failure than the one it prevents.

Verified live

Against the real binary and a standalone provider: admin/read/outsider users getting 200/200/403, a reader refused 403 on a write, a static token unaffected, and the audit line above. Plus the metric splitting kind="service" from kind="user" — kind, not identity, because a per-user label is unbounded externally-controlled cardinality.

Coverage

91.7% across internal/. internal/auth at 93.8%. Race detector clean.

Static tokens answer which service is calling. They cannot answer which person
changed the model that scores production traffic, because everybody holding the
credential looks identical. Pointing the server at an identity provider makes
the audit log name a human, with both the readable identity and the stable
subject recorded — an email is what makes the line answerable without a
directory lookup, and a subject is what still joins correctly after somebody's
surname changes.

The two coexist deliberately. A service scoring a thousand requests a second
wants a credential it holds, not an interactive login; a person changing what
serves traffic should be named rather than sharing a token. They are told apart
by shape, since a JWS has three dot-separated segments and a minted token has
none, so a mistyped static token never has an RSA verification attempted
against it.

I did not write the JWT verification, and the contrast with the XGBoost scorer
is the point. A bug in the scorer produces a wrong number that a differential
test catches. A bug in JWT verification is a total authentication bypass —
alg:none, RSA-versus-HMAC confusion, an unchecked kid — where everything works
perfectly while anybody can forge an admin identity. The tests verify the wiring
rather than the cryptography: a real key, a real JWKS endpoint over HTTP, real
signed tokens, and assertions that a wrong-key signature, swapped claims,
alg:none, an expired token and a wrong audience are each refused.

The audience is mandatory with no "any" setting, because skipping it is the
confused-deputy bug: a provider mints tokens for many services, and one issued
for another would otherwise be a valid credential here.

A user in no mapped group is refused rather than defaulted into access. Writing
the end-to-end test caught that this was returning 401, which is wrong and
genuinely confusing: the holder's signature checked out and their provider
vouched for them, so telling them to re-authenticate sends a real employee round
a loop against a provider that works, when the fix is somebody adding them to a
group. It is a 403 now, and does not spend rate-limit budget, on the same
reasoning as a scope failure. A forged token still does, because that is
somebody guessing.

Discovery runs in the background with backoff, so a provider being unreachable
degrades logins rather than stopping the server: static credentials keep
working and the serving path keeps serving.

Coverage across internal/ is 91.7%.
@codecov

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.51613% with 26 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/auth/oidc.go 86.30% 17 Missing and 6 partials ⚠️
internal/app/app.go 92.30% 2 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@sahilkalgutkar
sahilkalgutkar merged commit 6bc648f into main Aug 31, 2026
3 checks passed
@sahilkalgutkar
sahilkalgutkar deleted the feature/oidc-identity branch August 31, 2026 19:19
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.

1 participant