Supabase "permission denied for table" is usually a GRANT problem, not RLS
“Permission denied for table” reads like an RLS verdict, so people open policies, rewrites, JWT claims — and change nothing. On PostgreSQL 17 I reproduced the exact n8n forum symptom with row level security switched completely off. The gate was a missing GRANT. Same for service_role.
Six modes, three signatures
One table, one row, six configurations, each measuring what the caller gets back. Everything below ran on a local PostgreSQL 17.12 container with roles shaped like Supabase's anon and service_role: a plain login role and a BYPASSRLS one.
| Mode | Setup | SQLSTATE | Signature | What it proves |
|---|---|---|---|---|
| 1 | RLS disabled, no GRANT, plain role | 42501 | permission denied for table agency | Privilege gate. RLS is not even in the path — there is no grant. |
| 2 | RLS disabled, no GRANT, BYPASSRLS role | 42501 | permission denied for table agency | BYPASSRLS skips policies, not ACLs. service_role without GRANT fails identically. |
| 3 | RLS disabled, GRANT SELECT | 00000 | SELECT OK — 2 rows | The table was reachable all along. The grant was the gate. |
| 4 | RLS enabled, policy TO anon_probe, GRANT SELECT | 00000 | SELECT OK — rows filtered by policy | Policy + grant together. Neither one alone is the access path. |
| 5 | RLS enabled, policy TO authenticated, GRANT SELECT as anon_probe | 00000 | SELECT OK — 0 rows, no error | The empty-array signature. The grant lets you ask; the policy set does not include your role. |
| 6 | GRANT INSERT, sequence not granted | 42501 | permission denied for sequence agency_id_seq | A serial column needs USAGE on its sequence. This is the n8n 403 'check your credentials' shape — credentials were fine. |
Every failure returned 42501. Through PostgREST — including the n8n Supabase node — that surfaces as 403 Forbidden, often with the node's generic “perhaps check your credentials?” hint. The credentials were never the problem in modes 1, 2, or 6.
Why this gets misdiagnosed
“RLS, policies are disabled, credentials all appear correct, but permission denied” is the exact shape of the n8n community thread I measured against. The words “RLS disabled” act as a stop sign: if policies are off, people assume privileges are on. In PostgreSQL the two gates are independent:
- GRANT decides whether the role may open the table at all. No grant, no query — policy or no policy.
- RLS decides which rows the role sees once it is already allowed in. A policy cannot grant access; it can only filter it.
The expensive corollary: a project can run with relrowsecurity = false on a table and still be reachable— mode 3 proves the grant alone was the only gate. “RLS is disabled” is not a safety statement and it is not an error explanation.
The empty-array signature (mode 5)
The quieter failure has no error at all. A role that holds SELECTbut is not named by any policy gets a successful query and zero rows. From n8n that looks like “node returns empty” — workflows downstream of it branch on emptiness and silently do nothing. That signature is a grant-plus-policy mismatch: the grant let you ask, the policy set does not include you.
Mode 6 is the insert-side twin. GRANT INSERT on the table does not carry the sequence a serial column calls. The insert fails with permission denied for sequence— after the table-level grant “succeeded.” Sequences carry their own ACL.
The 30-second diagnostic
Run these read-only queries as the project role before touching a single policy. Each one separates a gate:
| Query | What it tells you | Measured result |
|---|---|---|
| has_table_privilege('anon','public.agency','SELECT') | Whether the role can even open the table | t after grant / f before — the first gate, before any policy |
| select grantee, privilege_type from information_schema.role_table_grants where table_name = 'agency' | Who actually holds what on this table | anon_probe: INSERT, SELECT — and nothing else |
| select relrowsecurity from pg_class where relname = 'agency' | Whether policies are in the path at all | t / f — a table can serve traffic with policies off |
| select polname, polcmd::text, (select string_agg(r.rolname,',') from pg_roles r where r.oid = any(p.polroles)) from pg_policy p join pg_class c on c.oid = p.polrelid where c.relname = 'agency' | Which roles each policy applies to | empty polroles = PUBLIC — the policy covers every role |
| select * from pg_default_acl | What future tables inherit | 0 rows in a fresh project — the next table starts ungranted |
has_table_privilege answers the mode-1 question in one call. If it returns f, stop reading policies — you are looking at the wrong gate.
The fix, in gate order
- Grant the table.
grant select, insert, update, delete on public.agency to anon, authenticated;— whatever the surface actually needs, no more. - Grant the sequence.
grant usage, select on all sequences in schema public to anon, authenticated;— without it, inserts with a serial/bigserial default die at mode 6. - Only then look at policies.Check the policy's roles: empty
polrolesmeans PUBLIC (every role), a named list means everyone else gets the mode-5 empty array. - Set default privileges before the next table.
alter default privileges in schema public grant select on tables to anon;— my fresh container hadpg_default_aclempty, so the next migration inherits nothing and repeats mode 1.
Honest limits of these measurements
- Local PostgreSQL 17.12 container, plain login roles shaped like
anon/service_role. Hosted Supabase provisions those roles with its own defaults — I did not run this on a hosted project. - SQLSTATE mapping is PostgREST's:
42501→403. A client that returns raw Postgres errors shows the code directly. - The n8n Supabase node's “check your credentials” text is a generic error wrapper; I measured the database side, not the node's error formatting.
What this has to do with RLS reviews
The drift monitor I publish free checks the other direction — policies that exist but do not protect (owner bypass, USING (true), missing WITH CHECK). Modes 1–6 here are the missing-grant direction. A complete picture needs both: who can reach a table, and which rows they actually see once inside.
The free drift monitor checks thirteen read-only catalogue conditions nightly and alerts only on changes from your own baseline. The $95 spot check is when you want a second pair of eyes on exactly these signatures before you touch production.
Prefer the verdict instead of running the toolkit yourself?
Fixed-price reviews with the evidence, the SQL and the written verdict. Fixes are quoted separately. Instant checkout, no account needed.
Want the free first step? The RLS Drift Monitor runs 13 read-only catalog checks on a schedule. It never reads application rows; zero findings is not proof of safety.
Prefer escrow? $49 drift monitor setup or $95 exposed-key triage on Upwork. Work starts only after the fixed-price milestone is funded.
Work starts only after payment is secured. Catalogue checks are read-only; no write credentials, no service_role key, no application rows.