Identity and principal token
Identifiers
- Users: the Keycloak
sub(UUID) is the primary key everywhere; every other attribute may change. The dev login user has the fixed ID00000000-0000-4000-8000-000000000001. - Everything else: ULIDs (
pkg/ids), sortable, used as_id. - Non-members (borrowers, later):
ExternalPersonentities with their own ID, linkable to a user.
Authentication at the gateway
| Caller | Credential | Principal kind |
|---|---|---|
| Browser | atl_session cookie (HttpOnly, SameSite=Lax, Secure outside development) referencing a server-side session in Valkey (BFF: OAuth tokens never reach the browser) | user |
| Script / device | Authorization: Bearer atl_<prefix>_<secret> | api_key (owner: user or project) |
| Background job | signed by a service holding the signing key | service |
| Nobody | — | anonymous |
The gateway strips every client header starting with X-Atl-, authenticates the caller, then signs a fresh
principal token for each request.
Principal token
X-Atl-Principal is a JWT signed with Ed25519 (EdDSA) by the gateway (PRINCIPAL_SIGNING_KEY), issuer
atl-gateway, audience atl-internal, valid 2 minutes (5 s leeway). Services verify it with
PRINCIPAL_PUBLIC_KEY (principal.Middleware) and never trust any other identity header. Requests without the
header are anonymous; requests with an invalid token are rejected.
| Claim | Meaning |
|---|---|
sub | user ID, API key ID or service name |
kind | anonymous, user, api_key, service |
owk, owid | API key owner kind (user, project) and ID |
adm | admin mode requested (client header X-Atl-Admin-Mode: 1, authenticated callers only) |
acr, auth_time | authentication context class and time (step-up) |
ip, rid | client IP and request ID |
Services forward the raw token to authz in every RPC (principal_token), so authz evaluates the same identity.
Step-up
Sensitive permissions require kind=user, acr == "passkey" (OIDC_STEP_UP_ACR / STEP_UP_ACR) and an
auth_time within 15 minutes (STEP_UP_MAX_AGE). GET /v1/auth/step-up restarts the OIDC flow with
acr_values=passkey and max_age=0, then updates the session ACR and auth time. API keys can never satisfy
step-up.
Sessions
Sessions live in Valkey under the SHA-256 of a random 256-bit ID (a Valkey dump leaks no usable cookie).
Idle timeout 2 h, absolute lifetime 12 h (configurable). The session is rotated at login; OIDC tokens are
refreshed 30 s before expiry under a short lock, and an invalid_grant ends the session. Unsafe methods from
browsers require an allowed Origin (or Referer), API key calls are exempt.