Skip to content
Supabase 2026-07-06 10 min

Supabase Row Level Security: Patterns That Scale

How to model multi-tenant RLS policies, avoid common leaks, and keep policies readable.

By Mohammad Zayed

Overview

Row Level Security (RLS) in Postgres via Supabase is the most important control for multi-tenant apps. A single missing policy can expose every tenant's data.

Policy pattern

enable + policy
alter table invoices enable row level security;

create policy "tenant isolation"
  on invoices
  for all
  using (tenant_id = current_setting('app.tenant_id')::uuid)
  with check (tenant_id = current_setting('app.tenant_id')::uuid);
Set app.tenant_id from your verified session on every connection. Never trust a client-supplied tenant id.

Multi-tenant

Use a shared schema with a tenant_id column and RLS, or separate schemas per tenant for stronger isolation. Start shared; split only when compliance demands it.

Gotchas

  • Joins bypass intuition — policy applies per table.
  • Service roles skip RLS; never use them from the client.
  • Test policies with two tenants in your test suite.

FAQ

Start with least-privilege policies for each role and tenant. Test both allowed and denied access with representative records before releasing policy changes.

Frequently asked questions

Can RLS replace my app-level auth checks?
RLS is defense-in-depth, not a replacement. Always authenticate the request and keep RLS as the final gate that prevents cross-tenant reads.
How do I avoid leaking data through joins?
Add RLS to every table in the tenant scope, including join tables. Test with two tenant sessions in CI.

Continue reading

Want help building this?

Share one workflow and the outcome you want. We'll review your brief and suggest an appropriate next step; scope and deliverables are agreed before work begins.

Founder-led delivery · Existing systems first · Available internationally