Kovlet per-record rules reference
For looking up exactly what a per-record rule for end users can say and how the server applies it. It covers the document's shape, every name a rule can read, the functions and operators, and the mapping from InstantDB's instant.perms.ts.
On this page
At a glance
- One JSON document per Data Space. Keys are tables,
_users,_files,_roomsor$default. Each entry hasallow(a CEL rule per action) and an optionalbind. - A rule reads
auth,data,newData,paramsanddata.ref('path')(up to 3 links). viewrules run as database filters, so they compare columns with values only. Write rules may use the whole language.- An action with no rule is denied, and a rule that hits an error denies.
- The routes that read, save, test and propose rules are in the end users REST API reference.
To write and save your first rules step by step, follow Write per-record rules for end users.
The document
Each key is a table, _users, _files, _rooms or $default. Each entry has:
allow: a rule per action. Tables takeview,create,updateanddelete._userstakesviewonly (clients can't write it),_filesthe same four actions,_roomsonlyjoin.$defaultinsideallowcovers the actions the entry doesn't name.bind(optional): name, expression pairs,["isOwner", "auth.id == data.owner"]. A rule uses the name as a shorthand.
The $default entry covers tables without their own entry. It never covers _users, _files or _rooms.
A rule for a table that doesn't exist yet is accepted and checked once the table exists, so a migration can propose rules before the app creates its tables.
What a rule can read
| Name | What it is |
|---|---|
auth.id, auth.email, auth.is_guest | The signed-in end user, from the verified session. auth.email is null for guests. |
auth.claims | Claims of an external identity token. Not stored on sessions yet: an empty map for now. |
data | The stored row: view, update and delete rules. For create, the new row. |
newData | The row as it would be stored after the write: create and update. Fields merge last-writer-wins first, so this is the real result. |
params | Values the client sends (subscribe, mutate, query and transact take params), InstantDB's ruleParams. Untrusted: never use them as an identity. |
data.ref('path') | The values reachable from the row through ref columns, up to 3 links. Use it on the right of in. |
Columns are read by name (data.title). data.id is the row's ID.
data.ref: following links
Each segment but the last names a link. The last names a column (or id) of the table it arrives at:
- Forward: a ref column of the current table.
data.ref('owner.email')followstodos.ownerto_users. - Reverse: a table with a ref column that points back. From
teams,data.ref('memberships.user')reads theuserof every membership whoseteamis this team. The table must have exactly one ref column pointing back.
{
"posts": {
"allow": { "view": "data.published || auth.id in data.ref('team.memberships.user')" }
}
}The post's team column leads to the team, memberships back to its memberships, and user to each member. When someone joins or leaves the team, the post moves into or out of their live queries.
data.ref inside a rule reads linked rows regardless of their own view rules, because you wrote the rule. Queries are different. An end user's where paths and nested keys only see linked rows they may view, so a filter can't probe hidden values.
Functions and operators
==, !=, <, <=, >, >=, &&, ||, !, ?:, in (a list, a map's keys, or data.ref), + (strings, numbers, lists), has(data.column), size(...), .startsWith(), .endsWith() and .contains(). Datetime columns compare as instants, so newData.due > '2027-01-01T00:00:00Z' works across time zones.
What view rules can't do
A view rule runs as a database filter and in the live fan-out, so it compares columns with values only:
- no
newData, and no column compared with another column (data.a == data.b) - no
size()or+on a column, and nostartsWith/endsWith/containswith a%in the argument
Write rules (create, update, delete) see concrete rows and may use all of it. Saving a document checks every rule against the schema and lists each problem as todos.view: … (422 rules_invalid).
Errors deny
A rule that hits an error denies. A missing params key or a value of the wrong type is an error, unless false && … or true || … decides the rule first. Kovlet is stricter than CEL here: an error anywhere else in a view rule hides every row.
How the server applies rules
| Path | Check |
|---|---|
| Sync subscriptions (protocol 2) | The view rule is ANDed into every query node and link path. Link rules keep hidden held sets, so changes to memberships move rows in and out live. |
GET …/records, POST …/query | The same filter in SQL. |
Writes (mutate, POST …/transact) | Inside the commit transaction: update and delete first need the row's view rule, then the action's rule on the merged row. data.ref sees the batch so far, so one atomic batch can create a team and its first membership. |
| Files | _files rules over data.path, data.size and data.mime_type: view for listing and metadata sync, create for new paths, update for overwrites and moves (checked at the old and the new path), delete for deletes. |
| Rooms | A room bound to a record (room_join.record: {table, id}) needs that row's view rule; the peer is removed when the row leaves their view. Other rooms need a _rooms join rule over data.id. |
Restoring from the Trash, and writes to rows in the Trash, are member tools: end users get forbidden.
When the rules change, every end user's live subscriptions re-plan and get a fresh result, so rows that left their view are dropped from their device.
From InstantDB
instant.perms.ts | kovlet.perms.json |
|---|---|
| Not set (InstantDB is open by default) | "true", written explicitly: Kovlet is closed by default |
true, false | "true", "false" |
auth.id != null | auth.id != null |
auth.id == data.creatorId | auth.id == data.creatorId (attributes keep their names; renamed ones are rewritten) |
auth.id in data.ref('owner.id') | auth.id in data.ref('ownerId.id'): a has-one link label x is the ref column xId |
auth.id in data.ref('team.members.id') | Each label becomes what the migration made of the link: a has-one label its ref column (teamId), a has-many label the child table, a many-to-many label its join table and column. At most 3 links in Kovlet. |
bind: ["isOwner", "..."] | bind, translated the same way |
ruleParams.x | params.x |
newData.x, data.x | the same |
$users view | _users view |
$files rules over data.path | _files rules over data.path |
auth.ref(...), data.x.exists(...) and other list macros, request.* | Not supported: rewrite with data.ref (link the row to _users) or split the data. migrate instantdb writes "false" and lists them. |
Field-level fields rules | Not supported: put the sensitive columns in their own table with its own rule. |
kovlet-mcp migrate instantdb writes this translation to kovlet.perms.json and lists every rule it couldn't translate in KOVLET_MIGRATION.md.
Not supported, on purpose
- Rules for members. Team members are governed by space roles and keep a full replica.
- Per-field read rules. A row is visible or not. Write rules may pin fields (
newData.owner == data.owner). - Time-based or networked view rules. Visibility must only change with an op the server sees.
Next
- Write per-record rules for end users: write, test and save a rules document.
- Kovlet end users REST API reference: the rules routes and every end-user route.
- Kovlet glossary: every Kovlet term, with a stable link.
Ready to try it? Start free. No credit card, no API keys.
For coding agents: this page is also Markdown. Add .md to the URL or send Accept: text/markdown. The full reference is at /llms-full.txt.