0018. Two roles, a route access table, token sign-in with a local-only stub and a gated clock
- Status: Accepted
- Date: 2026-12-01
Context
The app has two kinds of login with different rights (the Admin and the Member). Pages and routes were built before sign-in through Cloudflare Access, so the rules for who may do what had to live somewhere that real sign-in could be added later without touching every route (it has since been added, see below). Local runs, tests and demos also need to sign in as either person and to pin "today".
Decision
- Two roles, stored in the database.
people.roleisadminormember; no role means no login. Cloudflare Access will say who someone is (asubmatched topeople.access_subject); the database says what they may do. A role is never read from the token. - One table of routes.
access.tslists every/apiroute as public, any signed-in person, or Admin (with the named Admin action). A test fails when a route is missing from it, when a row has no route, or when a Member can reach an Admin row. A new route cannot ship unclassified. - The Worker redacts, the page does not hide. What a role may not see (the trust balance, reconcile detail, Settings warnings, another person's private envelope, how another person's entry has changed) is removed before an answer leaves the Worker. A Member's request for an Admin route is refused (403) before its input is read.
- Verified sign-in everywhere it is deployed; a stub only locally. The Worker matches the token's
subto a person and takes the role from the database. In every deployed environment the token is verified (signature, issuer, audience, expiry) against the keys Cloudflare Access publishes, and a missing or oddTEAM_DOMAINorPOLICY_AUDrefuses every sign-in (401). A second, unchecked stub mode decodes thesubwithout checking the signature, and only when the variableAUTH_MODEis exactlystub; it exists so local runs and tests can sign in as either person.AUTH_MODEis set only in the local config and the test setup, and the config generator never writes it. - One clock, with a gated override. Only
api/clock.tsasks for the time. TheX-Nowheader sets it only when the variableNOW_OVERRIDEis exactlyallowed; with any other value the header is refused (400), never ignored. Both variables are local-only and the demo and production configs must leave them out.
Consequences
- The role checks and the masking are the same whether sign-in is the stub or verified, so one set of tests covers both.
- Moving the role into the token (or a second source) would touch every masking path: treat the database as the only source of roles.
- Adding a route means adding a row to the access table in the same change.
- A deployment that forgets the two clock and stub variables is verified and on the real clock, which is the safe way to be wrong; one that forgets
TEAM_DOMAINorPOLICY_AUDis locked. - The stub is unsafe by design: it must never reach the demo or production configs. The generated configs leave out both variables and a test proves it, but a config written by hand is not checked, so a review of any config change has to look for them.