ADR-0131: Keycloak grant broker and schema v39 account identities
Foundation / checks (checks) (push) Successful in 42m13s
Foundation / checks (deploy) (push) Successful in 4m5s
Foundation / checks (ecs) (push) Successful in 2m25s
Foundation / checks (network) (push) Successful in 19m18s
Foundation / checks (postgres) (push) Successful in 44m19s
Foundation / checks (tsan) (push) Successful in 9m48s
Foundation / checks (client) (push) Failing after 12m6s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped
Foundation / checks (checks) (push) Successful in 42m13s
Foundation / checks (deploy) (push) Successful in 4m5s
Foundation / checks (ecs) (push) Successful in 2m25s
Foundation / checks (network) (push) Successful in 19m18s
Foundation / checks (postgres) (push) Successful in 44m19s
Foundation / checks (tsan) (push) Successful in 9m48s
Foundation / checks (client) (push) Failing after 12m6s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped
evo-grant-broker verifies realm aeternalis access tokens offline (RS256 against the pinned JWKS; audience aevolution-grants, client aevolution-game, verified email) and issues 10-minute session grants: - POST /grant routes to the region holding the account's life, or the default. - POST /logout makes every issued grant stale and expires current control. - GET /healthz. Schema v39 maps (issuer, subject) to stable accounts with strictly increasing serials. The binary ships in the server image. The DEV manifests are in deploy/kubernetes/grant-broker-dev and are not yet enabled in region/dev; that waits for the image promotion and the out-of-band Secrets and Ingress. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
# 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 `aeternalis` at `auth.aeternalisgames.com` is 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, redirect `http://127.0.0.1:47600/callback`
|
||||
(RFC 8252 loopback). Device authorization is enabled for test tools.
|
||||
- An audience mapper adds `aevolution-grants` to 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 (Secret `aevolution-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 /grant` with `Authorization: Bearer <access token>`: the token must be an
|
||||
RS256 access token (`typ` Bearer) from the realm issuer, for audience
|
||||
`aevolution-grants`, authorized party `aevolution-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 /logout` with 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 /healthz` for 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)` and
|
||||
`revoke_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
|
||||
|
||||
1. Sign in (authorization code + PKCE), keep the refresh token in the OS credential
|
||||
store, never on disk in clear.
|
||||
2. `POST https://grants.aeternalisgames.com/grant` with the access token. The JSON
|
||||
answer is `{"grant":"<base64>","account":"<uuid>","region":N,"endpoint":"host:port",
|
||||
"server_name":"name","expires_at":unix_seconds}`.
|
||||
3. Connect with the grant. About one minute before `expires_at`, refresh the access
|
||||
token if needed, fetch a new grant and send `SessionRefresh`.
|
||||
4. On logout: `POST /logout`, then revoke the refresh token at Keycloak's revocation
|
||||
endpoint.
|
||||
|
||||
### Deployment (DEV)
|
||||
|
||||
- `deploy/kubernetes/grant-broker-dev`, a component of `region/dev` so 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`: Secret `aevolution-grant-issuer` (key `issuer.key`,
|
||||
the raw 32-byte dev issuer scalar), Secret `aevolution-grant-broker-pg`
|
||||
(`pg_service.conf` with service `[evolution]`, `pgpass`, `ca.crt`) and the Ingress
|
||||
for `grants.aeternalisgames.com` (the Argo project admits no Ingress).
|
||||
- Its NetworkPolicy admits TCP 8080 from the ingress controller and the node subnet,
|
||||
and egress 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.
|
||||
@@ -31,6 +31,7 @@
|
||||
- [ADR-0128: Cellular offline freeze, linger and resume](0128-cellular-offline-freeze-and-resume.md) - M11.7: a frozen step intent (set for owned lives without a session) freezes biology; owner format 6 / rules 5 track presence: lingering for 200 ticks (10 s, trial) perceivable and vulnerable, then suspended out of the world without aging; an unfrozen intent resumes in place or at the nearest clear spot within three extents; bundle v6, schema v38.
|
||||
- [ADR-0129: Cellular readable play signals](0129-cellular-readable-play-signals.md) - M11.8 server half: v10 diagnostics report engulf and bud results in two reserved bytes, and v10 type 27 tells the owner its life ended and why (starved or engulfed); presentation stays with the maintainer.
|
||||
- [ADR-0130: Cellular playtest telemetry boundary](0130-cellular-playtest-telemetry-boundary.md) - M11.9: playtest telemetry is an offline, read-only `evo-world-clone summary` of a region head with account-free aggregates only (population, death causes, lifespans, buds, mutations, variety); per-player questions stay in consented notes.
|
||||
- [ADR-0131: Keycloak login and the grant broker](0131-keycloak-login-and-grant-broker.md) - players sign in to Keycloak realm `aeternalis` (PKCE, public client `aevolution-game`); `evo-grant-broker` verifies the RS256 access token, maps it to a game account (schema v39), issues 10-minute grants with increasing serials, and revokes on logout by raising the accepted serial and expiring control.
|
||||
|
||||
- [ADR-0058: Region durability contract](0058-region-durability-contract.md) - accepted M7.1 full checkpoint batches and explicit state closure; storage implementation follows.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user