RLS testing
potalab base lint and the dashboard Advisors page read the catalog and report missing protection. potalab base test rls goes further: it runs statements against your policies as two fake users and tells you which policies leak. It needs no LLM and no extension (pgTAP is optional).
potalab base test rls # local stackpotalab base test rls --db-url postgres://postgres@host:5432/mydbpotalab base test rls --json --fail-on high --min-score 80 # CIpotalab base test rls --emit potalab/tests/90_rls_generated.sql # also export the probes as pgTAPWhat it does
Section titled “What it does”- Reads the exposed schemas (default
public, change with--schema): tables, views, columns, foreign keys, policies and the privileges ofanonandauthenticated. - Classifies each table by its isolation column: owner (a foreign key to
auth.users, or a column such asuser_id,owner_id,created_by), tenant (tenant_id,org_id,workspace_id…) or unscoped. Override with--owner-column public.notes=writerand--tenant-column public.notes=company_id. - Seeds two rows per table inside a transaction, for user A and user B.
- Attacks as B and as
anon, only for the commands those roles are granted:
| Check | Statement | Passes when |
|---|---|---|
read_cross |
SELECT A’s row |
0 rows |
insert_spoof |
INSERT a row owned by A |
RLS violation (42501) |
update_cross, delete_cross |
change A’s row | 0 rows |
move_owner, move_tenant |
hand B’s own row to A | 0 rows or 42501 |
anon_read, anon_insert, anon_update, anon_delete |
the same without a token | blocked |
- Runs static checks:
rls_disabled,view_bypasses_rls(a view withoutsecurity_invoker),foreign_table_exposed,rls_no_policy.
Dashboard
Section titled “Dashboard”The dashboard has the same test under Security > RLS test (project admins only). It shows the score, the findings per table and a download of the pgTAP file. It runs in a rolled-back transaction with these limits:
- at most 100 tables and views per run;
- 5 seconds per statement;
- 30 seconds for the whole run (a run that hits the limit returns a partial result and says so);
- one run at a time per project (a second request gets a conflict).
Untick execute (execute: false in the Management API, POST /v1/projects/:ref/security/rls-test) to only generate the pgTAP file: no row is seeded and no probe runs. Each run is written to the audit log.
RLS playground
Section titled “RLS playground”Security > RLS playground in the dashboard answers “what does user X see, and why”. Pick a role (anon, authenticated or service_role). For authenticated, search an end user (this fills sub and the email) and optionally set tenant_id, aal and extra claims. Then browse a table or write one SELECT.
- It runs in a read-only transaction with
SET LOCAL ROLEand the chosenrequest.jwt.claims, always rolled back, with at most 200 rows and 5 seconds. Writes are refused. A statement that fails for that identity (permission denied, an RLS violation) is shown as the result. - Below the rows, per table: RLS on, off or forced,
BYPASSRLS, the policies that apply to that role forSELECT(permissive ones are OR-ed, restrictive ones AND-ed, default deny when none applies), theUSINGandWITH CHECKofINSERT,UPDATEandDELETE, and, for a single-table query, a row-by-row trace of each policy on the first 20 rows, including rows the user cannot see. - Generate pgTAP test downloads a test built with the same probe as the CLI, asserting the row count (or SQLSTATE) you just observed.
Only project admins can use it.
Security score
Section titled “Security score”The score starts at 100 and loses 25 per critical finding, 15 per high, 7 per medium and 2 per low (info costs nothing). Grades: A at 90 or more, B at 75, C at 50, D at 25, otherwise F.
- critical: anyone, including anonymous visitors, can change or see other people’s data.
- high: a signed-in user can read or hand over another user’s rows.
- medium / low: the table has no isolation column, which may be intentional (use
--ignore).
Inconclusive means a probe failed for a reason other than RLS (a trigger or CHECK); it never counts as a pass.
Options and exit codes
Section titled “Options and exit codes”| Option | Meaning |
|---|---|
--db-url <url> |
Database to test (default: the local stack; the password may come from BASE_DB_PASSWORD). |
--schema, --table, --ignore |
Choose exposed schemas, restrict to tables, skip tables. |
--owner-column, --tenant-column |
Override the isolation column as schema.table=column. |
--fail-on <severity> |
Exit 5 when a finding at or above this level exists (info, low, medium, high, critical, none; default high). |
--min-score <n> |
Exit 5 when the score is below n (0-100). |
--emit <file> |
Also write the probes as a pgTAP file. |
--json |
Print the whole report as JSON. |
Exit codes: 5 for a failed gate, 2 for a usage error, 4 for a connection error.
Export as pgTAP
Section titled “Export as pgTAP”--emit file.sql writes the generated probes as a pgTAP test (BEGIN; SELECT plan(n); ... SELECT * FROM finish(); ROLLBACK;). Put it in potalab/tests/ and it runs with your other SQL tests, so a policy regression fails CI without the generator.
See also Row level security and the CLI reference.