ExitRow-Level Security: tenant-bound policies for shared tables1 / 9
Explanation

Make the tenant boundary a database rule

How row policies enforce tenant boundaries using trusted session context, including fail-closed behavior, connection-pool context handling, and privileged-role bypass risks. · advanced

Row-level security (RLS) adds row authorization to ordinary table privileges. Consider PostgreSQL, including Aurora PostgreSQL, with a shared orders table and a non-null UUID tenant_id. Enable enforcement with ALTER TABLE orders ENABLE ROW LEVEL SECURITY. For roles subject to RLS, an enabled table with no applicable policy defaults to denying rows; granting table access alone does not make rows accessible.

A tenant policy can compare each row against session context using tenant_id = NULLIF(current_setting('app.tenant_id', true), '')::uuid. Use this predicate in both USING and WITH CHECK. USING determines which existing rows are eligible for SELECT, UPDATE, or DELETE. WITH CHECK validates proposed rows for INSERT and UPDATE, preventing an application from inserting another tenant's row or moving an existing row into another tenant.

These are different checks: an UPDATE must pass the existing-row test and the new-row test. Ordinary SQL privileges still determine which operations are allowed. RLS adds a boundary even when application SQL omits its tenant filter, but its correctness depends on the supplied tenant context and the database role actually being subject to enforcement.