The broker NetworkPolicy no longer admits the node subnet. Port 8080 is the in-cluster backend for ingress-nginx pods only; players use https://grants.aeternalisgames.com on 443. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5.3 KiB
ADR-0131: Keycloak login and the grant broker
Status
Accepted (2026-10-15). DEV first; stage and World0 need their own realm, issuer key and review.
Context
Region servers accept 160-byte session grants signed with an ECDSA P-256 issuer
key (ADR-0091). Grants are single-use per account: each carries a serial that must
exceed the newest one the world accepted, and a session can be extended with a
newer grant (SessionRefresh). Until now grants were minted offline by
evo-session-probe grants with the issuer key on the operator's host, for
hand-made accounts. Players need to register, log in and log out, and grants must
never be minted on a client.
Decision
Identity
- Keycloak realm
aeternalisatauth.aeternalisgames.comis the identity provider: registration, email verification, password reset and MFA live there. Users sign in with their email. - The game client is the public client
aevolution-game: authorization code with PKCE S256 in the system browser, redirecthttp://127.0.0.1:47600/callback(RFC 8252 loopback). Device authorization is enabled for test tools. - An audience mapper adds
aevolution-grantsto access tokens. Access tokens live 5 minutes; refresh tokens rotate and are single-use.
The grant broker (evo-grant-broker)
- A small HTTP service behind
grants.aeternalisgames.com(TLS at the ingress). It holds the issuer private key (Secretaevolution-grant-issuer) and a database login; it never calls Keycloak. It verifies access tokens itself against the realm's public keys, pinned from the realm's JWKS in Git (a Keycloak key rotation is a Git change and a sync). POST /grantwithAuthorization: Bearer <access token>: the token must be an RS256 access token (typBearer) from the realm issuer, for audienceaevolution-grants, authorized partyaevolution-game, unexpired (30 s leeway), with a subject and a verified email. The broker maps (issuer, subject) to a stable game account, created on first use, so registering is the first login. It takes the next grant serial for that account (above any serial the world has accepted), routes to the region holding the account's active life or else the configured default region, and returns a 10-minute grant with the region's endpoint.POST /logoutwith the same bearer: the account's accepted serial is raised past every serial issued so far and its current control is expired. Outstanding grants are then stale, and a live session closes at its next control renewal (at most 5 s). Refused tokens get 401 with a JSON reason (invalid_token,token_expired,email_not_verified,token_not_for_this_service); a second grant for the same account within 2 s, 429; an unreachable database or unrouted region, 503.GET /healthzfor probes.- Responses carry no secret but the grant itself; nothing logs tokens or grants.
Database (schema v39)
account_identities(issuer, subject, account_id, last_serial, created_at).issue_account_grant(world, issuer, subject)andrevoke_account_grants(world, issuer, subject), SECURITY DEFINER and granted to the runtime group role. The broker logs in with its own login in that group (DEV); a dedicated broker role is a later least-privilege step.
Client contract
- Sign in (authorization code + PKCE), keep the refresh token in the OS credential store, never on disk in clear.
POST https://grants.aeternalisgames.com/grantwith the access token. The JSON answer is{"grant":"<base64>","account":"<uuid>","region":N,"endpoint":"host:port", "server_name":"name","expires_at":unix_seconds}.- Connect with the grant. About one minute before
expires_at, refresh the access token if needed, fetch a new grant and sendSessionRefresh. - On logout:
POST /logout, then revoke the refresh token at Keycloak's revocation endpoint.
Deployment (DEV)
deploy/kubernetes/grant-broker-dev, a component ofregion/devso it runs the same pinned server image (/usr/local/bin/evo-grant-broker). One replica, non-root, read-only root filesystem, port 8080, probes on/healthz.- Out of band in
evolution-dev: Secretaevolution-grant-issuer(keyissuer.key, the raw 32-byte dev issuer scalar), Secretaevolution-grant-broker-pg(pg_service.confwith service[evolution],pgpass,ca.crt) and the Ingress forgrants.aeternalisgames.com(the Argo project admits no Ingress). - Public access is HTTPS on 443 only, terminated by ingress-nginx. Port 8080 is the in-cluster backend: a ClusterIP Service, and a NetworkPolicy that admits only the ingress-nginx pods and nothing on the LAN. Egress goes to PostgreSQL only.
- The grant lifetime (600 s) must stay within the region's
REGION_M10_MAX_GRANT_LIFETIME.
Alternatives
- Verify Keycloak tokens in every region: rejected; it changes the Hello wire format, puts identity mapping in every region and spreads key rotation.
- Long-lived grants without refresh: rejected; a stolen grant would stay usable.
- Our own password store: rejected; Keycloak already provides it properly.
Consequences
Players log in with an email account; the issuer key leaves the operator's host for a Secret; hand-minted grants remain for tests. A new login supersedes the old session (unchanged). Revocation is immediate within one renewal.