The short answer
-
Turn RLS on for the table, in the dashboard under Database > Policies, or with
alter table … enable row level securityin a migration. - Write a policy for each command your app uses (select, insert, update, delete), for the roles that should use it.
-
Grant those commands to
authenticated, and toanononly for public data. New tables no longer get these grants automatically. - Check every table, then test as a real user before you ship.
Do all of it in one migration. Turning RLS on without policies blocks your own app: as Supabase’s docs put it, no data is accessible through the API with the publishable key until you create policies. New to RLS? Read what RLS is in Supabase first; this page is the how-to.
Enable RLS in the dashboard
Supabase’s docs give the path: open Database > Policies in your project’s dashboard, find the table, and select Enable RLS. The same page is where you add policies afterwards.
Tables you create in the dashboard’s Table Editor already have RLS on, and the Table Editor shows a warning label on any table that doesn’t. Tables made in the SQL Editor, by migrations, by an ORM or by an AI app builder don’t get it by themselves, so those are the ones to look for.
Enable RLS with SQL
In a migration, or in the SQL Editor, one statement per table:
alter table public.notes enable row level security;
To catch every table in public at once, loop over the ones still without it. Run it only when you’re
ready to add policies straight after, because each table it touches stops answering the API until you do:
-- Turns RLS on for every table in public that doesn't have it yet.
-- Each one returns no rows to the API until you add its policies.
do $$
declare
t record;
begin
for t in
select schemaname, tablename from pg_tables
where schemaname = 'public' and not rowsecurity
loop
execute format('alter table %I.%I enable row level security', t.schemaname, t.tablename);
end loop;
end $$;
That covers the tables you have. For tables created later, an event trigger can turn RLS on as each one is created; see automatic RLS.
Write the first policies
Most tables start with one rule: each user owns their rows. Write one policy per command, name the role with
to, and compare the owner column with the signed-in user:
-- Each user reads and changes only their own notes
create policy "Users read their own notes"
on public.notes for select
to authenticated
using ((select auth.uid()) = user_id);
create policy "Users add their own notes"
on public.notes for insert
to authenticated
with check ((select auth.uid()) = user_id);
create policy "Users update their own notes"
on public.notes for update
to authenticated
using ((select auth.uid()) = user_id)
with check ((select auth.uid()) = user_id);
create policy "Users delete their own notes"
on public.notes for delete
to authenticated
using ((select auth.uid()) = user_id);
-- Policies compare user_id on every query, so index it
create index if not exists notes_user_id_idx on public.notes (user_id);
Write the select policy even if you think you only need writes. Supabase’s docs warn that an update needs a matching select policy to work as expected, and reading a row back after an insert needs one too.
Public content, roles, organizations, MFA and Storage need other shapes. The free Supabase RLS Generator writes them from a grid of who can do what, with the indexes, grants and test queries, and its page has examples of each.
Grant the API roles access
A role needs a grant on a table before RLS is even asked. Until recently Supabase granted every new table in
public to the API roles for you. Its
changelog
says new tables are no longer exposed to the Data API automatically: the default for new projects from 30 May 2026,
and applied to existing projects on 30 October 2026. Tables that already existed kept their grants.
A new table without grants answers the API like this:
{
"code": "42501",
"message": "permission denied for table notes",
"hint": "Grant the required privileges to the current role with: GRANT SELECT ON public.notes TO anon;"
}
Grant each role the commands its policies cover, and nothing more. Supabase recommends keeping grants and RLS in the same migration:
-- Signed-in users get exactly the commands their policies cover.
grant select, insert, update, delete on public.notes to authenticated;
-- Only if signed-out visitors should read the table, with a policy for anon:
-- grant select on public.notes to anon;
The two layers do different jobs. Grants decide whether a role can reach the table at all; policies decide which rows. A grant without RLS leaves every row open to that role, and RLS without a grant gives a permission error before any policy runs.
What breaks right after, and why
- Queries return an empty list
-
No select policy covers this user. RLS denies by default and doesn’t say so: a refused read looks like an empty
table. Check the policy’s
torole, and that the request carries the user’s session. permission denied for table …(42501)- The role has no grant on the table. Add the grant; a policy can’t fix this.
- An update or delete succeeds but changes nothing
-
The command only reaches rows the user can select, so with no select policy it matches nothing, and reports no
error. Add the select policy, then check the update policy’s
using. new row violates row-level security policy for table "…"-
The new row fails the insert or update policy’s
with check, often because the client didn’t setuser_id. It also appears on.insert(…).select()when no select policy covers the new row. - Your server code still sees everything
-
It uses a secret key, which runs as
service_roleand skips RLS. That’s expected; read does the service role bypass RLS? for when it doesn’t, and how to act as the user instead. - Realtime stops sending some changes
- Database change events are now checked against each subscriber’s select policies. Users only receive rows they could read.
Check every table
The Security Advisor in your dashboard, under Advisors, runs Supabase’s
database linter; the CLI
equivalent is supabase db advisors. Three of its checks are about this page:
- Table publicly accessible (
0013_rls_disabled_in_public): RLS is off on a table the API can reach. Fix these first. - Security policy not enforced (
0007_policy_exists_rls_disabled): you wrote policies but never turned RLS on, so they do nothing. - No access rules defined (
0008_rls_enabled_no_policy): RLS is on with no policies. Safe, but the API returns nothing for that table.
To see RLS, policies and grants side by side, run this in the SQL Editor. It reads settings only, never rows:
-- Every table in public: RLS, policy count, and what the API roles can do
select
c.relname as table_name,
c.relrowsecurity as rls_on,
(select count(*) from pg_policies p
where p.schemaname = n.nspname and p.tablename = c.relname) as policies,
has_table_privilege('anon', c.oid, 'select') as anon_select,
has_table_privilege('anon', c.oid, 'insert, update, delete') as anon_write,
has_table_privilege('authenticated', c.oid, 'select') as auth_select
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'public' and c.relkind in ('r', 'p')
order by c.relrowsecurity, c.relname;
Any row with rls_on false and anon_select true is readable by anyone with your public key.
A row with anon_write true deserves a second look even with RLS on.
For a fuller check, open “Check my project” in the Supabase RLS Generator. Paste your migrations, or the result of one read-only query it gives you, and it lists tables left open, policies that allow everyone, writes that only check someone is signed in, roles read from user_metadata, views and functions that skip RLS, and open Storage buckets, with the SQL to fix each. It runs in your browser.
Test as a user before you ship
The SQL Editor runs as an admin, so it shows every row whatever your policies say, and your server code may use a secret key that skips them too. Test the way your users connect: sign in as two different test users in your app and check each sees only their own rows, or switch role inside a transaction in SQL. The generator’s page shows the SQL for that, and the generator writes a test block for every kind of user in your plan.