How to Configure OpenHands Postgres Credentials
You set up openhands postgres credentials by creating a restricted database role and passing it into the agent container. You should give this role only the specific table and column privileges it needs to run tasks. Many teams start by giving their coding agent a full admin user to save time. That choice lets the agent read sensitive rows or drop tables by mistake. A safer setup uses native database roles to limit what the agent can touch from the start. How to set up openhands postgres cred
Ephemeral Credentials + End-to-End Encryption: the complete guide
Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.
You set up openhands postgres credentials by creating a restricted database role and passing it into the agent container. You should give this role only the specific table and column privileges it needs to run tasks.
Many teams start by giving their coding agent a full admin user to save time. That choice lets the agent read sensitive rows or drop tables by mistake. A safer setup uses native database roles to limit what the agent can touch from the start.
How to set up openhands postgres credentials with database roles
Start by creating a dedicated role in your database for the agent. Do not reuse a developer account or the main app user. If you run several agents, you can create a group role first. You then grant permissions to that group role and add each agent role as a member. This structure keeps your permission rules clean as your team grows.
Next, lock down what the new role inherits from the system. Postgres has a special role called PUBLIC that includes every user on the server. By default, PUBLIC can connect to databases, create temp tables, and run functions. The database owner can revoke these default grants so the agent starts with zero extra rights.
You also need to check the public schema on older databases. In Postgres 15 and newer, regular users cannot create new objects in the public schema by default. If your database came from an older version, an admin must revoke that create right from PUBLIC. This step stops the agent from building unwanted tables during a run.
Finally, grant the SELECT privilege on the exact tables the agent needs to inspect. Postgres lets you grant SELECT on specific columns of a table or view. Column grants help you keep secret columns away from the agent role. Once the role is ready, pass the connection details into the agent container through its secret store.
What native database roles solve and what they miss
Native database roles do a great job of controlling who can log in. They also define which tables and columns a specific user can read or change. If an agent tries to query a blocked table, the database stops the request right away.
Ephemeral Credentials + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Still, static database roles only check permissions at the table or column level. They do not inspect what individual queries do while they run in flight. For example, the SELECT privilege also allows the user to bulk export data. An agent with read rights on a customer table can still pull every email or phone number at once.
Static roles also mean the agent container holds a live password during its entire session. If a prompt causes the agent to print its environment variables, that password can leak into logs. Native roles also cannot pause a risky command to ask a human for approval first. And if you need to hide card numbers or national IDs inside a mixed text column, column grants alone will not help.
Managing secret rotation and audit logs for agent tasks
When an agent runs code on its own, you need a clear record of every query it sends. Standard database logs often mix agent traffic with normal app traffic when roles are shared. Giving each agent its own role helps separate these records in your database logs.
You should also rotate the password for the agent role on a regular schedule. Short password lifetimes shrink the window of risk if an agent log ever gets exposed. Pairing scoped Postgres roles with tight runtime controls gives your team a much safer setup for autonomous coding tools.
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
Should I give an autonomous coding agent a read-only database role?
Yes, start with a read-only role that only has SELECT rights on required tables and columns. Only grant write permissions in isolated test databases where the agent needs to test schema changes.
Why can my new Postgres role still run functions and create temp tables?
Postgres grants connect, temp table, and function execution rights to the special PUBLIC role by default. Every new user gets these rights until the object owner revokes them from PUBLIC.
Can column-level grants stop an agent from reading sensitive user fields?
Yes, Postgres lets you grant SELECT on specific columns of a table or view. If you leave sensitive columns out of the grant, the database blocks any query that asks for them.
Related guides
In this post