The query hit the database hard. You watch rows stream back, but this time every packet is inspected, every byte judged. Open Policy Agent (OPA) is sitting in the middle, enforcing rules before Postgres even replies. This is Postgres Binary Protocol proxying with OPA—fast, precise, uncompromising.
Most access control in Postgres happens at the SQL or application layer. That leaves a gap. Protocol-level proxying closes that gap by intercepting all traffic between clients and the database. With OPA wired in, you can apply declarative policies to the raw Postgres Binary Protocol, not just to SQL statements. Policies are written in Rego and evaluated in real time against each message: authentication requests, prepared queries, transaction commands, even low-level protocol details.
Why proxy at the binary protocol level?
- You avoid relying on the database’s role system alone.
- You can enforce consistent rules across microservices and tools hitting Postgres.
- You can block or transform queries before they reach the database.
- You can record detailed context from every connection for audit and compliance.
An OPA-powered Postgres proxy sits between the client and the database. It decodes the binary protocol, passes the relevant data to OPA, and lets OPA’s decision engine return “allow” or “deny”—or even modify the message. This architecture makes policy enforcement transparent to applications. No changes in client code. No rewriting queries. The proxy handles protocol parsing, routing, and control.