0
Challenge · 56RLS: The Core
GRANT vs RLS: privileges are columns, policies are rows
Securityused in ~70% of apps
DevLog wants one more, very ordinary feature: a user may edit their own bio, but nothing -- not a bug, not a clever query, not the Data API being asked nicely -- should ever let them flip their own is_admin flag to true. You already know how to write "only your own row" as a policy. But is_admin lives on the same row as bio. RLS decides which rows a statement can touch; it has no concept of which columns are in play at all. The tool for "never this column, regardless of the row" is not RLS -- it is a completely separate system you already granted broadly on day one and never looked at again: GRANT.
Core idea. GRANT and RLS are two independent privilege systems, and every request must clear both. GRANT (optionally scoped per column, as `GRANT UPDATE (bio) ON profiles`) decides which columns a role may touch on a table at all -- checked once per statement, before any row is examined, and it is all-or-nothing: reference one ungranted column anywhere in the statement and the whole thing is rejected. RLS decides which rows a role may touch -- evaluated per row, and blind to which specific columns the statement mentions. A policy can read a sensitive column like is_admin inside its own USING expression to help decide a row's visibility, but that does nothing to stop the column from being returned once the row is deemed visible -- hiding a column is GRANT's job, and only GRANT's.
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
This table's columns are all fully granted to
authenticated -- GRANT is not the obstacle here. Run this as alice, targeting bob's row. Predict whether it succeeds, and if not, what kind of failure you get.Querying as
Cmd/Ctrl + Enter
↑ play a little first, then dig in