0
Challenge · 52RLS: The Core

Enabling the wall: RLS denies by default

Securityused in ~100% of apps

Concept 19 showed you this trick on one table, months ago: run `enable row level security` and the exact same query starts returning nothing. Easy to nod along and move on. But DevLog is not one table anymore -- it is profiles, posts, comments and likes, and the wall has to go up around all four, in one migration, before a single policy exists. Miss one table in that list, or enable it but never run the follow-up statement someone assumed happened automatically, and you have shipped a leak that passes code review, because the policy sitting right there in the migration file reads perfectly.

Core idea. Row level security is a per-table switch, not a per-schema one, and it is binary: a table either denies every non-bypass role completely (RLS on, whatever policies exist so far) or filters nothing at all (RLS off, no matter how many CREATE POLICY statements target it). Writing a correct policy on a table where RLS is still off changes exactly nothing -- Postgres never consults a policy on a table it isn't guarding. Enabling RLS on posts does nothing whatsoever for comments or likes. And even once a table is walled off, two roles still walk straight through: service_role always, and the table's own owner unless you additionally run `force row level security`.
Playground, this isn't a screenshot
-- you just ran: create table posts …
Aalice's appselect * from posts
#1Why I switched to Postgres
#2Draft: my RLS notesprivate
#3Ships on Fridays
Bbob's appselect * from posts
#1Why I switched to Postgres
#2Draft: my RLS notesprivate
#3Ships on Fridays
Bob is reading Alice's private draft. This is the leak.

The table is wide open. The same query hands every row to both identities — Bob is reading Alice's private draft. Nothing is stopping him.

One query. Two identities. Different answers. No where clause chooses who sees what — the policy does, inside Postgres. You do not yet understand howthat clause works; that is Tiers 9–10. This concept exists to make you want the answer.
↑ play a little first, then dig in