How to Configure OpenHands Postgres Approval
You set up openhands postgres approval by pairing strict database roles with agent confirmation prompts. This setup stops AI coding agents from running unapproved data changes on your tables. Many teams start by giving their AI agent a shared developer database account. That broad role lets the agent drop tables or read private rows by mistake. A safer plan uses tight database privileges and clear human review steps. How openhands postgres approval works with database roles Your first step ha
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
You set up openhands postgres approval by pairing strict database roles with agent confirmation prompts. This setup stops AI coding agents from running unapproved data changes on your tables. Many teams start by giving their AI agent a shared developer database account. That broad role lets the agent drop tables or read private rows by mistake. A safer plan uses tight database privileges and clear human review steps.
How openhands postgres approval works with database roles
Your first step happens inside the database engine itself. You must build a dedicated role just for the AI agent. Never let the agent log in with an owner account. Instead, use group roles to manage privileges across your team and tools. You can create a read-only group role and add the agent to it.
Next, you need to check what the special PUBLIC role allows. In PostgreSQL, the PUBLIC role gives rights to every user on the system. By default, PUBLIC gets the right to connect to databases and make temporary tables. It also gets the right to run functions and procedures. The database owner can take away these default rights from PUBLIC.
You should also check the public schema rules on your server. Since PostgreSQL 15, normal users cannot create new objects in the public schema by default. Older databases, or upgraded ones, might still allow this action. If you run an older database, revoke the create right on the public schema from PUBLIC.
After you lock down defaults, grant read rights only where the agent needs them. The SELECT privilege lets a role read from a whole table or view. You can also grant SELECT on specific columns of a table. This lets the agent inspect table shapes without reading secret columns. Note that the SELECT privilege also allows the agent to export data with COPY TO.
Why native roles are not enough for agent workflows
Database roles control who can log in and which objects they can touch. Still, static roles cannot pause a single query to ask a human for permission. Once a role has write rights on a table, every update runs right away. The database engine does not know if a human or a bot sent the query.
On the client side, an AI agent can ask a user before running a shell command. This local check helps during small tests, but it has big limits for teams. If the agent holds raw database keys in its workspace, it can bypass prompt rules. Any script the agent runs in that space can read those stored keys.
Approval Chains & Escalation + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Also, static column grants take a lot of work to keep up to date. Every time a developer adds a table, an admin must update the column grants. If someone forgets a column, the agent pulls raw emails, phone numbers, or card numbers. Even worse, a wide SELECT query can dump thousands of customer rows into the agent log. Native roles decide who gets in, not what each statement does in flight.
Building a safe review flow for database queries
To fix this gap, teams separate read tasks from write tasks. The agent uses a restricted role to read schema details and plan its code. When the agent needs to change data or alter a table, the flow must pause. A human reviewer should see the exact statement before the database runs it.
Good review flows also protect private fields in query results. Instead of relying only on column grants, teams use data masking on the output. Masking rewrites matched fields like emails, phone numbers, and national IDs in the results. This lets the agent test queries against real table shapes while keeping customer details safe.
Add query and result controls beside Postgres
Grants and pools govern who logs into PostgreSQL. Yet every query in an open session still runs with that role's full scope. In practice, hoop.dev runs beside your database as a sidecar for your Postgres. It reads plain and prepared queries on the wire with no change to your users or drivers.
When a tool or agent sends SQL, hoop.dev Postgres controls check each statement against your deny rules. An AI Analyzer you configure can also score intent or hold a risky query for human review. Matched sensitive columns in result rows are masked in memory before they reach the caller. Each query and decision is logged per listener, which generates evidence for SOC 2, HIPAA, and GDPR audits. View the binary on GitHub.
Frequently asked questions
Can PostgreSQL pause a single query for human approval on its own?
No, PostgreSQL checks role permissions right when a statement arrives and runs it right away. It does not have a built-in queue to hold queries for a human review.
How do I stop OpenHands from reading secret columns in a table?
You can grant the SELECT privilege on specific safe columns rather than the whole table. You can also add data masking to rewrite emails, phone numbers, and card numbers in results.
Why can my restricted agent role still run functions in PostgreSQL?
By default, PostgreSQL gives the special PUBLIC role the right to run functions and procedures. A database owner must revoke those default rights from PUBLIC to block the agent.
Related guides
In this post