Most database drift and data-quality tools ask for a connection string with SELECT privileges across your production tables. For B2B SaaS teams handling customer PII, billing records, or multi-tenant Supabase schemas, giving a CI workflow or monitoring agent read access to every production row is a hard no.
Yet three silent production regressions keep happening on PostgreSQL, Supabase, and Neon:
- Someone disables Row-Level Security (RLS) on a table in the dashboard during debugging and forgets to re-enable it.
- A developer creates a
publicview withoutsecurity_invoker = true— silently bypassing RLS on the underlying tables because views default to running with the view owner's privileges. - An unreviewed migration adds a column with a volatile default, runs
CREATE INDEXwithoutCONCURRENTLY, or drops a column that downstream services still query.
I built pgseal (GitHub Actions Marketplace) — a single static Go binary (~10.75 MB, MIT license, only pgx/v5 as a runtime dependency) — to catch all three while proving it has zero read access to user table rows.
1. Zero-Data-Access Attestation (select_privileged_tables = 0)
Running pgseal init --role pgseal_ro --db appdb prints the least-privilege SQL for your database:
CREATE ROLE pgseal_ro LOGIN PASSWORD '<set-via-secret-manager>'
NOSUPERUSER NOCREATEDB NOCREATEROLE NOREPLICATION NOBYPASSRLS NOINHERIT
CONNECTION LIMIT 2;
GRANT CONNECT ON DATABASE appdb TO pgseal_ro;
ALTER ROLE pgseal_ro SET default_transaction_read_only = on;
ALTER ROLE pgseal_ro SET statement_timeout = '3s';
ALTER ROLE pgseal_ro SET lock_timeout = '200ms';
Notice there are zero GRANT SELECT statements on any user table. PostgreSQL lets any role with CONNECT inspect pg_catalog.* and pg_stat_* metadata. pgseal executes all 12 embedded catalog queries inside a single transaction:
BEGIN ISOLATION LEVEL REPEATABLE READ READ ONLY;
SET LOCAL statement_timeout = '3000ms';
SET LOCAL lock_timeout = '200ms';
Every pgseal doctor and pgseal snapshot run records a live attestation:
select_privileged_tables = 0is_superuser = falsebypass_rls = falseread_only_tx = true
In CI across PostgreSQL 15, 16, and 17 behind PgBouncer (pool_mode=transaction), our integration suite explicitly verifies two things:
-
pg_stat_user_tablesuser-table scan delta (seq_scan + idx_scan) equals 0 (validated alongside a negative control that proves a realSELECTincrements the counter). - Attempting
SELECT 1 FROM public.<user_table>withpgseal_roreturns PostgreSQL error42501 permission denied.
2. Catching Real RLS Leaks (Verified Live on Neon PostgreSQL 17.12)
During live testing against a Neon Serverless PostgreSQL 17.12 instance (-pooler.*.aws.neon.tech with channel_binding=require&sslmode=require), two real-world catches stood out immediately:
-
Views silently bypassing RLS (
RLS-004): When we created a normalpublic.invoice_summaryview and grantedSELECTtoPUBLIC,pgseal rlsflagged[BREAKING] RLS-004(security_invoker=false), ANDpgseal doctorsimultaneously caught thatpgseal_rohad inheritedSELECTon that view viaPUBLIC(DOC-001, exit code2). -
Live RLS toggle + breaking column drop: After revoking
PUBLICaccess on the view (doctorpassed in 398 ms over the internet withselect_privileged_tables=0,pooler_detected="neon-pooler"), we took a baseline snapshot (841 ms) and ran:
ALTER TABLE public.invoices DISABLE ROW LEVEL SECURITY;
ALTER TABLE public.invoices DROP COLUMN created_at;
pgseal diff immediately exited 2 catching DIFF-010 [BREAKING], and pgseal rls --baseline exited 2 catching RLS-001 [BREAKING] (rls_enabled: true -> false).
Altogether, pgseal rls checks 7 rules (RLS-001 through RLS-007), including USING (true)/1=1 tautologies, 0-policy lockouts, SECURITY DEFINER functions exposed to anon/public, and policies referencing client-mutable user_metadata.
3. Transaction Pooler Safety (PgBouncer / Supavisor / Neon Pooler)
A common reason schema tools fail on Supabase (:6543 Supavisor) and Neon (-pooler.neon.tech) is prepared-statement caching or unsupported startup options parameters in transaction pooling mode.
pgseal enforces:
-
pgx.QueryExecModeSimpleProtocolwithStatementCacheCapacity = 0 - Transaction-local
SET LOCALinstead of startupoptions - Automatic Neon host detection (extending connect timeout to
30sfor scale-to-zero compute wakeups, retrying transient57P03errors while failing fast on28P01auth errors) - Default exclusion of internal Supabase schemas (
auth,storage,realtime,vault,extensions,pgsodium,supabase_migrations, etc.)
4. Fast Deterministic Lockfiles, Offline SQL Linting & Zero-ML Freshness
-
Deterministic diff:
.pgseal/schema.lock.jsonstores canonical JSON with Merkle SHA-256 sub-hashes. On Apple M2, diffing a 500-table / 5,000-column schema takes 0.24 ms/op (0.14 ms/op on unchanged schemas). -
Offline migration lock safety (
pgseal check-sql): A pure-Go SQL lexer checks 9 rules before merge (SQL-001–SQL-009), includingCREATE INDEXwithoutCONCURRENTLY,CONCURRENTLYinsideBEGIN..COMMIT, volatileADD COLUMN DEFAULT,SET NOT NULLwithoutNOT VALID, missingSET lock_timeout, andCREATE TABLEin exposed schemas withoutENABLE ROW LEVEL SECURITY. -
Zero-ML table freshness (
pgseal watch): Trackspg_stat_user_tableswrite-activity deltas across 168 weekday×hour seasonal buckets using MAD/IQR with stats-reset and replica guards.
3-Line GitHub Action
- uses: yun87457-web/pgseal@v0
with:
mode: drift # drift | rls | check-sql | watch
dsn: ${{ secrets.PGSEAL_DATABASE_URL }}
The Action downloads the pinned static release binary, verifies its SHA-256 against checksums.txt, posts or updates a single sticky PR comment (<!-- pgseal -->), and safely skips with exit code 0 on fork PRs when secrets are unavailable.
- GitHub: https://github.com/yun87457-web/pgseal
- GitHub Actions Marketplace: https://github.com/marketplace/actions/pgseal
Top comments (0)