Skip to content

Accept access tokens from configured authorization servers - #608

Merged
rgarcia merged 5 commits into
mainfrom
hypeship/oauth-access-tokens
Nov 27, 2026
Merged

rgarcia merged 5 commits into
mainfrom
hypeship/oauth-access-tokens

Conversation

@rgarcia

@rgarcia rgarcia commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

hypeman-api can act as an OAuth resource server: it accepts access tokens signed by authorization servers named in its configuration, beside the tokens signed with jwt_secret. It holds only public keys for these tokens, so it verifies them and cannot issue them. Stacked on #607.

oauth:
  audiences:
    - https://hypeman.example.com
  authorization_servers:
    - issuer: https://auth.example.com
  • Token format. JWTs in the format of RFC 9068: typ is at+jwt, the algorithm is asymmetric, aud holds one of this server's audiences, the claims the RFC requires (iss, sub, client_id, aud, iat, exp, jti) are all present, and scope becomes the permissions list the existing scope middleware enforces. A token without a scope has no permissions; * is full access.
  • Two kinds of token, never mixed. lib/jwtauth dispatches on the typ header. A token typed at+jwt is checked only against an authorization server's keys, and every other token only against jwt_secret.
  • Keys. By default from the server's RFC 8414 metadata; also an explicit URL or inline keys. A fetched key set keeps verifying requests while a refresh runs or fails, so requests do not wait on the authorization server once keys are known. It is saved under 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.
  • Key withdrawal. A key removed from the authorization server stops being trusted at the next successful fetch. A key set that is empty, or holds only valid public keys for other purposes, withdraws every key. Any other response is a failed fetch and keeps the last key set. If a fetched key set cannot be saved, the older copy on disk is removed, so a restart cannot bring withdrawn keys back.
  • Revocation. revoked_token_hashes applies 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.
  • Algorithm and key. A key must be of the kind the token's algorithm signs with, and an ECDSA key on that algorithm's curve. This also applies to identity tokens.

Operator documentation is in docs/oauth-access-tokens.md. Design: https://gist.github.com/rgarcia/d01f8381a0d104a0dc3d9b523e14d3f4

Worth a reviewer's attention

  • While an authorization server is unreachable, its last key set stays trusted with no time limit. That is deliberate: long-lived tokens signed by that key must keep verifying through an outage. Deleting the saved copy and restarting drops it at once.
  • A restart does not change how fresh the keys are: the saved copy carries its fetch time and expires when it would have in memory.
  • lib/oidcfederation/verifier.go splits the signature step out of Verify so both token profiles share it. Identity assertion behaviour is unchanged apart from the algorithm and key check above.
  • As for every API token, the registry under /v2 does not check permissions. That predates this change.

Not in this PR

The authorization server, and running without jwt_secret. jwt_secret is still required, and tokens signed with it work as before.

Testing

  • Unit tests for the token rules, the type dispatch, configuration decoding, the key cache (refresh failure, restart from the saved copy, withdrawal, curve mismatch) and revocation of both ECDSA forms. The revocation and withdrawal tests fail without their fixes.
  • A middleware test sends access tokens through JwtAuth: scoped, full access, no scope, the registry path, revoked, and signed with the wrong kind of key.
  • go test passes for ./cmd/api/ ./cmd/api/config/ ./lib/accesstoken/... ./lib/jwtauth/ ./lib/oidcfederation/ ./lib/middleware/ ./lib/registry/ ./lib/paths/ ./lib/scopes/ ./lib/tokenrevocation/, and -race for the packages with new code. gofmt and go vet are clean.
  • Full make test was 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_id and jti are required).

@rgarcia
rgarcia added this pull request to stack #609 November 24, 2026 20:47
@rgarcia
rgarcia requested a review from sjmiller609 November 24, 2026 20:48

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread lib/oidcfederation/verifier.go Resolved
Base automatically changed from hypeship/oidc-verification-lib to main November 25, 2026 18:01
@rgarcia
rgarcia force-pushed the hypeship/oauth-access-tokens branch from 87f03df to 37ea132 Compare November 25, 2026 18:01
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.
@rgarcia
rgarcia force-pushed the hypeship/oauth-access-tokens branch from 37ea132 to adbdc2c Compare November 25, 2026 18:01

@sjmiller609 sjmiller609 left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. blocker — registry access ignores token scope. ... the registry fallback accepts .. without checking permissions...
  2. restart can undo a key withdrawal. if ... saving the replacement set fails, memory is correct but disk still holds the old set....
  3. 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.
@rgarcia
rgarcia merged commit d85e2b9 into main Nov 27, 2026
11 checks passed
@rgarcia
rgarcia deleted the hypeship/oauth-access-tokens branch November 27, 2026 20:35
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.

2 participants