Supabase Row Level Security Policies

Lock down Supabase tables with row level security policies keyed to auth claims, scoping reads and writes to tenant ownership.

TypescriptSecurity Boundaries

Code

snippet
-- Supabase RLS policies:run at the Postgres layer
alter table projects enable row level security;

create policy "tenant read own projects"
  on projects for select
  using (tenant_id = auth.jwt() ->> 'tenant_id');

create policy "tenant insert own projects"
  on projects for insert
  with check (tenant_id = auth.jwt() ->> 'tenant_id');

create policy "tenant update own projects"
  on projects for update
  using (tenant_id = auth.jwt() ->> 'tenant_id')
  with check (tenant_id = auth.jwt() ->> 'tenant_id');

-- 服务端绕行角色仅在维护任务中使用
create policy "service role full access"
  on projects for all
  using (auth.role() = 'service_role');