Skip to main content

RLS (Row-Level Security)

Row-level security (RLS) is a database access control mechanism that restricts which rows a user can read or modify based on their identity, role, or other attributes, commonly used in multi-tenant applications.

What Is Row-Level Security?

RLS is a security feature in databases (like PostgreSQL/Supabase) that automatically filters data at the row level. Instead of returning all rows and filtering in your application code, the database itself enforces who can see what.

How RLS Works

1. Enable RLS on a table

2. Create policies that define access rules

3. Database enforces policies automatically on every query

Example: Multi-Tenant Business App

``sql

CREATE POLICY tenant_isolation ON transactions

FOR ALL

USING (organization_id = current_setting('app.current_org'));

``

This ensures users can only see transactions belonging to their organization — without any application code changes.

Why RLS Matters for Business Banking

  • Data isolation: Each business only sees its own data
  • Compliance: Meets regulatory requirements for data segregation
  • Defense in depth: Even if application code has a bug, the database prevents data leaks
  • Audit trail: Policies are defined in SQL, versioned, and reviewable
  • RLS in Supabase

    Supabase (built on PostgreSQL) uses RLS as its primary security model. When you create a table in Supabase, RLS is enabled by default — you must create policies to allow access.

    Related Terms