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 definerfunction - Reviewing a migration or pull request that touches RLS
- Answering whether users or tenants are isolated from each other
Workflow
- List the access rules first. For each table, write down which role (
anonorauthenticated) 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. - Write the migration. Enable RLS, add one policy per operation, and index every column the policies filter on.
- Write a pgTAP test file for the table under
supabase/tests/, using the template below. - Run
supabase test dband read every line of output. - Break the policy on purpose, on a local database only. Copy the test file and add a temporary policy with
using (true)right afterbegin;, for examplecreate policy "tmp_open" on public.notes for select to authenticated using (true);. Runsupabase test dbagainst the local stack fromsupabase start, confirm at least one test fails, then delete the copy. Do the same with a temporaryfor updateand afor deletepolicy. The file ends withrollback, 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. - 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.