Status: Accepted (2026-11-28). Refines 0011 (token keys) and 0021 (table ownership, now enforced by Postgres). Role names, the HKDF salt and the variable names updated by 0028 (2026-11-30).
Security finding SR-07 (Medium). One HMAC keyring (LINORA_TOKEN_KEYS) signed every token type, and every tier connected with the same database role. The doc worker parses attacker-shaped documents and runs resvg, so it is the most exposed tier. With code execution there, it could mint a realtime token for any user, file and role, or write any table directly.
rt: user realtime tokens; the API signs, realtime verifies.cg: client grants; realtime signs and verifies.svc:api: the API calling doc workers.svc:docworker: doc workers following pages over realtime.A purpose key is HKDF-SHA256(master secret, salt "linora-token-v1", info purpose) and keeps the master’s kid.
typ/svc, then checks the MAC. A token of another purpose still fails as wrong_type, and a purpose the process holds no key for fails as unknown_kid.signToken throws when the process holds no key for the purpose.LINORA_TOKEN_KEYS (master); every purpose is derived in-process.LINORA_TOKEN_KEYS_RT: api, realtimeLINORA_TOKEN_KEYS_CG: realtimeLINORA_TOKEN_KEYS_SVC_API: api, docworkerLINORA_TOKEN_KEYS_SVC_DOCWORKER: docworker, realtimenode packages/server-common/src/token-keys.ts derive prints the four lines from a master. Explicit purpose keys win over derived ones.loadServerConfig(env, { tokenPurposes })) and refuses to start without them.tokenKeysFromEnv(env) folds all variables into one string that parseTokenKeys reads, so realtime can still hand its keys to threads as a single string.0002_tier_roles.sql creates NOLOGIN group roles linora_api, linora_realtime, linora_docworker and linora_compactor, with table and column GRANTs that encode ADR 0021’s write ownership:
page_ops; updates pages.head_seq/tail_*/last_op_at and files.next_client_id; reads pages, files, snapshots, projects and members.pages.snapshot_seq/node_count/tail_*; retention deletes of page_ops; deleting expired sessions (it reads only token_hash, expires_at of sessions).Ops creates one LOGIN user per tier as a member (deploy/postgres/roles.sql, O1) and gives each process its own DATABASE_URL. The migrator owns the tables and needs CREATEROLE, or the roles are created beforehand. Every later migration that adds a table must grant it in the same file.
svc:api tokens (accepted only by doc workers) and svc:docworker tokens (hidden read-only realtime subscriptions). It can read pages and the journal, but not accounts, sessions, PATs or audit, and it can write nothing.apps/docworker/test/roles.test.ts). Purpose separation and rotation are covered in packages/server-common/test/token.test.ts.