Dev.to
7/17/2026

A governance pattern for restricting AI agent database access to read-only queries
Original: AI agent has more write access than the newest hire
Short summary
The author presents a governance pattern for AI agents accessing databases: a gatekeeper proxy that allows SELECT queries but blocks all write operations, with every verdict logged to an append-only ledger. The pattern is implemented three ways — OPA with Rego for production infrastructure, client-side JavaScript for a browser demo, and a Terraform-provisioned container — all sharing identical verb parsing and blocklist logic. The approach complements read-only replicas by adding policy enforcement and audit logging that replicas alone can't provide.
- •Gatekeeper pattern: agent talks to a policy proxy, never directly to the database; only SELECT passes, writes are blocked
- •Three implementations: OPA/Rego for production, JS for browser demo, Terraform for provisioning — all sharing identical logic
- •Append-only ledger logs every query verdict for tamper-proof audit; defense in depth on top of read-only replicas
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



