Database

Row-level security

Set a user column when you create a table and CubiBase writes the PostgreSQL policy for you: a row belongs to the user whose id it carries.

The model

Every table created through CubiBase has Row Level Security enabled and forced. Two policies exist from the start, and the Policies screen lets you add, edit, or drop your own:

PolicyRoleEffect
Developer policysql (Console)Full access, so you can manage every row
Isolation policyapi (Data API)Only rows where the user column equals the caller’s id

The user column must be a text column on the new table — owner_id in these docs. Its value is compared to the verified JWT subject, which the engine sets as cubibase.user_id for the transaction.

The policy CubiBase creates

For a table customers with user column owner_id, the isolation policy is equivalent to:

SQL · created for you
CREATE POLICY customers_api_isolation ON public.customers
  FOR ALL TO example_project_db_api
  USING (owner_id = cubibase.current_user_id())
  WITH CHECK (owner_id = cubibase.current_user_id());
  • USING limits which rows the user can read, update, or delete.
  • WITH CHECK limits which rows the user can insert or update into: writing someone else’s id fails with 403 forbidden.
  • The check runs inside PostgreSQL, not in application code you have to remember.

From JWT to rows

  1. The user signs in; the access token’s sub claim is their user id.
  2. Your app sends the token as Authorization: Bearer … on a Data API call.
  3. The engine verifies the token and sets cubibase.user_id for that transaction.
  4. PostgreSQL applies the policy: the query only sees rows where owner_id matches.

What the policy does not do

  • It is per-row ownership, not roles or teams. For richer rules — statuses, teams, published rows — write your own policies on the Policies screen.
  • The user-column flag itself only exists at creation; an existing table can get an equivalent rule as a hand-written policy.
  • It does not replace exposure switches: an unexposed operation is refused before any row is touched.
  • Anonymous users work exactly like registered users — their id is real, so their rows are theirs.

Additional resources