Menu

Designing PostgreSQL RLS with permissive and restrictive policies
📰

Designing PostgreSQL RLS with permissive and restrictive policies

DEV Community: database·Chris Rodriguez·7 days ago
#Q0gYeAfi
#devtodatabase#devto#dev#policy#policies
Long article (1169 words) — no AI summary yet.
Reading 0:00
15s threshold

PostgreSQL RLS policies do not compete for precedence. For each command and role, PostgreSQL gathers the applicable policies and combines them by policy mode: permissive policies form an OR group, while restrictive policies form an AND group. The effective decision is therefore “at least one permissive rule passes, and every restrictive rule passes.”

A small tenant-records design makes the distinction concrete. Put tenant ownership in a permissive policy: it establishes the rows the current caller may consider. Put the active-record requirement in a restrictive policy: it narrows those candidate rows so archived records remain unavailable. A row belonging to the tenant but marked inactive is denied; an active row in another tenant is also denied.

This choice is useful when access has both an additive baseline and a non-negotiable constraint. Additional permissive policies can widen the candidate set for a role or use case. Additional restrictive policies can add guards that all must hold.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.