Repository navigation
Authenticate people with OIDC, alongside the service tokens - #12
Merged
Merged
Conversation
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 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.
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.
Both the readable name and the stable
subare 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 uncheckedkid— 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 —
kidalg:noneunsecured tokenA stub returning
valid: truewould 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"fromkind="user"— kind, not identity, because a per-user label is unbounded externally-controlled cardinality.Coverage
91.7% across
internal/.internal/authat 93.8%. Race detector clean.