Dev.to Security 🔐 Cybersecurity 👁 0 📖 2 min read

A catalogue-only Postgres role for nightly RLS drift checks (measured on PG17)

A monitoring job that reads pg_catalog does not need to read a single application row. I wanted to verify that claim instead of repeating it, so I ran a small local experiment. The setup Local PostgreSQL 17 c

A monitoring job that reads pg_catalog does not need to read a single application row. I wanted to verify that claim instead of repeating it, so I ran a small local experiment.

The setup

Local PostgreSQL 17 container, one table public.orders, and a role created with:

CREATE ROLE rls_monitor LOGIN PASSWORD 'CHANGE_ME'
  NOSUPERUSER NOCREATEDB NOCREATEROLE NOREPLICATION NOBYPASSRLS;
GRANT CONNECT ON DATABASE postgres TO rls_monitor;
GRANT USAGE ON SCHEMA public TO rls_monitor;

No SELECT on any table. No service_role, no superuser, no BYPASSRLS, no write grants. pg_catalog and information_schema are readable by PUBLIC by default, which is all the checks need.

What I measured

I connected as rls_monitor and ran the 12-check SQL (catalogue reads only):

  • It returned a HIGH finding for public.orders — row level security disabled.
  • A direct SELECT count(*) FROM public.orders returned permission denied for table orders.

So the monitor could see the security-relevant catalogue state without being able to see customer data. This was a synthetic fixture in a scratch database, not a production app; I am not claiming anything about hosted plan defaults or about which revision a hosted platform runs.

What the 12 checks look at

A: RLS disabled · B: RLS on but not FORCEd (owner bypass) · C: permissive USING (true) SELECT/ALL policies · D–E: missing WITH CHECK · F: policies open to PUBLIC · G–H: SECURITY DEFINER without pinned search_path, or owned by a bypassing role · I: write grants to anon/authenticated · J: public EXECUTE grants · K: pg_default_acl future grants · L: views without security_invoker.

Two caveats worth keeping: a catalogue signal is not proof of a leak, and zero findings does not mean safe. Also, the nightly diff must be fail-closed — if the credential breaks, that must never be reported as "all findings resolved". I use a snapshot of finding fingerprints as the baseline: every new fingerprint alerts until a human refreshes the baseline.

Files

I packaged the workflow, the standalone SQL, a short start-here guide (TR/EN) and the role template here: https://kurtoglu1.gumroad.com/l/supabase-rls-drift-monitor-free

It is free. If role creation is unavailable on your platform, use your least-privileged read-only role and keep the same rule: no service_role, no row reads, no writes.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.