Repository navigation
Conversation
POST /oauth/token trades an identity token from a configured OIDC issuer for a short-lived API token carrying the matching federation rule's permissions. The exchange is an RFC 7523 jwt-bearer grant with no client authentication, and every refusal reads the same to the caller. Single-use assertions are recorded in memory until they expire, and ones issued before the server started are refused. Issued tokens name their rule, and the JWT verifier rejects them once that rule or its issuer is removed or changed.
The record of spent single-use identity tokens lived in memory only, so after a restart the server had to refuse tokens issued around its start, which made the exchange unavailable for about 30 seconds. Write each spent token to a file under the data directory before its API token is returned, and load the file at start. A restart now forgets nothing and exchanges work as soon as the server is up. The time-based floor remains only for a start that finds the file missing or damaged, and the file remembers it across later restarts.
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 c0b41c2. Configure here.
A record of a spent assertion is dropped once the host clock says its assertion has expired. A clock that ran ahead dropped records early, and after it was corrected their assertions could be exchanged again. The record now keeps the latest expiry it has dropped, at a start and while running, and refuses an assertion expiring at or before it. With a correct clock no assertion still within its lifetime expires that early. Both that mark and the floor are checked under the same lock as recording the spend, and a file counts as complete only if both of their lines were read.
This branch has not been deployed
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.

Summary
Second of two stacked pull requests, on top of #601. Adds
POST /oauth/token, where a workload trades an identity token from a configured OIDC issuer for a short-lived Hypeman API token carrying its federation rule'spermissions.curl -sS https://hypeman.example.com/oauth/token \ --data-urlencode grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer \ --data-urlencode assertion="$IDENTITY_TOKEN" \ --data-urlencode federation_rule_id=ciOperator documentation is in
docs/oidc-federation.md.How it fits the existing auth model
jwt_secret, withsubset tofederation:<rule>and an explicitpermissionslist. The existing verifier, key rotation, hash revocation and scope middleware apply unchanged.docs/jwt-rotation.mdgains a paragraph; rotation needs no new step.lib/jwtauthrejects it once the rule is removed or changed, on every path that verifies tokens, and rejects any such token without an explicitpermissionslist.The exchange
federation_rule_idselects the one rule to check and grants nothing by itself.invalid_grant; the reason goes to the server log only.temporarily_unavailable(503) means no token can be issued right now./v2/tokenand the exec and cp routes: it is form-encoded and must see repeated parameters and theAuthorizationheader.Replay
A single-use identity token can be exchanged once. Each spent token is written to
oidc/spent-assertionsunder the data directory, and synced, before its API token is returned, and the file is loaded at start. A restart therefore forgets nothing and needs no warm-up: fresh tokens are accepted as soon as the server is up, and spent ones stay refused.iatis earlier than that start plus the 30 seconds of clock leeway the verifier allows, and keeps that line in the file across later restarts. For about the first minute the refusal istemporarily_unavailable, so callers retry with a fresh token.Observability
hypeman_oidc_exchanges_total{issuer, rule, result}. The labels come from configuration only, never from request input.jti. Identity tokens are never logged.Not in this change
permissionsare enforced as for any scoped token; direct registry access under/v2accepts any valid API token, as it does today..well-knownmetadata, and rate limiting.Testing
go test ./lib/oidcfederation/ ./lib/jwtauth/ ./cmd/api/ ./lib/scopes/ ./lib/middleware/ ./lib/registry/, and-raceon the first two.make testsuite was not run locally (it needs KVM and the hypervisor binaries); CI runs it.Design notes for the whole stack: https://gist.github.com/rgarcia/d06b17f03b818f3d4dae431b5efcab9d
Reviewed with sol-loop: 3 rounds with openai-codex/gpt-6.2-sol on extra-high reasoning, and 5 more for the durable replay record. Sol verdict: approved.