Skip to content

Add hypeman-auth, the OAuth authorization server - #618

Open
rgarcia wants to merge 3 commits into
mainfrom
hypeship/auth-server
Open

rgarcia wants to merge 3 commits into
mainfrom
hypeship/auth-server

Conversation

@rgarcia

@rgarcia rgarcia commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds hypeman-auth, an OAuth authorization server that is a separate binary from hypeman-api. A workload proves who it is with an OIDC identity token it already has, and receives a short-lived access token that Hypeman servers verify with the authorization server's public keys (#608). No Hypeman server holds a key that can issue one. This is the third layer after #607 and #608.

curl https://auth.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=ci-nightly \
  --data-urlencode resource=https://hypeman.example.com
  • Token endpoint. The RFC 7523 JWT bearer grant, with the audience named as in RFC 8707. No client authentication. Every refusal of an identity token is the same invalid_grant; invalid_target is returned only once the caller is known to be the rule's workload.
  • Tokens. Signed with an ECDSA P-256 key in the RFC 9068 format hypeman-api accepts: aud is one of the rule's audiences, scope is the rule's permissions, client_id is the rule, and the lifetime is 300 seconds by default, at most 600, and never past the identity token's own expiry. A key's kid is its RFC 7638 thumbprint.
  • Keys. Published through RFC 8414 metadata and a JWKS, beside any published_keys for rotation.
  • Federation rules gain authorization.audiences (required) and authorization.subject_claim (optional: the identity token claim that names the caller, added to the token's subject).
  • Single use. Identity tokens from issuers that require it are recorded by one INSERT ... ON CONFLICT DO NOTHING on the primary key of a PostgreSQL table shared by every instance, so several instances can run and a restart loses nothing. If the insert fails, nothing is issued.
  • Configuration. A YAML file, environment variables, or both. Unknown keys are errors, and a number or boolean written where text belongs is an error rather than being converted: a large account ID written without quotes would otherwise be rounded on the way in.

Operator documentation is in docs/authorization-server.md. Design: https://gist.github.com/rgarcia/d01f8381a0d104a0dc3d9b523e14d3f4

Layout

  • lib/authserver: the exchange, the HTTP handlers, key loading and the PostgreSQL store.
  • cmd/auth: the binary, its configuration, and a Dockerfile.
  • lib/oidcfederation: the two rule fields and Registry.SingleUse.

Worth a reviewer's attention

  • The schema is numbered SQL files in lib/authserver/migrations, built into the binary. At start the server applies the ones the database has no record of, in one transaction behind an advisory lock so that instances starting together take turns, and records them in public.hypeman_auth_schema_migrations. Its role therefore owns the tables and keeps CREATE on the public schema. A later schema change is a new file, and must leave the schema usable by the release before it.
  • Records of spent identity tokens are deleted a day after the identity token expired, by the database's clock.
  • The token endpoint has one 20-second deadline for reading the request and exchanging, inside the server's 30-second write deadline, so an identity token is not spent for a response that can no longer be written.
  • Adds github.com/jackc/pgx/v5 v5.9.0. No existing dependency changes version.

Not in this PR

A workflow that publishes the image, release packaging, a signer backed by a key management service, signing long-lived tokens with hypeman-token, and running Hypeman servers without jwt_secret.

Testing

  • Unit tests for the exchange (single use across instances and under a race, store failure, audiences, lifetimes, the subject claim, refusals), the handlers, key parsing and the key set, and configuration loading. A token issued in the tests is verified with the same lib/accesstoken verifier hypeman-api uses.
  • TestPostgresStore runs against a real PostgreSQL 17 when HYPEMAN_AUTH_TEST_POSTGRES_URL is set, in a database it creates and drops: concurrent first starts, concurrent spends, cleanup, a later migration applied once, and a failing migration that changes nothing. It is skipped in CI, which has no database. The concurrent-start case fails every run without the advisory lock.
  • go test -race passes for ./cmd/auth/... ./lib/authserver/ ./lib/oidcfederation/ ./lib/accesstoken/... ./lib/jwtauth/ ./lib/middleware/. gofmt and go vet are clean.
  • Run by hand: the binary against PostgreSQL issued a token for a locally signed identity token, refused its replay, refused an audience outside the rule and a resource in the URL, and served the metadata, key set and metrics. The Docker image builds and starts.
  • Full make test was not run locally; CI is its first run.

Reviewed with sol-loop: 4 rounds with openai-codex/gpt-6.2-sol on extra-high reasoning. Sol verdict: approved. Two commits came after that review: a signing key from the environment now replaces the file's instead of being added to it and the image names its non-root user; and the store's schema moved from statements in Go to migration files.

hypeman-auth exchanges a workload's OIDC identity token for a
short-lived access token that Hypeman servers verify with its public
keys. It is a separate binary, so a Hypeman server holds no key that can
issue a token.

The token endpoint is the RFC 7523 JWT bearer grant, with the audience
named as in RFC 8707. Tokens are signed with an ECDSA P-256 key in the
RFC 9068 format hypeman-api accepts, and the keys are published through
RFC 8414 metadata.

A federation rule now names the audiences a token may be issued for,
and optionally the identity token claim that names the caller.

Single-use identity tokens are recorded by one insert in a PostgreSQL
table shared by every instance, so several instances can run and a
restart loses nothing.
@rgarcia
rgarcia requested a review from sjmiller609 November 27, 2026 21:13
@socket-security

socket-security Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedgithub.com/​jackc/​pgx/​v5@​v5.9.073100100100100

View full report

@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 36e718f. Configure here.

Comment thread cmd/auth/config/config.go Resolved
SIGNING_KEY__PEM or SIGNING_KEY__FILE set one half of the signing_key
block and left the other half from the file in place, so a file naming
a key path and an environment giving the key text left both set and the
server refused to start. Either variable now replaces the block.

The image also names its non-root user, which the base image already
ran as.
The table and its index were SQL strings in Go that ran at every start,
with no record of what a database already had, so a later schema change
would have needed its own if-not-exists logic.

The schema is now numbered SQL files built into the binary. At start the
store applies the ones the database has no record of, in one transaction
behind the advisory lock that was already there, and records them in
public.hypeman_auth_schema_migrations. A later change is a new file.

This branch has not been deployed

No deployments
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