Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.
Permissions Model
DBBASIC permissions are a server-side primitive. Scroll can edit, preview, and explain rules, but the object server must make the final allow/deny decision.
Many web frameworks treat permissions as something each app has to rediscover: blog visibility, admin-only pages, intranet roles, or social-app follows. Those cases matter, but they are not enough for a general business platform.
DBBASIC needs object-level permissions that can model SaaS, customer portals, employee roles, contractors, paid content, shared workspaces, internal admin tools, and AI-generated app surfaces with the same small set of primitives. Getting this right means most apps need less custom permission code.
The model needs to cover the common app cases without forcing every object into one framework shape:
- public visitors
- signed-in users
- paid subscribers
- temporary paid access
- admins and employees
- customer accounts with their own employees
- object owners
- users or accounts an owner shared with
- per-row and per-field restrictions
Permissions decide who may call an object. What the object's code may then do is a separate boundary: user-namespace objects (u_<uid>_*) run in a Landlock-sandboxed worker, as a separate OS user that owns nothing, that cannot read secrets, files, other users' data or the network, nor change or inspect other users' files, and reaches its own state, logs and files only through proxies the server checks. See runtime-contract.md "User Object Isolation". A system object that user code calls runs with the identity of the original request, never one the user code supplied.
Decision Shape
The core API is:
check_permission(subject, action, policy, collection=None, object_id=None, record=None)
It returns:
PermissionDecision(
allowed=True/False,
reason="...",
code="allowed|authentication_required|payment_required|forbidden",
http_status=200|401|402|403,
row_filter={...},
)
When a list/query request has a row filter but no specific record, the decision can return allowed=True with the row filter attached. The caller then applies that filter before returning rows.
flowchart TD
A["request"] --> B["identify subject"]
B --> C["load policy"]
C --> D{"admin role?"}
D -- yes --> Z["allow"]
D -- no --> E{"explicit deny matches?"}
E -- yes --> Y["deny with reason"]
E -- no --> F{"access mode allows?"}
F -- yes --> Z
F -- no --> G{"allow rule matches?"}
G -- yes --> H["allow with optional row/field filters"]
G -- no --> I{"owner fallback?"}
I -- yes --> J{"switched off by an owner_fallback rule?"}
J -- no --> Z
J -- yes --> Y
I -- no --> Y
Persistence And API
The current public server stores the active policy as:
data/permissions/policy.json
If the file does not exist, the server uses a conservative default:
{
"access_mode": "role_based",
"roles": {},
"user_roles": {},
"rules": [],
"admin_roles": ["admin", "superuser"]
}
That default has no allow grants. With enforcement on it is enforced as deny-all: every non-admin request is refused, the admin token still works, and /permissions/status warns until a real policy is written (by you, or by installing packages). object_permission_store.starter_policy_payload() returns the documented starter policy for a fresh deployment: anonymous visitors can execute the public pages (site_home, system_dashboard, system_write_probe) and read the dbbasic_probe demo records; signed-in users can write probe records; admin-role subjects bypass rules. It grants a signed-in user nothing else: what they can read and run is what the installed packages' rules (and your own, written per collection or object) give them. Install it with the policy endpoint:
python3 -c "import json, object_permission_store as s; print(json.dumps({'policy': s.starter_policy_payload()}))" \
| curl -s -X PUT https://your-host/permissions/policy \
-H "Authorization: Token <admin-token>" \
-H "Content-Type: application/json" --data-binary @-
Then edit grants per app instead of widening the starter rules in place. Run audit mode before enforcement to see what live traffic would be denied.
A wide rule left over from an older starter policy
Until 2026-11-29 the starter policy also carried
{"effect": "allow", "principal": "registered", "actions": ["read", "execute"],
"reason": "signed-in users can read and run objects"}
with no collection and no object_id. A rule that names no resource matches every resource, and the engine returns the first allow rule that matches without comparing it with the others, so on a box that started from that policy every signed-in account could run every object (the billing runner, recurring journals, sweepers, every hook, generators a package restricts to a role) and read every collection, and the row filters packages ship on wallets, notes and the rest decided nothing. With open signup, "signed-in" means anyone with an email address.
New boxes no longer get it. An existing box still has it, and nothing removes it for you: it carries no package tag, so a package upgrade's retraction never touches it, and the server will not delete an operator's rule on its own. It is made visible instead:
GET /permissions/unshippedlists it (stateoperator) with awideline
saying what it grants, and wide_rules lists every wide rule in the policy (an allow for registered or public with no collection and no object_id), whoever it is tagged for;
- the startup log prints one
[dbbasic] WIDE permission rule #N ...line per
such rule when permission checks are on.
To remove it: read the policy, drop the rule at the index the report gives, and write the policy back. Take the policy as it is, do not retype it.
curl -s https://your-host/permissions/policy -H "Authorization: Token $TOKEN" \
| python3 -c '
import json, sys
policy = json.load(sys.stdin)["policy"]
policy["rules"] = [r for r in policy["rules"]
if not (r["effect"] == "allow" and r["principal"] in ("registered", "public")
and not r.get("collection") and not r.get("object_id"))]
print(json.dumps({"policy": policy}))' \
| curl -s -X PUT https://your-host/permissions/policy \
-H "Authorization: Token $TOKEN" -H "Content-Type: application/json" --data-binary @-
Before you do, run audit mode (or read GET /permissions/audit) to see whether anything you rely on was only reachable through it. Packages ship the grants their own pages need; a page or action no package grants and your users must reach needs a rule of your own naming that object or collection. The changed policy takes effect without a restart.
The policy endpoints are still admin-gated while broader login, account management, and permission editing mature:
GET /permissions/policy
Authorization: Token <token>
PUT /permissions/policy
Authorization: Token <token>
Content-Type: application/json
{
"policy": {
"access_mode": "role_based",
"roles": {"sales": {"label": "Sales"}},
"user_roles": {"7": ["sales"]},
"rules": []
}
}
Saving a policy is checked; reading one is not
A save (PUT /permissions/policy, or object_permission_store.replace_policy from a shell, which is how the starter policy is installed) is held to DRON (dron/dron-policy.schema.json, docs/dron.md), the same check a package's rules.json gets at install. Before anything is written it refuses:
- a key it does not know, on the policy or on a rule, with the closest
spelling (unknown key 'rowfilter' (did you mean 'row_filter'?)): the engine would drop it, and a dropped row_filter turns "each user their own rows" into "every row";
- an effect, action, principal, row-filter operator or
$-variable that is not
one, a valid_from/expires_at that does not parse, and any value of the wrong type the engine would quietly coerce (a number for a collection or a role, a role listed twice, an access_mode left null).
The answer is a 400 naming every mistake by rule index, package tag and key (problems in the body). Rules the stored policy already holds, as the engine reads them, are not judged again: a save is not refused over rules you did not just write, so GET /permissions/policy then PUT of the same document saves, including on a box that carries rules from an older release, with one exception below: a serious mistake in the stored file must be fixed in the save that would otherwise write it back.
The stored file is different. A policy written by hand on disk, or left by an older release, is read exactly as before: nothing is refused and no decision changes on upgrade (unless you turn on the setting described under "Not applying an allow that is wider than written" below). Instead each mistake is reported, with what the engine is doing with it today and how to fix it:
- an
/admin/statusalert ("Permission policy file has N mistake(s) that let
it allow MORE than written: rule 3 (package app-notes) key 'rowfilter': the engine ignores this key, so this allow applies to every row ...");
policy.findingsinGET /permissions/status, one entry per mistake
(index, package, key, message, today, fix, serious, and applied on a serious one about an allow rule), and a warning for each serious one;
findingsinGET /permissions/unshipped;- a
[dbbasic] SERIOUS permission policy mistake, rule N key ...startup
line per mistake while permission checks are on;
findingsin a restore's policy-difference preview, for the file the
restore would put back.
serious marks the mistakes that make the policy allow more than written: a key that would narrow an allow (row_filter, collection, object_id, fields, denied_fields, valid_from, expires_at) that is ignored or null, a deny that can never apply (a principal that matches nobody, an expiry that does not parse, a filter that matches no row), and an ignored rules or admin_roles. The text names rules by index and package tag and keys only: never a rule's reason or a user id. To fix one, edit the rule as the fix says and save the policy; the save checks your edit.
A save cannot quietly make a serious mistake "written". Saving rewrites the file as the engine reads it, so a dropped rowfilter would come back as an explicit allow on every row and the report would vanish without anyone having decided it. So while the stored file has a serious finding, a save whose policy still holds the affected rule in that widened form (as GET returns it) is refused with a 400 naming the finding: rule index, package tag, key, what it does today and how to fix it (problems carries the findings, indexed as in the stored file). Fix the rule or remove it in the same save; any other edit waits until then. For an ignored rulez or admin_role, write the rules or admin_roles you meant. Smaller (non-serious) findings never block a save.
A package install does not erase a serious finding either. Installing (or retiring a package's rules) rewrites the policy file, and it used to write every rule as the engine reads it, so a misspelt rowfilter came back as a plain allow on every row and the alert went away. A stored rule with a serious finding is now written back exactly as the file held it, mistake included. The engine reads it the same way, so no decision changes, and the finding stays reported until you fix the rule with your own save.
The same holds for a misspelt top-level key with a serious finding (rulez, admin_role): an install writes the key back under the same name with the same value. The engine goes on ignoring it, so the rules under rulez still do not apply and the default admin roles still do; the finding and its alert stay until your own save writes the rules or admin_roles you meant. An unknown key whose finding is not serious is dropped by an install, as before.
Not applying an allow that is wider than written
DBBASIC_POLICY_FAIL_CLOSED_WIDENED_ALLOWS (default: off; 1, true, yes or on turns it on) changes what the engine does with one kind of serious finding. While it is on, every stored allow rule with a serious finding grants nothing: decisions are made as if the rule were not in the policy. That is an allow whose narrowing key (row_filter, collection, object_id, fields, denied_fields, valid_from, expires_at) is misspelt and so ignored, or is null. The own-rows allow with a misspelt row_filter then shows its users none of the rows, their own included, instead of all of them: the engine does not guess what the key was meant to say. Rules written correctly in the same policy grant as before.
The rule is not removed. It stays in the file and in GET /permissions/policy, a save still has to fix or remove it, and a package install that rewrites the policy writes the rule back as the file held it. Fix the key as the finding's fix says and save, and the rule grants what was written.
The finding says which of the two applies, in today, in the /admin/status alert and in the /permissions/status warning, and a serious finding on an allow rule carries applied:
- setting on: "... ; this rule is not applied",
"applied": false; - setting off: "... ; this rule applies more widely than written; set
DBBASIC_POLICY_FAIL_CLOSED_WIDENED_ALLOWS to stop applying it", "applied": true.
With the setting off no decision changes. Rules a package installs carry no findings, so they are unaffected either way. If the findings cannot be worked out while the setting is on, the policy is treated as one that cannot be read: requests are refused the way they are for a policy file that does not parse, and /admin/status says so.
Deny rules are never touched by this setting. A deny with a finding (one that can never apply, or one whose dropped key makes it apply more widely) is applied, or not, exactly as before, on and off. Whether a deny that never applies should also fail closed when read is still the owner's open decision (docs/dron.md). The serious findings that are not about a rule (an ignored rules or admin_roles key) are not changed either. The default is off in this release and may turn on in a later one; set the variable to false to keep today's behaviour whatever the default becomes.
Identity subjects can come from trusted headers, the admin token, or DBBASIC session tokens. The session tokens are backed by a small local registry:
data/identity/accounts.tsv
data/identity/users.tsv
data/identity/sessions.tsv
Accounts carry tenant/subscription defaults. Users carry account membership, roles, and user-level subscriptions. A session minted for a registered user takes that account, role, and subscription data from the user's current rows on every request (see "When a role change, disable or delete takes effect"), giving permission checks the same subject shape whether the request came from Scroll, a gateway, or a future DBBASIC login object.
New DBBASIC-created accounts, users, sessions, shared links, record IDs, and change/audit IDs should use UUIDv4 values. Imported systems can keep their old integer or slug IDs as compatibility columns, but new routes and generated UI should not depend on sequential IDs. This keeps SaaS-style tenant data, temporary links, subscriptions, shared records, and future package exports from being tied to one database sequence. The identity registry still accepts string IDs so Django/PostgreSQL data and older Scroll prototypes can migrate without a flag day.
Scroll and tests can preview decisions without persisting draft rules:
POST /permissions/check
Authorization: Token <token>
Content-Type: application/json
{
"policy": {
"access_mode": "role_based",
"rules": [
{
"effect": "allow",
"principal": "role:sales",
"actions": ["read"],
"collection": "contacts",
"row_filter": {"owner_id": "$user_id"}
}
]
},
"subject": {"user_id": "7", "roles": ["sales"]},
"action": "read",
"collection": "contacts"
}
If policy is omitted, /permissions/check uses the persisted policy file. The optional now field accepts an ISO timestamp for testing temporary access windows.
A check that names an object_id is answered by the same function the object routes' gate uses, so the preview and the gate cannot disagree: the collection comes from the id, not from the request, and a user object is decided as Access Modes and Sharing describe.
Route Enforcement
The public server can enforce the persisted policy against object routes and collection-record routes, but it is intentionally opt-in while auth and Scroll editing mature.
DBBASIC_ENABLE_PERMISSION_ENFORCEMENT=true
Requested enforcement is always enforced. With that flag set, every request is decided by the policy, from the first request to the last. There are three modes, and permissions.mode in /permissions/status, /identity and /admin/status names the one in force:
mode | Flags | What requests get |
|---|---|---|
off | neither | objects open per route rules, collection data admin-gated, no audit |
audit | DBBASIC_ENABLE_PERMISSION_AUDIT=true alone | the same as off; every decision is logged with enforced: false |
enforced | DBBASIC_ENABLE_PERMISSION_ENFORCEMENT=true | every decision applied (and audited) |
Shadow (audit) mode exists only when you ask for it. It used to be a fallback as well: the readiness checks below ran on every request, and while any of them failed a requested enforcement was quietly switched off, so the request was decided, logged and served anyway, to anonymous callers too. A box that started fenced went open at runtime when its last session expired, its last user was disabled, its users file became unreadable or its policy file was corrupted. Nothing does that any more.
Readiness problems are reported, not acted on by opening. Each one is handled by what the enforced request path does about it:
| Problem | What non-admin requests get | Way back in |
|---|---|---|
no admin token (DBBASIC_ADMIN_TOKEN) | the policy's decisions; nobody can use the admin APIs over HTTP | the server refuses to start without one (below) |
identity store unreadable (data/identity/*.tsv) | a request carrying a session or API key: 503 identity_store_unavailable with Retry-After; a request without one: what the policy grants anonymous callers | fix the file on the box; the admin token still works for diagnosis |
a user's account row missing or broken (their account_id has no row in accounts.tsv, there is no accounts.tsv, or the row does not parse), or their rows in users.tsv naming different accounts | that user's sessions and API keys: 403 account_unusable; their sign-in: 403 account_unusable after the right password; other users: unaffected | restore or fix the row (GET /admin/ops?kind=auth&event=account_unusable names the user, account and reason); or move the user out of the account; for reason=conflicting, remove the duplicate user row |
| policy invalid or unreadable | 503 permission_policy_unavailable; the parse error is shown only to the admin token | PUT /permissions/policy with the admin token, or the shell |
password access mode (no verifier exists) | 401 unless an explicit allow rule matches | PUT /permissions/policy with another mode |
| no non-admin sign-in path (the last session expired, the last user was disabled, none configured) | anonymous: what the policy grants anonymous callers, the rest 401/403 | the admin token: create users and mint sessions; /setup on a waiting one-click box; turn on a sign-in path and restart |
Every request loads the policy, the admin token's included. When the load fails, an admin-token request is decided against the built-in default policy instead (whose admin roles let it through), so the owner still reads, runs and repairs while the policy file is broken; everyone else gets the 503. What the console sees with the admin token on a broken policy:
GET /admin/statusandGET /permissions/status:200, with a leading
alert "Permission policy file is invalid: <error>" (or "could not be read"), permissions.policy.valid: false, mode still enforced; counts that need the policy are null (inventory.unavailable lists them).
GET /permissions/policy:200with `{"policy": null, "error": "...",
"raw": "<file text, first 64 KB>", "raw_truncated": false}; raw is omitted when the file cannot be read at all. A non-admin gets the 503 with no detail. Repair with PUT /permissions/policy`.
- Routes whose answer depends on the policy's rules (collection and schema
listings, collection detail and change history, GET /permissions/unshipped, search) answer 503 permission_policy_unavailable with error_detail, so a collection never quietly becomes known or unknown. An admin-role user signed in with a session is not the admin token: which roles are admin is named in the policy, so they wait for the repair like everyone else, and with DBBASIC_ENABLE_SESSION_ADMIN_GATES their session does not pass the admin gates either until the policy can be read. WebDAV answers the same 503 rather than an empty folder, which a sync client would take as every file deleted.
A single-record read (GET /collections/{c}/records/{id}, GET /api/files/{id}) is decided at the collection level before the record is looked up, and a row the caller may not read answers the same 404 as an id that does not exist, so the status tells nobody which ids exist.
A person's files have two ways in, /api/files and the WebDAV folder /dav/files/, and under enforcement both ask the same questions in the same order: may this subject do the action on the files collection at all (no record, so no owner fallback), and only then may they do it to this file. Every WebDAV verb that reads the folder (PROPFIND, PROPPATCH, GET, HEAD, PUT, DELETE, MOVE, COPY) needs read on the collection first; then DELETE needs delete, a rename or a replacing PUT update, a new file create. A folder the caller may not read is a 403, never an empty listing. Under a policy with no files rules the owner is refused on both, as on the record routes (Ownership).
At startup the server logs a WARNING naming each problem and the fix, and GET /admin/status leads with it in alerts ("Permission enforcement is ON, and ..."). After startup, at most once a minute per process, the server re-checks: a new problem is logged as an ERROR, a cleared one as INFO, and each change is an ops-log row (GET /admin/ops?kind=permission_readiness).
The one refusal: no admin token. Enforcement without DBBASIC_ADMIN_TOKEN refuses to start (the ASGI lifespan reports startup failed, so uvicorn exits): the token is the way in for every other problem, and the only way to repair a broken policy over HTTP. For one release, DBBASIC_ALLOW_START_WITH_BLOCKED_ENFORCEMENT=true starts it anyway, enforced, with a startup line saying so; the repair for any problem is then the shell. It used to start the server unenforced, and no longer does; it goes away in a later release. To serve without enforcement on purpose, set DBBASIC_ENABLE_PERMISSION_ENFORCEMENT=false and DBBASIC_ENABLE_PERMISSION_AUDIT=true.
Requiring enforcement. A hosted, multi-user box should set DBBASIC_REQUIRE_PERMISSION_ENFORCEMENT=true. The server then refuses to start unless the mode is enforced (off and audit both refuse), with one line: Refusing to start: DBBASIC_REQUIRE_PERMISSION_ENFORCEMENT=true and permission enforcement is off; set DBBASIC_ENABLE_PERMISSION_ENFORCEMENT=true. It is opt-in and changes nothing unset. Like the admin-token refusal it is checked in the ASGI lifespan, so a server run with the lifespan turned off (uvicorn --lifespan off) skips it.
DBBASIC_ALLOW_UNREADY_PERMISSION_ENFORCEMENT no longer does anything (it used to force enforcement despite the readiness checks, which is now what always happens); the server says so at startup. Remove it.
A fresh box is enforced from its first request. The supported order for a fresh box with enforcement on:
- set
DBBASIC_ADMIN_TOKEN(the way in while nobody else can sign in); - turn on a sign-in path:
DBBASIC_ENABLE_PASSWORD_LOGIN=true, trusted
headers, guarded session login, or an identity source;
- save a policy before the first start, e.g.
object_permission_store.replace_policy(object_permission_store.starter_policy_payload(), base_dir=DATA_DIR) if you want the starter grants (a one-click box does not: its policy is the rules its starting apps ship). Skipping it is safe: the box starts deny-all and you save one later with PUT /permissions/policy or by installing packages, using the admin token;
- start, and make the first admin through
/setup(a one-click box, which
answers only /health and /setup until then) or with the admin token.
Without step 1 the server refuses to start. Without step 2 it starts enforced with a warning: only the admin token and public grants get in.
Operators can see the state through:
{
"permissions": {
"mode": "enforced",
"enforcement_requested": true,
"enforcement_enabled": true,
"enforcement_blocked": false
}
}
enforcement_blocked is always false now and is kept for one release for clients that read it.
When enforcement is on, protected routes call the same decision engine before serving or executing data:
flowchart LR
A["HTTP request"] --> B["map subject"]
B --> C["map route to action"]
C --> D["load data/permissions/policy.json"]
D --> E["check_permission"]
E --> F{"allowed?"}
F -- yes --> G["serve route"]
F -- no --> H["return 401 / 402 / 403"]
E --> I["append data/permissions/audit.jsonl"]
Route actions currently map like this:
GET /objects/{id}->executePOST /objects/{id}->executePUT /objects/{id}->updateDELETE /objects/{id}->delete?source=true->source?state=true->state?logs=true->logs?versions=trueor?version=N->versions?metadata=true->readGET /collections/{collection}/records->readPOST /collections/{collection}/records->createGET /collections/{collection}/records/{record_id}->readPUT /collections/{collection}/records/{record_id}->updateDELETE /collections/{collection}/records/{record_id}->delete
Collection record lists apply row filters before pagination. Record detail checks include the selected record, so owner, account, subscription, temporary access, row-filter, and field-redaction rules can all be enforced by the server. Record writes check the affected record. Updates also check the candidate row after applying the submitted changes, so a user cannot pass a row filter on the old row and then move the row into another owner/account by changing fields. Both checks read the row before the write lock, so the write carries that row's fingerprint and is refused with 409 "code": "conflict" (nothing written) when the row under the lock is another one: a row given to someone else between the check and the write is not written on the old decision. The client reads it again and retries, and the retry is decided on the row as it now is (docs/dron-write-semantics.md S52).
By default the collection record routes are admin-token gated. Read routes can use audit or enforcement mode with the active policy. Write routes require the admin token unless permission enforcement is enabled and the active policy allows the matching create, update, or delete action. Audit-only mode logs write decisions, but it does not authorize mutations by itself.
Row-filter index
With enforcement on, a list of a collection (and /api/search, an anonymous visitor's public rows, and the relation-label fetches a form makes) runs the decision engine once per row of the WHOLE collection, for a user who may see a handful. Measured in a full install: 10,044 engine calls and about 94% of the request to list 40 visible notes out of 10,000.
DBBASIC_ROW_FILTER_INDEX=off | shadow | on (default: off)
off-- every row is read and checked. Today's behaviour.on-- the server first plans, from the policy and the subject alone,
the equality lookups that are a superset of the rows the subject could be allowed ("owner_id is u7", "project_id is one of p1, p2", "is_public is true"), finds those rows through a per-field index kept beside the records cache, and runs the engine on them only. The engine still decides every row that is returned, so the index can never show a row it should not; the differential tests (tests/test_row_filter_pushdown.py, ..._http.py) are what stop it from hiding one. Responses are identical to off: same rows, order, total, count, has_more, revs, redaction.
shadow-- both are computed, the full scan is served, and any
difference is recorded as a row_filter_shadow row in the ops log (GET /admin/ops?kind=row_filter_shadow): ids and counts, never record contents. At most one row per collection per minute and 200 in the life of a process, so a wrong index cannot crowd login failures out of the log the lockout reads. Run this before on; it costs more than off.
A list is not narrowed, and costs what it does today, when: the subject is an admin; the access mode allows reads without rules (public, registered, subscription); a rule that applies has no row filter (the subject sees everything) or only ne / range conditions; any filter in the policy uses an unknown operator; the collection is too large for the records cache (DBBASIC_RECORDS_CACHE_MAX_ROWS); or the only equality a rule has is on a store: extra field. Deny rules never narrow.
The index is built lazily, one field at a time, by the first narrowed read after each write to a collection, and only for the fields that rules and the owner keys (owner_id, user_id, created_by) compare by equality. It costs 4 bytes per row per field plus about 120 bytes per distinct value of that field, and 0.3-0.9 ms per field per 10,000 rows to build. Measured on 10,000 notes with the five fields the notes rules use: 3 ms to build, 0.4 MiB (40 bytes per row in all); 30,000 notes: 9 ms, 1.2 MiB. The worst case is a field whose every value is different, about 120 bytes per row (60 MB for one such field at the cache's 500,000-row ceiling); id, the usual such field, reuses the cache's existing id index and costs nothing. The index lives and dies with the records cache entry it describes, so it has no invalidation of its own, no file, and no knob beyond the cache's (DBBASIC_RECORDS_CACHE_MAX_ENTRIES, DBBASIC_RECORDS_CACHE_MAX_ROWS).
Time-windowed rules (valid_from / expires_at) are evaluated at one instant per list request, in every mode: the collection check, the row filter, a field filter and the field redaction all decide at the same reading of the clock. (Before 2026-12, off read the clock once per check, so a list running across the instant a rule's window closed could let a row through under the rule and then redact it under no rule, which removed nothing.)
Audit-only mode logs decisions without blocking the request:
DBBASIC_ENABLE_PERMISSION_AUDIT=true
It serves exactly what off serves: collection records, record detail, search and user files still need the admin token, as they do with no permission flag at all; objects answer per their route rules. (Until this release, turning the audit log on skipped those admin gates and served every row to anyone, so the observer changed what was served.) That is useful before turning enforcement on for a live app. Enforcement also writes audit entries.
The audit log is bounded like object logs. When data/permissions/audit.jsonl reaches DBBASIC_PERMISSION_AUDIT_MAX_BYTES (default 10485760; 0 or less never rotates) it is cut into audit-<sequence>-<timestamp>.jsonl beside it. Each segment is gzip-compressed at the following cut, and only the newest DBBASIC_PERMISSION_AUDIT_KEEP_ROTATED segments are kept (default 32; 0 or less keeps all). The audit endpoint reads back through the segments when the active file holds fewer matching entries than limit.
Operators and Scroll can read recent audit entries through the admin-gated audit endpoint:
GET /permissions/audit?limit=100&object_id=site_home
Authorization: Token <token>
Supported filters are action, object_id, collection, allowed, and enforced.
By default, route checks only trust the admin token and anonymous public traffic. If a reverse proxy or auth gateway has already authenticated the request, trusted identity headers can be enabled explicitly:
DBBASIC_PERMISSION_TRUST_HEADERS=true
Supported headers:
X-DBBASIC-User-IdX-DBBASIC-Account-IdX-DBBASIC-RolesX-DBBASIC-Subscriptions
Only enable trusted headers behind infrastructure that strips or overwrites client-supplied copies.
Identity sources
An identity source is another service vouching for who a caller is (object_identity_sources.py). It takes the request headers and returns a principal -- user id, optional account id, roles, display name -- or nothing. Sources are configured from the environment, consulted in order (first answer wins), and fail closed: an exception, a timeout, a non-200, an oversized, redirected or non-JSON answer all mean "not authenticated by this source".
Order of resolution for a request (_permission_identity):
- the admin token -- always wins, and is never forwarded anywhere;
- a
dbk_API key; - a local session (Authorization header or cookie);
- configured identity sources, for an Authorization token none of the
above recognised (cookies are never forwarded);
- trusted headers, when
DBBASIC_PERMISSION_TRUST_HEADERS=true; - anonymous.
A principal becomes the same PermissionSubject a session user gets (user id, account id, roles, then project grants and record shares), so the permission engine, owner fallback, audit log and the _identity an object sees treat it exactly like a local user; GET /identity reports auth.method as identity_source:<name>.
A remote identity may not take over a local user. When the upstream's user_id names a user in this box's registry (users.tsv; users are keyed by user id here, and the verify answer carries no email), the identity is refused unless that local user is explicitly linked to the source -- the user's identity_source field equals the source name (http_verify). Unlinked is the default for every user. Link one with identity_source in POST /identity/users, or from the shell:
python -m object_identity_cli set-identity-source --user-id 7 --source http_verify
python -m object_identity_cli set-identity-source --user-id 7 --unlink
Only a row in users.tsv makes a user id local. A password, sessions or API keys left under an id with no row (a user removed by hand) do not, and a remote identity with that id cannot reach them: keys and passwords are managed only with that user's own local session or the admin gate, password sign-in needs a user row, and a session or key works only for whoever holds its token. Creating a local user under such an id refuses or clears them first (POST /identity/users, clear-leftovers).
A refusal is an auth ops-log row, event: identity_source_collision, with the user id and auth_method: identity_source:<name> (never the token or its hash), at most one a minute per source and user id. A linked user id the local registry has disabled is refused too, as for trusted headers.
A source confers only the roles you allow. DBBASIC_IDENTITY_VERIFY_ALLOWED_ROLES (comma-separated, e.g. viewer,editor) lists the role names the verify source may confer. Unset or empty, it confers none: the upstream says who somebody is, and only an operator decides which of its role names mean anything here. Roles the upstream names outside the list are dropped, and the drop is an auth ops-log row (event: identity_source_roles_dropped, label: roles=<names>, the user id; at most one a minute per source and user id). A malformed name in the setting refuses the source (an ERROR at startup).
A source can never make anyone admin. admin, superuser and every role in the policy's admin_roles are stripped from what a source says even when the allowlist names them (all roles are dropped if the policy cannot be read), upstream flags such as is_staff/is_superuser are not read, and the operator gates (admin token, admin session) never consult sources. Note that a policy's own user_roles entry for that user id still applies -- that is the operator granting it, not the upstream.
The user id must be a canonical positive integer -- a JSON int, or a string of digits with no sign, whitespace or leading zero -- because it is the u_<id>_ object namespace (see User objects). "007", " 7", 7.0 and true have authenticated nobody. An account_id, when the answer carries one, must match the account id rules (letters, digits and _ . : @ -, starting with a letter or digit, at most 128 characters), so "../x" is refused. The answer must also declare Content-Type: application/json (a ; charset= suffix is fine); an HTML error page with a JSON-looking body is not an answer.
The first source is http_verify:
DBBASIC_IDENTITY_VERIFY_URL=https://app-internal:8443/api/auth/verify/
DBBASIC_IDENTITY_VERIFY_SECRET=<shared secret, 16-512 visible ASCII characters>
DBBASIC_IDENTITY_AUDIENCE=box-a.example.com
Off when unset. The source is refused -- not used at all, an ERROR line at startup says why (never quoting the secret), GET /admin/status lists the same reason in alerts and in capabilities.identity.identity_source_refused, GET /permissions/status in permissions.identity_source_refused and warnings (none of them quote the secret or the URL), and its users arrive as anonymous -- when:
- the URL is not
https://, unless its host is loopback (127.0.0.0/8,
::1 or the name localhost; a Compose service name or a private address is not loopback). A URL with user:password@ is refused too. The same check runs again before every call, and redirects are never followed, so a credential never crosses plain http to another host;
- the host is not loopback and
DBBASIC_IDENTITY_VERIFY_SECRETis unset
(or is not 16 to 512 visible ASCII characters with no spaces);
DBBASIC_IDENTITY_AUDIENCEis unset or not a name (letters, digits and
_ . : @ / -, starting with a letter or digit, at most 256 characters).
A configured source also counts as a user sign-in path in the enforcement readiness check (/permissions/status shows permissions.identity_source_configured). For a request carrying Authorization: Token ... (or Bearer ...) it sends that header verbatim in a GET with Accept: application/json to the URL (a 3 s deadline for the whole exchange -- connect, TLS, headers and body -- 64 KiB response cap, no redirects followed, no proxy), and maps an HTTP 200 JSON body naming this server as its audience to a principal.
Wire shape, for whoever implements the verify endpoint. The request:
GET /api/auth/verify/
Authorization: Token <the caller's token, verbatim>
Accept: application/json
X-DBBASIC-Audience: box-a.example.com
X-DBBASIC-Verify-Secret: <DBBASIC_IDENTITY_VERIFY_SECRET>
X-DBBASIC-Verify-Secret is omitted when no secret is configured (loopback only). The endpoint should compare it in constant time and refuse a request without it, and should check that the token may be used at the box named in X-DBBASIC-Audience. A token it recognises is answered 200 with Content-Type: application/json:
{"audience": "box-a.example.com", "user_id": 7, "username": "alice",
"account_id": "acct_1", "roles": ["editor"]}
audience is required and must be a string equal to this server's DBBASIC_IDENTITY_AUDIENCE -- a missing, different or list-valued audience authenticates nobody (cached as a refusal for 10 s). user_id is required; username, account_id and roles are optional.
The two refusals mean different things, so send the right one:
401: the token is not valid (unknown, expired, revoked, not usable
at this audience). The request itself was acceptable: the shared secret matched and the audience is one the endpoint serves. One user's sign-in fails; nothing is recorded.
403: this server is not accepted, whatever the token: a missing or
wrong X-DBBASIC-Verify-Secret, or an X-DBBASIC-Audience the endpoint does not serve. Every sign-in fails, so the server records it for the operator (below).
For the caller both are the same: the token is refused and the request goes on as anonymous. Anything else (another status, a redirect, a timeout, a body over 64 KiB) means "could not check" and the caller gets 503. Answers are cached, keyed by a SHA-256 of the header value -- raw tokens are never stored or logged -- in a cache bounded to 4,096 entries: positive answers for DBBASIC_IDENTITY_CACHE_TTL_SECONDS (default 30; a larger value than 60 is clamped to 60 with a WARNING at startup, and nothing in the upstream's answer extends it), a definite refusal (401, 403, or a 200 that is not a valid principal) for 10 s. The lookup runs in a thread before routing so a slow upstream never blocks the event loop.
An upstream that answers 403 (it refuses this server), or answers 200 without this server's audience, or with something that is not a JSON object, refuses every user it vouches for, which from outside looks like "everyone is logged out". The sign of it: an auth ops-log row, event: identity_source_audience_refused (one event for every "the upstream is not accepting this server" reason), auth_method: identity_source:<name> and label: reason=upstream_forbidden refused=<n> (the upstream answered 403: check that DBBASIC_IDENTITY_VERIFY_SECRET here and the upstream's secret match, and that DBBASIC_IDENTITY_AUDIENCE matches the upstream's audience setting) or reason=audience_missing (the answer has no audience key -- an upstream not yet updated to echo it) or reason=audience_mismatch (the key is there but is not this server's name) or reason=not_json (the 200 is not a JSON object: an HTML page such as a login page the upstream redirected to, a list, text that does not parse), at most one row a minute per source and reason, <n> counting the answers refused since the previous row. GET /admin/status lists an alert saying the same in plain words for ten minutes after the last such answer, naming every reason seen; it clears at once when the upstream answers 200 with the right audience. Neither quotes a token, a user, the URL, the secret or the audience value. A 401 leaves no row and no alert, even when every answer is one: on a quiet box that is just users with stale tokens.
A credential the server could not check is a 503, not "anonymous". When all 8 verify slots are busy (each is held for at most the 3 s deadline, so a slow upstream cannot keep them), or the verify service is unreachable, times out or answers 5xx (or anything other than 200/401/403), a request that carried an Authorization token meant for the sources is answered 503 with Retry-After: 2. Such failures are never cached, so users are recognised again the moment the service is back. Requests with no Authorization header, the admin token, dbk_ keys and local sessions never touch the verify path.
Revocation. A revoked token keeps working until its cache entry expires (at most the TTL). To cut that short, the upstream calls, with the admin token:
POST /admin/identity/sources/forget
Authorization: Token <admin-token>
Content-Type: application/json
{"token_hash": "<sha256 hex of the Authorization header value>"}
or {"all": true}. The hash is sha256("Token abc123") over the full header value, lower-case hex -- the server never accepts, logs or echoes a raw token here. The answer is {"status": "ok", "forgotten": <n>}. A lookup that was in flight when the entry was forgotten does not store its answer.
One Authorization header only. A request with more than one Authorization header is refused with 400 on every route, so a proxy and this server cannot pick different credentials.
Point it only at a trusted internal service you control. Every caller's credential is sent to it, and whatever it answers for this audience is believed. Only https URLs (or http to loopback) are accepted; anything else configures no source.
The verify service's user ids share the id space with the local identity registry (and so the u_<id>_ objects, grants and shares). A box can use both only for ids that do not collide, or for local users an operator has linked to the source (above).
The server can also mint DBBASIC identity sessions:
POST /identity/sessions
Authorization: Token <admin-token>
The admin route can mint arbitrary operator-controlled sessions. For a login gateway or local trusted client, POST /identity/session can mint a session for an existing active user when DBBASIC_ENABLE_SESSION_LOGIN=true and the caller presents DBBASIC_SESSION_LOGIN_TOKEN. That token is separate from the admin token. The route accepts only user_id, label, and ttl_seconds; role, account, and subscription overrides are rejected so the subject comes from the registered user and account.
Sessions store only a token hash under data/identity/sessions.tsv. Requests can then send Authorization: Token <session-token> or Authorization: Bearer <session-token>, and the server resolves the subject directly from its local identity store. This is the first built-in replacement for each app hand-rolling the same "current user, current account, current roles, current subscription" lookup.
When a role change, disable or delete takes effect
A credential never carries more than its user has now. Sessions and API keys name a user; on every request the server reads that user's row in data/identity/users.tsv (a stat-cached parse, re-read when the file changes, whoever changed it) and takes the user's standing and roles from it. So, whether the change came through the admin routes, the CLI, another process or a hand edit of the file:
| Change | Sessions | API keys |
|---|---|---|
| a role removed | gone on the next request | gone on the next request |
| a role granted | applies on the next request, no new sign-in | applies on the next request |
user disabled (any status but active) | refused on the next request and ended (marked revoked) | refused on the next request and deleted |
| user's row deleted | refused on the next request and ended | refused on the next request and deleted |
| user re-enabled, or re-created with the same id | old sessions stay ended: sign in again | old keys stay deleted: mint new ones |
| password reset by emailed link | every session revoked | not touched |
| password set, changed or removed by an admin (HTTP route or CLI) | every session revoked | not touched |
| an admin changing or removing their own password with their session | every session revoked except the one making the request | not touched |
first password (signup confirmation, first-time setup, create-superuser) | nothing to revoke | not touched |
the user's account disabled (PUT /identity/accounts/{id}/status, disable-account) | refused on the next request and ended | refused on the next request, kept |
| the account re-enabled | old sessions stay ended: sign in again | work again, unchanged |
| the account's subscription removed (a billing lapse) | still signed in; subscription: rules stop matching on the next request | unaffected: keys never carry the account's subscriptions |
Password changes revoke at the moment of the change, in the one function that writes the password (object_credentials), so it does not depend on enforcement or on which route or tool did it. If the new password is saved but the sessions cannot be ended, the change is reported as a failure (HTTP 500 password_sessions_not_ended, CLI exit 1), not success; setting the password again retries. API keys are a separate credential and survive a password change. If the account may be compromised, a new password is not enough on its own: revoke the user's keys (DELETE /identity/users/{id}/api-keys/{key_id}) or disable the user (PUT /identity/users/{id}/status or /offboard, which end sessions and delete keys).
"Ended" for the other rows happens when the credential is next presented. The status and offboard routes revoke everything at once anyway; a status or deletion made outside them is refused immediately and ended at first use. A user deleted by hand and re-created with the same id before an old session or key is presented again would find it alive, with the new row's roles, so creating a user looks for credentials left under its id first: a password, sessions still signed in, API keys. By default (POST /identity/users, the CLI's create-user) the create is refused and nothing changes, with an error naming what was found; python -m object_identity_cli clear-leftovers --user-id <id> removes them (only for an id with no user), and then the id is free. A signup clears them itself, with a warning in the log, since its id is new and random. First-time setup and create-superuser keep the password they have just written but end leftover sessions and delete leftover keys, since they wrote neither.
Roles granted through the policy's user_roles map are policy, not identity, and always applied on the next request.
Subscriptions and account membership follow the same rules as roles. A session's account is the user's current account_id, and its subscriptions are the user's own plus their account's, read from users.tsv and data/identity/accounts.tsv (stat-cached the same way) on every request. So a subscription cancelled on the user or on the account stops matching subscription: rules on the next request; a user moved to another account is in the new one (account: rules, $account_id row filters) on the next request, and a user taken out of one has no account. An account whose row is gone contributes no subscriptions; a disabled account refuses its users altogether (below). API keys read the user's row on every request too and have the user's own subscriptions and account; they do not add the account's subscriptions.
Disabling an account, and a billing lapse
Two different operations, for two different situations:
- Disable the account (
PUT /identity/accounts/{id}/status
{"status": "disabled"}, or object_identity_cli.py disable-account --account-id {id}) when nobody from that account may use the box at all: abuse, a compromised tenant, a contract ended. On the next request every session and API key of its users is refused (whatever their roles, admin included, as for a disabled admin user), its users cannot sign in, and their sessions are ended. API keys are kept but refused, so a mistaken or temporary disable does not break the customer's integrations for good. Re-enabling ({"status": "active"}, enable-account) lets them sign in again and makes the same keys work again; no session comes back. The admin token, and admins who are not in the account, are never affected, so an operator cannot lock themselves out this way. The route writes an account_status_set ops line. Details in http-api-contract.md ("Account Status").
- Remove the subscription for non-payment. A billing lapse is not a
disable: the customer has to be able to sign in to pay. Take the plan out of the account's subscriptions (and the user's, if it was granted there): on the next request subscription: rules stop matching, while the user stays signed in, can sign in fresh, keeps the account (account: rules, $account_id filters) and their API keys. Putting the subscription back applies on the next request, with no new sign-in. Use PUT /identity/accounts/{id}/subscriptions {"subscriptions": [...]} (the whole list; [] for none) or object_identity_cli.py set-account-subscriptions --account-id {id} --subscriptions pro,team: input is validated, the write is atomic, and each change leaves an account_subscriptions_set ops line with who did it and the list before and after (http-api-contract.md, "Account Subscriptions"). A hand edit of the subscriptions column of data/identity/accounts.tsv is still picked up on the next request, but is neither validated nor recorded. A member's subscriptions are their own (user row) plus the account's, so a name the user holds on their own row survives its removal from the account; API keys carry only the user's own. Plan the rules so that what a lapsed customer still needs (their invoices, the billing page) is granted to registered or account: principals, not only to subscription: ones.
To check this, accounts.tsv is consulted on every request of a user who has an account, by session or API key (one stat, re-parsed only when the file changes; users with no account do not touch it). If it cannot be read the request is 503 identity_store_unavailable under enforcement and carries no credential otherwise, as for users.tsv (below); nothing is revoked or deleted. An account row that does not parse refuses its users without ending anything, so fixing the row restores them. A user whose account_id names an account with no row at all (or when there is no accounts.tsv) is refused the same way; this used to refuse nobody. Both are fail-closed refusals with their own code: under enforcement every request with such a user's session or API key is 403 account_unusable (a fixed message; the admin token sees which account and why in error_detail on admin routes), otherwise the credential carries no authority; signing in is 403 account_unusable in both modes, and only after the right password, so nobody learns of it without one (the browser form redirects to /login?error=account). Each refusal writes an account_unusable ops auth line naming the user, the account and reason=missing or reason=unparsed (at most one a minute per user, account, reason and method). A user with several rows in users.tsv that name different accounts (or where one names none) is refused the same way, reason=conflicting, with every account named as the identifier (acme,globex; (none) for a row naming none): those rows used to merge into a user with no account, which skipped every account check. Duplicate rows that agree are read as before. Nothing is ended or deleted, so restoring the row restores everyone. Users whose row names no account (a single-user install, users created before accounts existed: an empty account_id or no such column) never read accounts.tsv and are not affected by its state. An ad hoc session for a user id with no row, and an account id asserted by a gateway or identity source, are not refused for naming an account this box has no row for. A disable written outside the route ends each session the first time it is presented, like a user disabled by hand.
Which roles, subscriptions and account a session has depends on how it was minted:
- From the user's row (every sign-in route, and
POST /identity/sessions
without roles or subscriptions): the user's current roles, account and subscriptions.
- With explicit
rolesorsubscriptions(POST /identity/sessionsfor
a registered user): the roles and subscriptions it was minted with less any the user no longer has, and its account only while the user is still in it. A narrowed session stays narrow; nothing the user does not hold gets through; a role, subscription or account the user gains later needs a new session.
- For a user id with no row (an ad hoc gateway session; refused under
DBBASIC_REQUIRE_KNOWN_IDENTITY_USERS=true): the roles it was minted with, since there is nothing to compare them with. If a row for that id appears later, the row caps them. An API key for such an id authenticates as the id with no roles, as before.
- Written by an older server (a
sessions.tsvrow with noroles_from
column, or an api_keys.tsv row with no user_bound column): capped by the user's roles, subscriptions and account while the row exists, like an explicit session; a deleted user's old session keeps its stored values, and an old key the user id with no roles, until they expire or are revoked, because such rows cannot tell "deleted" from "never registered". Revoke them (PUT /identity/users/{id}/status) or wait out the session TTL (at most 30 days, 24 hours by default).
If users.tsv cannot be read, or is missing while a credential names a registered user, or accounts.tsv cannot be read when a session needs its user's account's subscriptions, the request is not guessed at: under enforcement it is 503 identity_store_unavailable with Retry-After (see Route Enforcement), otherwise it carries no credential. Nothing is revoked, so restoring the file restores everyone. A row that does not parse refuses that user's credentials without ending them, so fixing the row restores them.
Users from an identity source (above) have no local session and no stored roles here: their roles are the upstream's latest answer (less anything outside DBBASIC_IDENTITY_VERIFY_ALLOWED_ROLES), trusted for DBBASIC_IDENTITY_CACHE_TTL_SECONDS (30 s by default, never more than 60), or until POST /admin/identity/sources/forget drops it. That TTL is the bound on a role the upstream removed. A local row for the same id refuses them unless it is linked to the source (identity_source, above). A linked row that is disabled, or that names a local account that is disabled, refuses them on the next request, and so does an account id the upstream names when that account has a local row that is disabled; local roles do not cap or add to theirs. The trusted-header path (X-DBBASIC-User-Id, X-DBBASIC-Account-Id) refuses the same cases.
Clients can inspect or revoke their own active session without the admin token:
GET /identity/session
DELETE /identity/session
Authorization: Token <session-token>
Those routes require an active session token and do not treat the admin token as a user session.
The active subject can be inspected through:
GET /identity
Authorization: Token <token>
Admin-token-gated operator routes still require DBBASIC_ADMIN_TOKEN by default. A deployment can opt in to DBBASIC_ENABLE_SESSION_ADMIN_GATES=true; when enabled, an active DBBASIC session whose subject has one of the policy admin roles can pass the same gate. This is intended for Scroll/operator clients that should stop carrying the raw deployment token after login exists.
That endpoint returns the normalized user_id, account_id, roles, subscriptions, auth method, and permission-mode flags the server will use for route checks.
Operators and Scroll can inspect permission rollout readiness through:
GET /permissions/status
Authorization: Token <admin-token>
That endpoint summarizes the active mode flags, identity counts, persisted policy shape, covered route groups, readiness, and warnings. Readiness is advisory: it says what would hurt if enforcement were on now (or, when it is on, what is hurting), and never switches enforcement on or off. It is meant to be read before enabling enforcement on a live app. For identity-gated modes, one of these non-admin identity paths should exist, or only the admin token and public grants get in: trusted proxy headers, guarded session login for existing users, password login (DBBASIC_ENABLE_PASSWORD_LOGIN=true, counted before any user exists: the first one arrives through /setup, signup or the admin token), an active DBBASIC session, or a configured identity source (a valid DBBASIC_IDENTITY_VERIFY_URL; see below). The startup check counts an identity source as a sign-in path, so a deployment whose users sign in only through one reports no problem. A verify source that is set but refused (not https:// or loopback http://, no secret for a remote host, no audience, or empty) does not count, and the server makes no network call at startup to check that the verifier answers.
Access Modes
Access modes answer who gets through the front door.
public- anyone can read or execute public objects.password- a shared gate authenticates before policy checks.registered- any signed-in user can read or execute.subscription- signed-in users with an active subscription can read or
execute.
role_based- rules decide by role, user, account, owner, row, field, and
action.
private- owner-only fallback unless explicit rules grant access.
An access mode never opens a user object (u_<id>_<name>) to anyone but its owner. public, registered and subscription allow read and execute without a rule on system and package objects only; on a user object the mode's grant reaches user <id> alone, and everybody else is decided as in role_based: an admin role or an allow rule naming the object_id (see Sharing), otherwise 403 with "user object is not shared with this caller". A caller the mode itself refuses (anonymous under registered, no subscription under subscription) gets the mode's 401 / 402 as before.
This matters where the gate is asked about a user object on someone else's behalf: a site route or an override whose object_id is a user object. (/objects/{id} already answers a non-owner 404 before the gate is asked, in every mode.) Earlier releases ran such a route for any caller the mode let in. To keep a route to a user object open to others, add a rule naming the object:
{"effect": "allow", "principal": "public", "actions": ["read", "execute"],
"object_id": "u_42_report"}
Use registered, role:<name> or user:<id> as the principal to open it to fewer callers.
Rules
Rules answer what the subject can do once they are known.
Actions should stay small and explicit:
createreadupdatedeleteexecutesourcestatelogsfilesversionsshareadmin
Principal strings are portable on purpose:
publicregisteredownerrole:adminrole:salesuser:42account:customer-acmesubscription:pro
One more principal is not a subject at all: owner_fallback, valid only on a deny rule, switches the owner fallback off for the rule's actions and resource. See Ownership.
Explicit denies are checked before allow rules.
A deny rule with a row_filter is about some rows, so it does not match the collection-level question (a list, a search, a /ws subscribe, asked with no record): the list is allowed and the deny hides exactly the rows its filter names, per record. Before 2026-11-28 such a deny refused the whole list with 403 for every principal except owner.
Pointing at a record you may not act on
A rule decides who may write a row. It says nothing about the row that row points at, and a row that points at something usually acts on it: a refund takes money out of its payment, a payment marks its invoice paid, a line changes its order's total, a stock move changes a product's level. Until 2026-11-30 the shipped rules for all of those were "registered users create rows whose owner_id is their own", so any signed-in user could refund any customer's payment: the refund was theirs, the money was somebody else's.
A relation states what its writer must be allowed to do to the target:
{"name": "payment_id",
"relation": {"collection": "payments", "display_field": "reference", "requires": "update"}}
On a POST or PUT through the record API with enforcement on, the server reads the target and asks the engine, for the same subject and policy, whether it may read it and (for "update") update it -- exactly the question PUT /collections/payments/records/{id} would ask, owner fallback, project grants and roles included. Admins pass, as they pass every rule.
- Checked on create for every such field with a value, and on update for each
one whose value changes.
- A target the writer may not read gets the same 400 a missing one gets
(references a missing record), so the check is no oracle for ids. One they may read but not update gets a 403 naming the field.
- An unreadable target collection is a 503; nothing is written.
updatewhere the child moves money, stock or state of the parent (or a
rollup on the parent sums it); read where it is a reference (the contact an invoice is for, the project a note is filed under, a public category). A project member with a read grant can therefore still file a note under the project: the engine has no "write member" action on a project row to ask for.
- Trusted server-side writers (actions, webhooks, the daemon) write through
object_records and never reach it. An action that writes a child of a record it was handed asks object_access about that record itself (below).
tests/test_relation_requires_guard.py fails when a shipped collection that a non-admin principal may create or update has a relation with no requires and no stated reason (its EXEMPT) for going without, and when a writable child that a parent rolls up requires less than update on it. tests/test_relation_requires_collections.py probes every declared pointer over HTTP as a registered user who owns nothing involved.
Objects That Read Storage Directly
A page or action that reads records with object_records gets the raw row: the collection API's rules, row filters and owner checks do not run. Such an object is the only gate in front of what it shows or changes, so it asks the same engine with object_access:
access = object_access.Access(request.get("_identity"), base_dir=base)
order = access.get("orders", order_id) # None when missing OR refused
if order is None:
return not_found() # one answer for both: no oracle
if not access.can("update", "disputes", dispute):
return {"status": 404, ...}
rows = access.visible("wallet_entries", rows) # the rows the API would list
It answers what the API would for the same subject under the active policy, with two differences, both towards refusing: a request with no _identity is anonymous (an in-process caller that wants authority passes one explicitly); and an unreadable policy refuses everybody. Project and record-share grants are resolved by the server's own code (object_access.with_grants), so a rule that matches through $accessible_projects or $shared_records matches for a project member or a sharee exactly as it does over the API. Field redaction is not applied: the object renders the fields it chooses.
One difference goes the other way, and it matters for update and delete: the record API first asks the collection-level question with no record, and can() with a record does not. So where a collection has no rule for the action, the API refuses and can() answers with the owner fallback: yes, for the row's owner. A collection that must be read-only to its owners says so with an owner_fallback rule (Ownership); do not infer it from the absence of a grant.
The guard test: forgetting is a CI failure
Most access bugs found in November 2026 were an object that read or changed someone's record through object_records and never asked. The platform remembers the other rules for people; this one it checks. tests/test_object_access_guard.py parses (with ast, not grep) every packages/*/objects/site/*.py and packages/*/objects/action/*.py and fails on any reference to a public object_records reader or writer (read_collection_records, get_collection_record, create_/update_/ delete_collection_record, read_collection_records_where and the rest of the lists in the test) unless one of these holds:
- The file asks
object_accessabout that collection. AnAccess
object's .get(collection, id), .can(action, collection, record), .visible(collection, rows) or .reads_every_row(collection) appears in the same file, with the same collection (a literal, a module constant, or the same variable expression). Asking about orders does not cover order_lines: each collection needs its own question or its own exemption. The test checks that the file asks, not that the answer is used; reading the diff for that is still a person's job.
- The call carries an exemption comment on its own line or on a comment
line directly above it:
# access: box configuration
rows = object_records.read_collection_records("app_settings", base_dir=base)
The reason is a sentence a reviewer can check against the code around it ("box configuration", "system write after the access check above", "capability link: the invoice is found by its secret portal_token", "public catalog", "the caller's own row: owner_id is the caller's user_id"). Two reasons are checked against the rules files: admin-only object (...) needs every execute grant for the object to be role:admin (none at all also counts), and role-only object (...) needs at least one grant, all of them role:*. public ... needs a rule letting public read the collection, and covers reads only.
A hand-written owner_id == user_id test is not an exemption for the reason in Objects That Read Storage Directly: the ones that let a row with a blank owner through disagreed with the API for admins, roles and unowned rows, and were the bugs. Where the filter is strictly tighter than the engine (the caller's own rows and nothing else) say so in the comment; where it can pass a row the engine would refuse, use object_access.
New public functions in object_records must be classified in the test (reads rows, writes rows, or neither), so the list the guard enforces cannot go stale. Objects under objects/system, hook and webhook, and helper modules at the repository root, are not scanned.
Package Rules And Upgrades
An installed package's rules sit in the same policy file as the operator's, each stamped "package": "<id>" when the install appended it. Installing a package again (an upgrade) does two things to that file, in this order:
- Retires the rules the package has withdrawn. A live rule is removed
only when BOTH hold: it is tagged as this package's, and it is identical (everything but reason) to a rule the package is known to have shipped and no longer ships. "Known" is the rules recorded at the package's last install (permissions in data/package_baselines/<id>.json), or the retracted list in the package's permissions file (package-authoring.md).
- Appends the rules it ships that are not in the policy.
Until 2026-11-28 only step 2 existed, so a package that deleted a grant or added a row filter to one (a different rule) fixed new installs only: an existing box kept the old, wider rule, and an allow rule that is still in the policy still allows.
What an upgrade will not do is remove something it cannot prove the package put there:
- a rule with no
packagetag is the operator's, even when it is identical
to one a package withdrew (reported as operator_rule: it is now the only thing keeping that grant alive);
- a rule the operator edited keeps its tag but no longer matches what was
shipped, so it stays (reported as unaccounted). To keep such a rule and stop it being reported, delete its package field; to drop it, delete the rule;
- a rule another installed package still ships changes hands
(reassign) instead of being removed.
A box installed before the baseline recorded rules has no record of what it was given. On it, only the rules a package explicitly retracted are removed; any other tagged rule the package does not ship is unaccounted until its first upgrade has recorded a baseline.
Where to look:
- the dry run (
GET /packages/{id}?dry_run=true) and the install response
carry permission_retractions: one entry per rule with action (remove, reassign, keep), because, why and the whole rule;
GET /packages/{id}/changeskeeps every removed or reassigned rule
whole, so a grant an upgrade took away can be read back and, if it was wanted, put back by hand without a package tag;
- the restore point taken before the install includes the policy file;
- at any time, the rules in the policy that no installed package ships:
GET /permissions/unshipped
Authorization: Token <admin-token>
{
"status": "ok",
"rules": [
{"index": 41, "state": "retracted", "package": "app-notes",
"rule": {"effect": "allow", "principal": "public", "actions": ["execute"],
"object_id": "site_notes", "package": "app-notes", "...": "..."}}
],
"count": 1,
"policy_rules": 212,
"installed_packages": ["app-notes", "app-tasks"],
"wide_rules": [],
"warnings": []
}
state is operator (no package tag), retracted (the package's next install will remove it), unaccounted (tagged for an installed package that neither ships nor retracts it) or package_missing (tagged for a package that is not installed or whose files are not on this box). A listed rule that is wide (see "A wide rule left over from an older starter policy") also has a wide string, and wide_rules lists every wide rule in the whole policy as {index, package, why, rule}. The report is read-only.
Upgrading a box that predates this: reinstall each installed package (POST /packages/{id}/install with {"allow_replace": true}; take one POST /admin/backups first and add "restore_point": "<backup id>" to each install so the run does not write a full archive per package), read permission_retractions in each response, then read GET /permissions/unshipped once and decide about whatever is left.
What Runs Outside The Policy
The policy decides what a request may do. The daemon and the scheduler are not requests. They run as the system, with no user behind them, so the policy is never consulted for what they do:
- The daemon (
object_daemon.py) imports no permission code. Its passes
(scheduler, queue, rollups, auto-transitions, notifications, mail sync, scheduled backups and the rest) read and write through object_records with a fixed system actor such as daemon:scheduler, which never asks object_permissions for a decision.
- A scheduled object method runs through
execute_objectwith an empty
payload and no identity: it runs as itself, not as whoever scheduled it and not as the admin. execute_object makes no policy decision either; the policy is only applied by the HTTP routes in front of it.
Why: there is nobody to ask. A nightly backup or a queue drain has no session, and a rule written for "registered users" or "owners" has no meaning for it. Making these jobs depend on the policy would also let a broken or restrictive policy stop backups and queues.
What an admin should take from this:
- A deny-all policy does not stop scheduled work. Rules cannot be used to
switch off a scheduled job; remove the task instead (the scheduler task endpoints under /daemon/scheduler/tasks need the admin token).
- Whoever can install an object that schedules itself, or create a scheduler
task, is in effect granting that code system-level access to records. Treat that as an admin decision.
- User-namespace objects (
u_<uid>_*) are the exception to "unrestricted":
when scheduled they still run in the sandboxed worker described at the top of this page, so they reach only their own state, logs and files. The sandbox is the boundary there, not the policy.
- Decisions made by these jobs are not in the permission audit log, because no
decision is made. Look at the daemon log, scheduler_runs and the activity log instead.
Ownership
The old object convention still matters:
u_42_report
That object belongs to user 42. Owners can read, execute, update, inspect, share, and delete their own user objects unless a future stricter policy blocks that behavior.
Records can also carry ownership fields:
{
"owner_id": "42",
"customer_account_id": "customer-acme"
}
The server can use owner_id, user_id, or created_by as owner fields for the basic fallback. Application objects can add richer policy around account, department, project, team, or customer ownership.
The fallback applies after your rules, not instead of them
The owner fallback is the last step of the decision: when no allow rule matches, whoever one of those three fields names may still read, update and delete the record (and execute, source, state, logs, files, versions, share). Leaving an action out of a collection's rules therefore does not refuse it to the row's owner. A collection whose only rule is "the owner may read their own rows" is, as far as the engine is concerned, also updatable and deletable by that owner.
Where that answer reaches:
object_access(pages, actions, hooks): always. `Access.can("update",
collection, record)` is true for the owner.
- The record API (
PUT/DELETE /collections/{c}/records/{id}): only when
the subject first passes the collection-level question the API asks before it looks the record up, which has no record and so no fallback. With no update or delete rule on the collection that question is a 403, which is why a stock install refuses the owner. It stops refusing as soon as ANY allow rule for that action matches the subject at the collection level, row filter or not: a rule "support may update runs that need review" lets a support user update their own settled runs, through the fallback. Do not rely on the first question as access control; it exists so a missing id cannot be told from a forbidden one.
- Files (
/api/files/{id}, the WebDAV folder, and a file attached to an
AI chat turn, POST /api/ai/chat with attachments): the same as the record API. With no files rule for the action, the owner is refused there too. An attachment is a read; a refused one fails the turn with a 400 before anything is sent to the provider, and a file refused on its record reads like a missing one. Attachments are owner-only on top of that, whatever the policy says. In audit mode the attachment is sent as before, and both questions are recorded in the permission audit log (enforced: false), a would-be refusal included.
- "Owner" is whoever those fields name. A grant row that names its grantee
in user_id makes the grantee its owner.
Switching the fallback off for a collection
A package (or an operator) that means "only what the rules say" ships a rule that says so:
{
"effect": "deny",
"principal": "owner_fallback",
"actions": ["update", "delete"],
"collection": "template_runs",
"reason": "a run is read-only to the person it belongs to"
}
It is consulted in one place: after the allow rules have found nothing, and only when the fallback would otherwise have allowed. So:
- an explicit allow rule for the same action still grants. This is the
difference from an ordinary deny, which is checked first and beats every allow. "Owners may edit their own drafts" beside an opt-out for update lets drafts be edited and nothing else;
- admins are decided before any rule, and in-process writers
(object_records, the daemon, an action's own writes) never ask;
- the refusal is a 403 carrying the rule's
reason; actionsmay be["*"]; a rule naming neither a collection nor an
object switches the fallback off for the whole policy; a row_filter limits it to the rows it names; valid_from / expires_at work as on any rule;
- naming an
object_idcovers theu_<id>_...convention above, except in
private access mode, where object ownership is the access mode itself.
owner_fallback on an allow rule does not parse: it would grant nothing while reading as if it did.
The packages that ship one, and the collections whose packages are silent about whether the owner may update or delete, are both listed in tests/test_owner_fallback_opt_out.py (OPTED_OUT, UNDECIDED), which fails when a new collection or a narrowed grant leaves an owner's update or delete resting on the fallback alone.
Who owns a record you create
On POST /collections/<name>/records, for a collection whose schema declares an owner_id field and a caller signed in as a person (a session or one of their API keys):
owner_id sent | What happens |
|---|---|
| left out, or blank | The caller owns the row: the server fills in their id before the permission check, so a rule filtered on {"owner_id": "$user_id"} judges the row they will actually own. The returned record shows it. |
| the caller's own id | Kept. |
| somebody else's id | Kept exactly as sent, and refused with 403 {"code": "forbidden", "field": "owner_id"} unless the caller holds an admin role or an allow rule with "on_behalf": true covers this create. Nothing is written. |
The server never rewrites an owner_id the client sent. It used to: a treasurer recording a donation for a donor got 201 and a row the server had quietly made the treasurer's own, so the donor never saw it.
on_behalf is the grant for staff entering records for members, donors or patients:
{"effect": "allow", "principal": "role:treasurer", "actions": ["create", "read"],
"collection": "donations", "on_behalf": true,
"reason": "the treasurer enters donations for donors"}
It is deliberately narrow, and a rule outside this shape makes the policy invalid rather than granting nothing: an allow, naming a collection, covering create, for a role:<name> or user:<id> principal. registered, public, owner, account: and subscription: are refused, because a row owned by someone else is theirs to read, change and delete (the owner fallback above), and "any signed-in user may plant rows in anyone's account" is the forgery this check exists to stop. The rule's row_filter still has to match the record as sent (an on-behalf grant limited to {"fund": "general"} does not cover other funds), and an explicit deny still wins. A create grant without on_behalf -- even one with no row filter -- lets its principal create rows they own, and only those.
The admin token is not a person: seeding, migration and scripts that send an owner_id keep it. Only owner_id is handled this way; user_id and created_by are written as sent and judged by the rules like any other field. tests/test_create_owner_id.py walks each case through HTTP.
Changing who owns a record
On PUT /collections/<name>/records/<id> under enforcement, an owner_id that differs from the stored one is a change of owner, and it needs exactly what creating the row with that owner_id needs: an admin role, or an allow rule with "on_behalf": true covering create on the collection whose row filter matches the record as it would be. Anything else is 403 {"code": "forbidden", "field": "owner_id"} and nothing is written.
- An
owner_idsent unchanged is no change: clients that PUT back the whole
record they read are not refused.
- Taking a row for yourself, or clearing its owner, is a change of owner too
(the old owner loses it) and is asked the same way.
- An owner's own row-filtered grant (
owner_id: $user_id) already refused
giving a row away, because the rule is judged on the record as it would be. This closes the other door: a role with an unconditional update grant (a billing manager on invoices, a manager on expenses and time logs, an assignee on a task) could hand any row to any user.
- The admin token and in-process writers (actions, the daemon) are not
asked; an action that moves records between owners decides that itself.
Sharing
Sharing is just a rule:
PermissionRule.allow(
"user:99",
["read", "update"],
object_id="u_42_shared_report",
reason="shared by owner",
)
A user object is shared only this way, by object_id. An object is checked under the collection its name starts with (tools_export under tools), but a user object u_<id>_<name> is in no collection's scope: an allow rule that names a collection never grants on it, whatever the owner called it (u_42_tools_export is not opened by a grant on tools). Deny rules that name the collection still apply to it, as they always did. The access mode does not share it either: see Access Modes.
Account sharing uses the same shape:
PermissionRule.allow(
"account:customer-acme",
["read"],
collection="invoices",
row_filter={"customer_account_id": "$account_id"},
)
That covers the common case where a customer has multiple employees and they all need access to the customer portal, invoices, files, or support tickets.
Project sharing — "records I own OR records in a project shared with me" — uses grant records plus one filter value. Grants are rows in the plain project_access collection (project_id, user_id), so sharing is data: browseable, audited, versioned. Before checks run, the server resolves the subject's grants; rules opt in with $accessible_projects, which matches when the record's field value is any granted project id:
PermissionRule.allow(
"registered",
["read"],
collection="notes",
row_filter={"project_id": "$accessible_projects"},
reason="notes in shared projects are readable",
)
Pair it with an owner rule on the same collection: matching stays first-rule-wins at the collection level, but list, single-record, and search reads evaluate rules per record, so "own" and "shared" rules combine naturally. The engine itself stays pure — grant resolution is IO the server does once per request, and the subject carries the result.
Granting is self-serve through the companion value $owned_projects, which resolves to the projects whose owner_id is the subject. "Only a project's owner may share it" — a cross-record condition — becomes a plain row filter on the grant collection itself:
PermissionRule.allow(
"registered",
["create", "read", "delete"],
collection="project_access",
row_filter={"project_id": "$owned_projects"},
reason="project owners share and revoke access to their own projects",
)
Creating a grant is creating a record; revoking is deleting it; both are audited and appear in the change history like every other write.
Grants carry a permission of read or write. Most rules only need membership ($accessible_projects), but some need to tell read grants apart from write grants — "only project writers may publish" — and that narrower set is $writable_projects, resolved from the same project_access rows filtered to permission == "write":
PermissionRule.allow(
"registered",
["update"],
collection="docs",
row_filter={"project_id": "$writable_projects"},
reason="only writers may edit docs in a shared project",
)
It resolves the same way and is available everywhere $accessible_projects and $owned_projects are: row filters and, for schema-declared lifecycle fields, transition guards (see the transitions field key in docs/schema-forms.md).
Row And Field Rules
Row filters model rules like:
sales reps only see their own leads
As data:
PermissionRule.allow(
"role:sales",
["read"],
collection="contacts",
row_filter={"owner_id": "$user_id"},
)
A row filter never matches a field the record does not have. A collection's file only gains a column once some record is written with it, so "the record has no owner_id at all" is an ordinary state, not a corrupt one, and it is treated exactly like the column being present and empty:
| the filter value | field missing or null | field present, empty | field has a value |
|---|---|---|---|
$user_id / $account_id, resolved | no match | no match | match when equal |
$user_id / $account_id, unresolved (anonymous visitor, user with no account) | no match | no match | no match |
$accessible_projects and the other set-valued variables | no match | no match | match when a member |
| a literal value | no match | match only for the literal "" | match when equal |
a literal null | no match | no match | no match |
This is the same answer for an allow rule and for a deny rule: there is one comparison, and the effect only decides what a match means. So the account example above stays correct if it is generalised from account:customer-acme to registered ("every customer sees their own invoices"): a signed-in user with no account matches no invoice, including in a collection where no invoice has a customer_account_id yet. Before this was pinned (tests/test_permission_missing_column.py) an unresolved variable compared equal to a missing field and such a rule matched every row until the column was first written.
(The set-valued row assumes what the server guarantees: it drops grant rows with an empty id before building those sets, so "" is never a member.)
The table is about equality and membership. The ne operator is not part of it and is unchanged: {"op": "ne", "value": X} is plain inequality with a missing field read as null, so a missing field matches ne for any real X and does not match it when X is unresolved or null -- while an empty field does match ne against an unresolved X. A rule that depends on that corner should say what it means with a second clause.
The ordered operators (gte, lte, gt, lt) compare numbers as numbers and ISO dates and datetimes as instants in UTC: a trailing Z or an offset says the zone, a value with no offset is UTC, and a date alone is UTC midnight. So {"created_at": {"op": "lt", "value": "2026-01-01"}} compares with the created_at the server stamps (...Z). Before 2026-12-03 a date alone was read with no zone, comparing it with a stamped datetime failed, and the failure was read as "no match": such a deny refused nothing and such an allow granted nothing.
An ordered condition can also be impossible to judge: the record has no such field, the bound is a $-variable with no value (or a set), or the bound is a number or a date and the stored value is blank or text. That is the one place the effect changes the answer:
| rule | cannot judge |
|---|---|
| allow (and attention counts, list filters) | no match: grants nothing |
deny (and the owner_fallback opt-out) | the deny holds: refused |
A deny's other conditions still decide, since a filter's conditions are ANDed: a deny that names a status or an owner still spares a row with another one. A deny that should spare blank rows says so beside its bound: {"approved_at": [{"op": "lt", "value": "2026-01-01"}, {"op": "ne", "value": ""}]}. A bound that is plain text (neither a number nor a date) is compared as text and can always be judged.
Field rules model cases like hiding salary, internal notes, cost, or private metadata:
PermissionRule.allow(
"account:customer-acme",
["read"],
collection="invoices",
fields=["invoice_id", "status", "total"],
denied_fields=["internal_notes"],
)
Schema field permissions add the generated-form version of the same idea. They live next to field metadata so Scroll can render the right controls and the server can enforce the same decision:
{
"name": "margin",
"type": "currency",
"permissions": {
"admin": "edit",
"sales": "hidden",
"viewer": "hidden"
}
}
The access levels are:
edit- visible and writableread- visible but not writablehidden- removed from reads and not writable
Principal keys can be role names such as sales, or full principals such as role:sales, user:42, account:customer-acme, subscription:pro, registered, public, or owner. Grouped access lists are also accepted:
{
"name": "notes",
"permissions": {
"edit": ["owner", "role:admin"],
"read": ["role:support"],
"default": "hidden"
}
}
When multiple principals match one subject, the most restrictive field access wins. Schema field permissions only refine fields after the broader policy has already allowed access to the row.
Field permissions on writes: what is checked, and the known limits
Known limits, pending the owner's rule-combining design. This is what the engine does today, pinned by tests/test_field_permission_semantics.py; do not build on the corners below as if they were promises, and expect them to change together with that design.
- Only the keys a write submits are checked. A
PUTthat sendstitle
is not stopped by a field it did not send, however restricted that field is. A key that is sent is checked even when its value is unchanged or blank ({"secret": ""} is refused where the field is read).
- Create is checked too, against the keys of the new record, with
owner evaluated on the record being created. The refusal is 403 with "code": "forbidden" and "denied_fields": [...]; nothing is written.
- **The most restrictive access across ALL of a subject's matching
principals wins, in either direction.** A field set {"owner": "edit", "role:auditor": "read"} is read-only for a person who is both the row's owner and an auditor: holding the extra role takes edit rights away. There is no "most specific wins" and no way to say "owner overrides role". Give a person who must edit their own rows a role set that does not also appear in the field's restricted list, or restrict by default and list who may edit.
- An allow rule's
fieldsanddenied_fieldsapply to reads only. They
remove keys from what a read returns (and from what can be filtered on); they do not stop a write that sends those keys. The answer to a create, update or delete is the row as the writer's own GET shows it, so it leaves those keys out too (docs/http-api-contract.md, "Write answers"). To stop writes to a field, use the field's schema permissions.
- Transition guards cannot reference roles. A guarded move's
whenis
the row-filter language over the record's current values with the closed set of subject variables ($user_id, $account_id, and the project and shared-record sets). Each when value is a single string, a literal or one of those variables, compared for equality: no ne, in or other operators, so a guard cannot say "not your own row". To let only a role make a move, put the move behind a field permission on the field it changes, or a pre-write hook that gets the caller.
Notifications, activity feeds and history lines
With enforcement on (DBBASIC_ENABLE_PERMISSION_ENFORCEMENT, the mode /permissions/status calls "enforced"; the daemon reads the same setting through object_access.enforcement_enabled), anything shown to a user that is built from a change to a record follows the same read decision as the record, for that user, on that row, at the moment it is built. With enforcement off or audit-only the record API serves that user every row and field, so notifications and history lines are delivered whole, exactly as before; if the mode cannot be determined, notifications are not delivered. Fields a rule's fields / denied_fields or the schema's field permissions hide from them are left out, and a change that touched only such fields produces nothing for them.
- Notify rules (
app-notify, in-app and email), with enforcement on. A recipient gets a
notification only if they are an active user who may read the row; its text is rendered from the row as that user may read it, so a template's {salary_band} renders empty for someone who cannot read it. A rule whose match names a field the recipient cannot read does not fire for them (firing would tell them the value). An update none of whose changed fields they can read notifies them of nothing. An unknown recipient id, an inactive user, or an unreadable policy delivers nothing. The check is made when the daemon processes the change, not when the rule is written.
- Declared attention counts (a package's
attentionentry with
collection + where, shown on the home page and the menu), with enforcement on. The count, and the sums, ages and sub-counts of its detail sentence, are computed from each row as the viewer may read it. A row they may not read is not counted. A where condition on a field they cannot read is false for that row, so the count means "rows where this field, which you can see, matches" and is 0 for someone who cannot read the field at all. A sum or age adds nothing from a row whose field is hidden, and a detail part that depends on a field hidden in every counted row is left out of the sentence, zero or not. With enforcement off the counts are row-level, as before; if the mode cannot be determined nothing is counted. Counts are computed on each page view, so there is no stored number to go stale. A code provider's number (object_id) is not per-viewer: it is shown only to a viewer who reads every row of each collection in its reads, and, with enforcement on, from whom no schema field permission of those collections could hide a field (package-authoring.md).
GET /api/activity(a user's own recent changes): with enforcement on,
an entry's title comes from the fields the caller may read; a row they may not read is titled by its id.
action_counter_history: before/after snapshots andchanged_fields
carry only the fields the caller may read.
- Realtime (
/ws) sends only collection, id and action, after a read
check on the row. It does not look at which fields changed: a reader of a row is told the row changed even when only a field they cannot read did, exactly as the row's rev tells them on the next read. That the row changed is treated as visible to anyone who can read the row; which field, and to what, never is.
- Admin routes (
/collections/{c}/changes,/admin/changes, the event
log, subscriptions) are admin-token only and show everything, including changed_fields.
Known limits: a notification already stored in notifications was rendered for its recipient when it was written; if their access to the row or field is narrowed afterwards, the stored text stays as it was. Nothing re-renders or purges stored notifications on a permission change.
Comment moderation
Both comment collections are moderated by one role, moderator, and nobody else: app-thread's thread_comments (statuses published, pending, flagged, removed) and app-worker's guestbook profile_comments (pending, approved, rejected). The admin token is not a moderator. It is built from the pieces above, and the limits above are why it has the shape it has:
- A rule lets a moderator reach every comment. Each package ships
role:moderator read (pending, flagged, removed and rejected rows included: the pending ones are the queue) and update, with no row filter. No delete: a moderated comment is removed or rejected by its status, not erased.
- **Field permissions make
statusthe only thing that update can
change.** An allow rule's fields do not restrict writes, so the other client-writable fields (the text, the author's name and URL, the thread or profile a comment hangs off, the reply target, owner_id on the guestbook) say {"owner": "edit", "role:admin": "edit", "role:superuser": "edit", "default": "read"}: the comment's author and admins edit them, everyone else (moderators included) reads them. A moderator's PUT that sends any of them is 403 with denied_fields, and nothing is written, status included. A change of owner is refused before that anyway ("Changing who owns a record"). Server-owned fields (created_at, edited_at) were never writable by a client.
- **
statussays `{"owner": "read", "role:moderator": "edit", "default":
"hidden"}.** The author reads their own comment's status and cannot set it; a moderator edits it on other people's comments; on a moderator's own comment both entries match and the more restrictive, read`, wins, so nobody approves their own comment. Everyone else (other users, visitors, the admin token) does not see the field at all; the read rules give them only published or approved rows.
- The moves are the schema's
transitionsmap, unguarded:
thread_comments pending to published (approve), flagged or removed (reject); published to flagged or removed; flagged to published or removed; removed is final. profile_comments pending to approved or rejected; approved to rejected (un-approving); rejected is final. Nothing moves back to pending. Any other move is 400.
- Moderators have a queue on the home page: the declared attention
counts thread_comments_to_moderate and profile_comments_to_moderate count other people's pending comments the viewer may read, so they are zero for everyone who is not a moderator (or an admin, who reads every row). Each count opens a seeded page listing the pending comments oldest first, /comments/pending and /guestbook/pending (app-views list views; site routes must be on, DBBASIC_ENABLE_SITE_ROUTES=true). The page lists, it does not decide: a decision is a PUT of status over the record API. It also lists the moderator's own pending comments, which the count leaves out (a list's where cannot say "not mine"); to anyone who may not filter on status (authors, other users, visitors) it says "Not available". The same queue over the API is GET /collections/<collection>/records?status=pending.
What changes for whom, against app-thread 0.1.1 and app-worker 0.1.2:
| Caller | Before | After |
|---|---|---|
| the author | reads their comment and its status in any state; edits its text; cannot set status | the same |
| a moderator, someone else's comment | thread: reads it, status included, cannot update it. Guestbook: approved rows only (with their status), cannot update | reads it in any state with its status; moves status along the map; cannot change any other field or delete it |
| a moderator, their own comment | reads it, edits its text, cannot set status | the same |
| another signed-in user | thread: published rows; guestbook: approved rows; no status, cannot update | the same |
| a visitor | thread: nothing; guestbook: approved rows, no status | the same |
| the admin token | reads every row, status hidden; edits the text; cannot set status | the same |
anyone else an operator's own rule lets update other people's comments (a role other than moderator, admin, superuser; also a custom name in the policy's admin_roles) | could change any field | can change none of the fields above (they are read for it) |
On upgrade, reinstall both packages (POST /packages/app-thread/install and /packages/app-worker/install with {"allow_replace": true}): the moderator rules are added and nothing is retracted. Then give the role to whoever moderates, PUT /identity/users/{user_id}/roles with {"roles": [..., "moderator"]} (it takes effect on their next request). The guestbook's commenters' rule keeps its old reason text on an upgraded box, because an upgrade matches rules on everything but reason; edit it in the policy if the stale wording bothers you.
An AI agent that moderates is a user with the moderator role and an API key, not the admin token. Create a user for it (POST /identity/users with "roles": ["moderator"]), mint it a key (POST /identity/users/{user_id}/api-keys), and give the agent that key. It then works the queue exactly as a person would (GET ...?status=pending, PUT {"status": "approved"}), can do nothing else a moderator cannot, is recorded under its own user id in the change history, and is switched off by revoking the key or the role. The admin token would be the wrong credential twice over: it reaches every collection on the box, and it cannot moderate at all (status does not name it).
Subscription And Temporary Access
Subscriptions can be broad:
PermissionPolicy(access_mode="subscription")
Or plan-specific:
PermissionRule.allow(
"subscription:pro",
["read"],
collection="premium_reports",
)
Temporary pay-per-view style access is a time-boxed grant:
PermissionRule.allow(
"user:42",
["read"],
object_id="reports_market_snapshot",
valid_from="2026-06-01T00:00:00Z",
expires_at="2026-07-01T00:00:00Z",
)
If access should be consumed after one or more views, that should be tracked by an entitlement or ledger object. The permission rule says access is possible; the ledger object records purchases, consumption, refunds, and audit history.
For HTTP APIs, missing or expired paid entitlement should map to:
402 Payment Required
That is different from:
401 Unauthorized- the server does not know who the user is yet.403 Forbidden- the server knows the user, but the user is not allowed.402 Payment Required- the user may be allowed after subscription,
purchase, credit, or another payment entitlement.
Scroll Contract
Scroll should eventually call a server endpoint that exposes the same decision shape:
{
"allowed": true,
"reason": "sales reps only see own contacts",
"code": "allowed",
"http_status": 200,
"row_filter": {"owner_id": "$user_id"},
"fields": null,
"denied_fields": []
}
That lets Scroll show permission previews, generated matrices, "test as role", and AI-generated rules without becoming the authority.