PostgreSQL guard proxy · pre-alpha
sluice
A small proxy written in C that sits between a client and PostgreSQL: it reads every query, decides whether it goes through and records the decision. No server extension: only the client's connection string changes.
One binary and one rules file. You run it next to the client, on a laptop, as a Kubernetes sidecar or in CI, and the client connects to it instead of the database. It is a safety net against mistakes and an audit trail, not a barrier against a determined attacker: GRANT and row-level security remain the real protection.
What I built
- SQL is read by PostgreSQL's own parser (libpg_query), then judged by rules written in TOML: no UPDATE or DELETE without a WHERE, read-only for an AI agent, access limited to some tables.
- An audit mode to see what would be blocked, an enforce mode to block it: the client gets a normal PostgreSQL error and keeps its connection.
- Confirmation before a DELETE or UPDATE: the statement runs in an uncommitted transaction, the affected rows are shown, and nothing is committed without an answer.
- Every verdict is logged as JSON, with values masked on request; TLS available on both the client and the database side.
Highlights
- When TLS is requested and cannot be had, the connection fails: it never falls back to plain text.
- In enforce mode, what it cannot read is blocked rather than let through.
- Tested against a real PostgreSQL 17, with sanitizers and fuzzing targets.
- Measured and published cost: around 0.1 ms per query and 10 to 15% less throughput.