lore-forge/.ai/designs/token-issuer.md

9.1 KiB

Token issuer

Status: phase 1 built (crates/forge-id/src/issuer/); every grant below is exercised against the Lore v0.14.0 release by scripts/e2e-lore.sh. Last updated 2026-11-25.

lore-forge is the OpenID Connect issuer that loreserver trusts. This document covers what it must serve. The requirements come from Lore; see lore-integration.md.

Role

  • Lore clients log in at lore-forge and receive tokens.
  • loreserver verifies those tokens locally with lore-forge's public keys.
  • lore-forge is both the login issuer and the token-exchange issuer, under one issuer URL.

lore-forge is an issuer for Lore clients. It is not a general-purpose identity provider for other applications.

Endpoints

Endpoint Path Purpose
Discovery /.well-known/openid-configuration Discovery document
JWKS /oauth/jwks Public signing keys, each with alg declared
Device authorization /oauth/device_authorization Starts a CLI login
Token /oauth/token All grants below
Revocation /oauth/revoke lore auth logout
Device verification /device Browser page where the person approves a CLI login (part of the web UI)

The Lore CLI is a public client: it presents client_id (default lore-cli) and no secret. Every grant checks the client ID. The one exception is the client credentials grant, where the client is a service account authenticating with a secret, by HTTP Basic or in the form body; discovery lists none, client_secret_basic and client_secret_post.

Verified in Lore's source (6b12f00) and by the e2e test: Lore's client uses Basic when discovery lists client_secret_basic and the form body otherwise. For API-key login it sends the token type it was given verbatim, so lore-forge accepts both api-key and urn:lore:params:oauth:token-type:api-key.

Grants on the token endpoint

Grant Used by Result
Device code (RFC 8628) lore auth login Login token and refresh token
Refresh token Lore client, automatically New login token; refresh token rotated
Client credentials CI, lore auth login --client-id Login token for a service account; no refresh token. The login lasts one hour or until the secret expires
Token exchange (RFC 8693), login token in Lore client, per repository Repository-scoped token
Token exchange (RFC 8693), API token in CI without a browser, lore auth login --token-type api-key Login token and refresh token for the token's user; the token needs the lore scope

The device grant must honour the polling rules Lore's client expects: interval, slow_down, expired_token and access_denied.

Tokens

Login token

A JWT access token (typ: at+jwt) identifying the user.

Claim Value
iss lore-forge's issuer URL
sub Stable internal user ID
aud The loreserver deployment URL
identity The identity Lore records in history (see below)
root_domains Hosts the token may be sent to: the loreserver host and lore-forge's own. Always set, because the CLI sends tokens to lore-forge's user directory too
sid The CLI login the token belongs to; lets exchange refuse tokens of an ended login
client_id, jti, scope As RFC 9068 describes
name, preferred_username For display
exp, iat Short lifetime; renewed by refresh

It carries no repository permissions. loreserver accepts it for calls that do not name one repository, such as creating a repository, and forwards it to lore-forge's registry.

Repository-scoped token

Issued by token exchange for exactly one repository.

  • Same iss, sub, aud and identity as the login token, so the caller is the same user to loreserver in both.
  • Adds resources: [{"resource_id": "urc-<repository id>", "permission": [...]}] with the actions the user holds on that repository.
  • Lifetime of at most five minutes, and never past the login token's expiry.

Exchange behaviour

  1. The client sends its login token as subject_token and names the repository as resource=<resource_template with the repository id>.
  2. lore-forge verifies the login token, resolves the user's actions on that repository from its grants, and signs the scoped token.
  3. Errors follow the sample service Lore ships: invalid_grant for a login token that does not verify (the client reports "not authenticated"), invalid_target for a repository the user has no grant on (the client reports "not authorized").

Performance constraint

Every active Lore client repeats the exchange for each repository it uses about every five minutes. This path must be cheap: it reads grants and signs, and performs no database write. Audit records for exchanges are batched or sampled. See storage.md.

Refresh tokens

  • Opaque, stored hashed, rotated on use.
  • One CLI login (a cli_logins row) per lore auth login; its refresh tokens rotate within it. Shown in the user's session list (/settings/sessions) and revocable there. A login started from an API token or a service account secret ends when that token is revoked.
  • Reuse detection: a rotated-out refresh token presented again ends the whole login, per RFC 9700. A 60-second grace period lets a client retry a refresh whose response was lost.
  • The login ends 30 days after its last refresh, or 90 days after it began, whichever is first, matching "stay signed in" browser sessions.
  • Lore's client requests offline_access on every login; lore-forge issues a refresh token for it.
  • Revocation through the revocation endpoint ends the login.

Signing keys

  • Algorithm: ES256, with alg always declared in the JWKS. loreserver takes the algorithm from the declared value.
  • Storage: private keys are stored encrypted with the same environment-supplied key that protects provider secrets.
  • Rotation: the JWKS publishes the current key and the previous one. loreserver re-fetches keys when it sees an unknown key ID, so rotation needs no server restart. The owner rotates from /admin/settings or with lore-forge rotate-signing-key on the server; a running lore-forge re-reads its keys every minute, so a rotation made by the command reaches it within that time. Rotating twice retires the oldest key, ending tokens it signed.
  • Stability: keys persist across restarts. Lore's sample service regenerates its key on every start, which invalidates all outstanding tokens; lore-forge must not.

Identity claim

Lore records identity (or sub when absent) as the creator and committer of revisions.

Decided (owner, 2026-11-25): set it to the stable internal user ID and serve names through Lore's UserService. See accounts-and-sign-in.md.

Tokens for the web UI

Issuer::browse_token mints a token for lore-forge's own pages to read a repository from loreserver as the viewer: the viewer's identity, one resources entry for that repository with only read, a one-minute lifetime, no sid. It is never handed to the browser. It is refused when the viewer's grants do not include read.

Service accounts and CI

  • A service account is a non-human identity owned by a user or organisation.
  • It logs in with client credentials; its secrets are API tokens with the lore scope. A person's own API token logs in through token exchange instead.
  • Details are in accounts-and-sign-in.md.
  • It receives grants like any user. The push-protected action is how a CI account is allowed to push to a protected branch.

Revocation and how fast changes apply

Change Takes effect
Grant added or removed Within five minutes, when the client's scoped token expires
CLI login revoked Exchange refuses at once (it checks the login is live), so repository access ends within five minutes. The login token itself stays valid until it expires, at most an hour, for calls that name no repository
User disabled Same as a revoked login, for all of that user's logins
Signing key rotated out When removed from the JWKS

The exchange's liveness check is one indexed read. It keeps the exchange path free of writes.

Lifetimes

Defaulted, not confirmed by the owner (forge_id::issuer::Lifetimes):

Item Lifetime
Login token 1 hour
Repository-scoped token 5 minutes, never past the login token
CLI login (refresh) 30 days idle, 90 days at most
Device code 10 minutes, polled every 5 seconds

Security notes

  • The private signing keys grant access to every repository. They are the most sensitive data lore-forge holds.
  • The token endpoint and the cookie-authenticated web UI share a process. Constraints that keep untrusted repository content away from them are in web-ui.md.
  • The audience is fixed to the deployment, so tokens cannot be replayed against another service, and Lore's client will not send them to a host the token does not name.

Open questions

  • Confirm the lifetimes above.
  • Whether to keep an audit trail of token exchanges, and at what granularity.