garage44.eu/jeroen/cartopolis

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

.. /docs/adr/031-layered-access-model.md

raw

ADR-031: Layered Access Model (Anonymous Viewer → Login → ACL Layers)


Metadata:


Context

Problem: The client is a multi-faceted viewer whose facets have different access requirements, but today the boot model offers only three all-or-nothing modes (--connect, default solo, --offline — main.rs:302) and login is effectively mandatory: even to browse the map in the default mode you spin up a full cartopolis_simulator and authenticate. There is no first-class anonymous viewer that just looks things up, routes, and browses public layers; and no articulated path for login to add the simulation, nor for per-user ACLs to add restricted layers later.

The building blocks exist but are ungoverned: the map tier and data layers already run independent of any sim (ADR-020; layer systems are ungated in main.rs), data layers are already a declarative registry (LAYER_DEFS/LayerDef, ADR-023), and place lookup exists (self-hosted Nominatim, geo_nav.rs). Routing is desired but not yet built. What's missing is a model that says which facets are available to whom, and lets that grow monotonically: anonymous → authenticated → authorized.

This must not be conflated with platform capability (ADR-030): can the runtime do it is a different question from is the user allowed it.

Requirements:

Decision

Model the viewer as a stack of layers, each declaring an access tier; the session carries a monotonically growing set of entitlements that selects which layers are active.

Two tiers are primary today — the Viewer (no login) and the Simulation (login) — with an Authorized sub-tier for per-user ACL grants. Avatars and chat live behind the Simulation tier: they require a logged-in session.

The Authorized tier has its first concrete case: the AI assistant is admin-only. It holds a server-side secret (the Anthropic API key) and spends real money per request, so it is gated on an ai capability granted only to admin users — not merely on being logged in. See ADR-034, which routes it through cartopolis_simulator over NetMessage rather than the anonymous data relay.

Access tiers (a layer declares exactly one):

TierProduct nameUnlocked byExamplesEnforcement
PublicViewernothing (anonymous)map tiles, place lookup, routing, public POI/transit data layersnone — external services hit directly by the client
AuthenticatedSimulationany logged-in sessionthe sim tier (ADR-020): avatars, prims, editing, chatserver: sim only serves/accepts for authenticated sessions
Authorized(cap)(first case: ai)a specific ACL/role grantAI assistant (admin-only); later: private worlds, moderator overlays, org dataserver: sim withholds data / rejects intents unless the session holds cap

Session entitlements grow, never shrink within a session: {Public} (anonymous) → +Authenticated on login → +Authorized(cap) per granted capability. Login is a runtime transition (a button), not a CLI mode — the app starts anonymous (always, and necessarily so for the wasm build) and upgrades.

Two orthogonal gates. A layer is live iff platform-supported (ADR-030) ∧ entitled (this ADR). Keep them as separate predicates and separate resources — do not fold access tiers into ADR-030's platform Capabilities. One answers "can this build render it," the other "is this user allowed it."

Enforcement rule (load-bearing). For Authenticated/Authorized tiers the server is the gate: cartopolis_simulator withholds layer data and rejects mutating intents for sessions lacking the entitlement (P-01, P-04). Client-side layer toggles are UX only (show/hide, grey-out an unavailable action) and carry no security weight. Public-tier layers are external services (tiles, Nominatim, routing) the client calls directly and need no entitlement.

Implementation shape. Generalize the existing LayerDef registry (ADR-023) so every layer — map tiles, place lookup, routing, POI/transit overlays, the simulation layer — is a registry entry carrying an access: Tier. A SessionEntitlements resource holds the current set; a run-condition activates each layer's systems on platform_supported(layer) && entitlements.grants(layer.access). The "simulation layer" is the Authenticated entry and maps onto the existing sim connection path (ADR-016 auth is what flips it on).

Rationale

Primary Reasoning:

  1. Matches the product's real shape. cartopolis is a place-lookup/routing/map viewer and a virtual world; the tiered stack lets the anonymous viewer be genuinely useful (G-04) while login unlocks the world (G-02) and ACLs unlock more (G-05) — one model, three depths.
  2. Web-native default. "Anonymous, public layers only" is precisely the wasm build's base state (ADR-030); login as a runtime upgrade means the web and native flows are identical.
  3. Security lives server-side (P-04, P-01). Making entitlement a client toggle would be a paper wall; the sim-as-gate rule keeps restricted layers actually restricted and slots into the authz work the capability map already flags as a gap after ADR-016.
  4. Reuses an existing seam (P-05). Layers are already a declarative registry (ADR-023); adding access: extends it instead of forking a new system.

Alternatives Considered:

AlternativeProsConsRejected Because
Binary Viewer vs Connected modeSimpleNo room for ACL layers; re-couples "logged in" with "can see layer X"Doesn't express per-layer, per-role access
CLI launch modes only (today)Already builtLogin is boot-time, not a runtime upgrade; no anonymous facetCan't land on a page and browse without login
Client-side entitlement checksEasy to implementTrivially bypassedViolates P-04 for restricted layers
Fold access into ADR-030 CapabilitiesOne resourceConflates "can render" with "is allowed"; muddies bothTwo orthogonal concerns must stay separate

Consequences

Positive:

Negative:

Related