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 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…
Monitoring a Postgres database for Row Level Security (RLS) drift is possible without granting excessive privileges to a monitoring role. This was demonstrated using a small Local PostgreSQL 17 container with a single table named public.orders. The monitoring role, rls_monitor, was created with minimal privileges: LOGIN, NOSUPERUSER, NOCREATEDB, NOCREATEROLE, NOREPLICATION, NOBYPASSRLS, CONNECT, USAGE, and no select grants on tables.
The monitoring job utilized the 12-check SQL to assess RLS configurations. The checks included: verifying that RLS was disabled, checking if RLS was enabled but not forced, examining for permissive USING (true) SELECT/ALL policies, identifying missing WITH CHECK clauses, detecting policies open to PUBLIC, checking for SECURITY DEFINER without pinned search_path or bypassing roles, reviewing write grants to anonymous or authenticated users, inspecting public EXECUTE grants, monitoring future grants to pg_default_acl, and identifying views without the security_invoker.
The monitoring role was able to access the pg_catalog and information_schema, which provided the necessary catalog data for the checks. However, the role could not perform any data reads on the public.orders table, ensuring that sensitive customer data remained protected. The workflow, standalone SQL, a short guide, and the role template were made available for free at https://kurtoglu1.gumroad.com/l/supabase-rls-drift-monitor-free.
The author emphasizes that a catalog signal is not proof of a leak, and zero findings do not guarantee safety. Additionally, the nightly diff must be fail-closed to avoid false reporting in the event of credential issues.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to