Repository navigation
Accept access tokens from configured authorization servers - #608
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 8c1a067. Configure here.
87f03df to
37ea132
Compare
hypeman-api can now act as an OAuth resource server. The oauth block of its configuration names authorization servers and the audiences this server answers to, and a token one of those servers signed is accepted as an API token: its subject is the user and its scope is the permissions list. The server holds only public keys, so it verifies these tokens and cannot issue them. Tokens follow the JWT format of RFC 9068. A token with the at+jwt type is checked only against an authorization server's keys and every other token only against jwt_secret, so neither kind of key vouches for the other kind of token. Keys come from the server's RFC 8414 metadata, a URL or the configuration. A fetched key set keeps verifying requests while a refresh runs or fails, and is saved under data_dir so that a restarted server verifies with it from its first request while it fetches the key set again. A key set without any signing key withdraws every key. Revoking a token by its hash now also revokes the second token string that carries the same ECDSA signature, since (r, n-s) verifies wherever (r, s) does. Tokens signed with jwt_secret work as before.
A token naming a key ID the last key set lacks waits for a refresh. If it joined a refresh that was already running for another reason and that refresh failed, it was handed the last key set and refused as an invalid token, although nothing newer had been checked. The code that handed a waiter the last key set dates from when the saved copy was read after a failed fetch. Since the copy is read first, it only ever applied to this case. It is removed, so such a token now gets the refresh's own outcome.
A restarted server restored its saved key set as already expired, so every restart began with a fetch, and what a restart did to the age of the keys in use needed its own explanation. The copy now carries the time its keys were fetched. A restart continues the cache as it was: a copy within the five-minute lifetime is used until that lifetime ends, and an older one answers while the key set is fetched again. A copy without a usable fetch time is due at once.
37ea132 to
adbdc2c
Compare
There was a problem hiding this comment.
finding 1: recommend check original reasoning for this and see if still holds, doesn't seem like a blocker to me, worth checking on.
finding 2: worth fixing / looks like bug
finding 3: why not just include that too
- blocker — registry access ignores token scope. ... the registry fallback accepts .. without checking permissions...
- restart can undo a key withdrawal. if ... saving the replacement set fails, memory is correct but disk still holds the old set....
- standards mismatch. RFC 9068 §2.2 requires client_id and jti; the verifier requires neither.
no action requested: PR descriptions “no time limit” applies to the cached public key, which is fine
cutover metric / plan: consider how to measure if we can disable the old kind of key and consider adding a way to turn that off.
A fetched key set that could not be written left the previous copy on disk. A restart then started from that copy, so a key the authorization server had withdrawn in between was trusted again until the next fetch. A failed save now removes the older copy. A restart without a copy waits for a fetch.
RFC 9068 requires both claims, and the verifier accepted tokens without them.

Summary
hypeman-apican act as an OAuth resource server: it accepts access tokens signed by authorization servers named in its configuration, beside the tokens signed withjwt_secret. It holds only public keys for these tokens, so it verifies them and cannot issue them. Stacked on #607.typisat+jwt, the algorithm is asymmetric,audholds one of this server's audiences, the claims the RFC requires (iss,sub,client_id,aud,iat,exp,jti) are all present, andscopebecomes the permissions list the existing scope middleware enforces. A token without a scope has no permissions;*is full access.lib/jwtauthdispatches on thetypheader. A token typedat+jwtis checked only against an authorization server's keys, and every other token only againstjwt_secret.data_dir/oauth/keys/with the time it was fetched, so a restarted server continues with the key cache it had: a copy younger than five minutes needs no fetch, and an older one answers while it is fetched again.revoked_token_hashesapplies to access tokens. Revoking a token signed with ECDSA now also revokes the second token string that carries the same signature, since(r, n-s)verifies wherever(r, s)does.Operator documentation is in
docs/oauth-access-tokens.md. Design: https://gist.github.com/rgarcia/d01f8381a0d104a0dc3d9b523e14d3f4Worth a reviewer's attention
lib/oidcfederation/verifier.gosplits the signature step out ofVerifyso both token profiles share it. Identity assertion behaviour is unchanged apart from the algorithm and key check above./v2does not check permissions. That predates this change.Not in this PR
The authorization server, and running without
jwt_secret.jwt_secretis still required, and tokens signed with it work as before.Testing
JwtAuth: scoped, full access, no scope, the registry path, revoked, and signed with the wrong kind of key.go testpasses for./cmd/api/ ./cmd/api/config/ ./lib/accesstoken/... ./lib/jwtauth/ ./lib/oidcfederation/ ./lib/middleware/ ./lib/registry/ ./lib/paths/ ./lib/scopes/ ./lib/tokenrevocation/, and-racefor the packages with new code.gofmtandgo vetare clean.make testwas not run locally; CI is its first run.Reviewed with sol-loop: 5 rounds with openai-codex/gpt-6.2-sol on extra-high reasoning. Sol verdict: approved. Four commits came after that review: one removes a dead branch that reported a failed refresh as an invalid token, one saves the fetch time with the key set, and two address review findings (the older copy is removed when a save fails;
client_idandjtiare required).