supabase-rls-policies

Installation
SKILL.md

Supabase RLS Policies

Write Row Level Security (RLS) policies for Supabase tables, then prove them with pgTAP tests that act as two different users. A policy is not finished until a test shows that a second user cannot read, change, delete, or create rows that belong to the first user.

When to Use This Skill

  • Creating a table in an exposed schema (by default public)
  • Adding or changing a policy, a view, or a security definer function
  • Reviewing a migration or pull request that touches RLS
  • Answering whether users or tenants are isolated from each other

Workflow

  1. List the access rules first. For each table, write down which role (anon or authenticated) may run which operation (select, insert, update, delete) on which rows. Confirm the list with the user before writing SQL. Each rule gets one test.
  2. Write the migration. Enable RLS, add one policy per operation, and index every column the policies filter on.
  3. Write a pgTAP test file for the table under supabase/tests/, using the template below.
  4. Run supabase test db and read every line of output.
  5. Break the policy on purpose, on a local database only. Copy the test file and add a temporary policy with using (true) right after begin;, for example create policy "tmp_open" on public.notes for select to authenticated using (true);. Run supabase test db against the local stack from supabase start, confirm at least one test fails, then delete the copy. Do the same with a temporary for update and a for delete policy. The file ends with rollback, so the temporary policy is undone even when the run fails or stops early. Never put a temporary policy in a migration, and never run this against a shared or production database. Do not drop the real policy to do this: with no policy every read is denied, so denial tests still pass and prove nothing.
  6. Do not change a policy just to make a test pass. Report which assertion failed and which policy it covers, and let the user decide which one is wrong.
Installs
10
GitHub Stars
41.6K
First Seen
Nov 9, 2026