Skip to content

rowstileAccess rules for Postgres

Authorization inside your Postgres. Sharing, groups and nested folders in one policy file, compiled to row-level security. No second service, no data to sync.

A small policy ​

authz
app role app_user                               -- the Postgres role the app connects as
type user = app.users
type folder = app.folders
  owner  : user   = owner_id                    -- a relation read from a column
  parent : folder = parent_id
  editor : user   = app.folder_editors(folder_id -> user_id)   -- ... or from a link table
  can edit = owner or editor or parent.edit     -- inherited down the tree
  can view = edit
rules app.folders
  select                 : view
  update                 : edit
  update owner_id        : owner                -- only the owner gives it away
  update parent_id after : parent.edit          -- moved only under a folder they may edit

The app says who is asking, then runs its usual queries:

sql
BEGIN;
SELECT authz.act_as('user', '42');
SELECT * FROM app.folders;                      -- only the folders 42 may view
UPDATE app.folders SET name = 'Plans' WHERE id = 7;   -- 0 rows unless 42 may edit folder 7
COMMIT;

The SDKs turn a write that changed nothing into a 404 (the row can't be seen) or a 403 that says which rule refused it and why.

Is it for you? ​

It fits when your app's data is in one Postgres database, and who may see or change a row depends on other rows: its owner, the members of a team (teams inside teams), a folder or a project that passes access down, a tenant, what people share with each other. It is for you if you were about to add an authorization service and keep it in step with the database, or if your hand-written row-level security has become hard to test and to change.

It doesn't fit when what decides access is in several databases or outside Postgres, when a browser reads the tables through Supabase's Data API, or when one tree takes many moves and links a second. And if you need an outside audit or a vendor behind it today: rowstile is in beta, with one maintainer, and nobody outside has audited it.

Next: Getting started goes from a schema to a policy, its tests, the edit loop and the first migration. Pick your stack for the SDK that does the signing in for you.

For coding agents: each page here is also Markdown, at its address with .md (https://rowstile.dev/getting-started.md), and https://rowstile.dev/llms.txt lists them with what to know first.