0
Challenge · 55RLS: The Core
Permissive (OR) vs restrictive (AND) policies
Securityused in ~75% of apps
Concept 53 left you with a promise: every policy you have written so far is PERMISSIVE, because that is the default, and this concept is where you learn what that word is doing. DevLog is about to grow a feature that concept 53's policies cannot express on their own: a banned user must see nothing, ever, no matter how many other policies would otherwise let them read their own posts. Get the keyword wrong -- or just forget it -- and the ban silently does not apply, while every other policy on the table keeps working exactly as before.
Core idea. A command's visibility is decided by one formula, and it has exactly two halves: (the OR of every PERMISSIVE policy that matches) AND (the AND of every RESTRICTIVE policy that matches). PERMISSIVE policies (the default) each independently grant access -- any one passing is enough, and each additional permissive policy can only add rows, never remove them. RESTRICTIVE policies do the opposite: every single one must pass, and each additional restrictive policy can only remove rows, never add them. The corollary that catches people: with zero permissive policies for a command, the OR of nothing is false, so restrictive policies alone -- however many, however correct -- admit nobody.
poke it, drag it,
try to break it
try to break it
no slides here.
you drive.
you drive.
Playground, this isn't a screenshot
Live demointeractive
Real Postgres · in your browseridle
Two PERMISSIVE policies exist: "published posts, to everyone" and "your own posts, to their author." Run this as alice. She owns a private draft AND there are two public posts. Predict how many rows come back before running it.
Querying as
Cmd/Ctrl + Enter
↑ play a little first, then dig in