garage44.eu/jeroen/cartopolis

logclone: git clone https://garage44.eu/jeroen/cartopolis.git

.. /docs/adr/016-authentication-and-session-model-v0.md

raw

ADR-016: Authentication and Server Session Model (v0)


Metadata:


Context

Problem: Vision ties governance (G-05) and mutating security (P-04) to known identity before uploads, world edits, or social sends. ADR-009 already gates world traffic on a Handshake → Ack, but it does not define what “proof” means, who stores sessions, or how a principal (stable account id) is bound to a TCP connection. Without that, implementers cannot wire auth consistently across cartopolis_simulator and clients.

Requirements:

Decision

v0 model: After TCP connect (ADR-008), the client completes an authentication handshake inside the ADR-009 envelope. The server verifies credentials, creates a server-side session, and returns an opaque session id plus a stable principal id. Until Ack succeeds, the server must not send world snapshot or accept mutating application messages (read-only probes if any are defined stay explicitly whitelisted in spec).

Approach:

Rust ecosystem (CLI) — use clap (derive) on both client and sim; dialoguer for interactive secrets and destructive confirms; optional clap_complete; miette or color-eyre at binaries; zeroize for sensitive in-memory buffers; argon2 + password-hash (or bcrypt) for stored password hashes. Config and logging stay on ADR-014 (figment, tracing).

Explicit non-decisions (v0):

Solo/dev mode and process model

Tier context (ADR-031). The product runs two tiers: the Viewer (anonymous, no login) and the Simulation (login — avatars, prims, editing, chat). The app starts in the Viewer tier; authenticating here is the runtime transition that adds the Simulation tier. The CLI modes below are dev shortcuts that pre-seed that transition (auto-connect + auto-login), not the product's default entry — a fresh web or desktop launch lands anonymous and upgrades on a login action.

Adding auth must not change the dev DX: cargo run -p cartopolis --profile dev-bevy still launches a working sim+viewer with one command. This is achieved without a solo-only code path:

Rationale

Primary Reasoning:

  1. Roadmap order (roadmap.md): authentication before asset upload and authorization reduces rework on hot paths.
  2. Fits existing gate: ADR-009 already promises “no world snapshot before successful handshake”; this ADR defines successful in security terms.
  3. P-04: Mutating actions attach to principal at the sim; v0 policy is binary (authenticated or not), which is enough until asset and social paths need separation of duties.
  4. CLI-first matches headless sim + developer client (ADR-007) before graphical login or admin UIs exist.
  5. Operator ergonomics: scripts and deploys can provision users without SQL or a separate tool.

Alternatives Considered:

AlternativeProsConsRejected Because
Stateless JWT only, sim verifies signatureHorizontally scalableWeak revocation and session invalidation for v0Sim is single writer for v0; server-side session is simpler and safer to reason about
Mutual TLS as sole identityStrong transport bindingHeavy ops for desktop/lab clientsDefer; optional later as additional proof kind
Per-message HMAC with shared secretNo session storeKey rotation and UX cost; easy to get wrongSession + handshake is clearer for game-style clients
Piggyback on external IdP only (no local principals)Enterprise fitBlocks offline/lab and early iterationv0 needs a local path; federated auth layers on top

Consequences

Positive:

Negative:

Related