How to Configure OpenHands Postgres Read Only Access

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up openhands postgres read only access by making a dedicated database role. That role only gets permission to read specific tables and columns. Teams often start by giving AI agents their main app database keys. This fast shortcut creates big risks when an agent runs a bad query. A broad role lets the agent change rows, drop tables, or read private fields. Scoping the database role down to read privileges is a good first step. How native openhands postgres read only access works Postg

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 read only access by making a dedicated database role. That role only gets permission to read specific tables and columns. Teams often start by giving AI agents their main app database keys. This fast shortcut creates big risks when an agent runs a bad query. A broad role lets the agent change rows, drop tables, or read private fields. Scoping the database role down to read privileges is a good first step.

How native openhands postgres read only access works

PostgreSQL controls table permissions through roles and grants. To set up openhands postgres read only access, an admin creates a group role. Individual user accounts for the agent then join this group role. The admin grants the read privilege on target tables, views, or specific columns. This privilege also lets the role export data out of the table.

Admins must also check the built-in public group role. By default, every role on the system gets permissions assigned to this public group. It allows any user to connect to the database and make temporary tables. It also lets any role run functions and procedures by default. An object owner can take back these default rights to tighten security.

In PostgreSQL 15 and newer, regular users cannot make objects in the public schema. Older databases, or upgraded ones, may still allow this action by default. In those cases, an admin must take away schema creation rights from the public group. Admins also set default rules so future tables grant read rights to the group role.

What native roles solve and what they miss

A native read role stops the agent from deleting rows or changing table data. It blocks write actions at the database engine level before any harm happens. If OpenHands tries to update a record, PostgreSQL rejects the command right away. This setup is essential for any agent that inspects production or staging data.

Still, database roles only check who logs in and which tables they can read. Once the login succeeds, the role allows any read query on those allowed tables. A table with user accounts often holds both safe metadata and private details. Native table grants do not rewrite sensitive fields inside query results on the fly.

Auditor Read-Only Access + Customer Support Access to Production: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Column grants can hide certain columns, but they break many standard agent queries. If an agent selects all columns from a table, the whole query fails. Also, native roles still allow bulk exports from any table the agent can read. An agent with read rights can pull millions of emails, phone numbers, or card numbers. The database also keeps a static password that the agent needs to store locally. Teams still need a way to mask sensitive fields in results and track every query.

Why runtime controls matter for AI agents

AI coding agents work fast and run many database queries during a single task. They read schemas, check sample rows, and test joins to fix bugs. Static database roles cannot tell a safe debugging check from a massive data dump. Adding runtime rules lets teams inspect queries in flight and rewrite sensitive data fields. Data masking rewrites matched fields like emails and national IDs in the returned rows. The agent gets the schema shape it needs without pulling raw personal data into prompts.

Run guardrails and masking on the Postgres connection

Role grants and firewall rules are needed setup. Setup alone cannot check single SQL statements or mask sensitive rows in a response. By design, hoop.dev is an open-source proxy that sits beside Postgres, RDS, or Aurora as a sidecar for your Postgres. Clients and agent tools keep their credentials and point their connection string at the listener.

On each query, hoop.dev guardrails refuse disallowed drops, deletes, or table reads before they run. Next, hoop.dev data masking rewrites sensitive fields in returned rows that match your rules. Furthermore, hoop.dev holds SOC 2 Type II and logs every statement and verdict per resource. Check out the project on GitHub.

Frequently asked questions

Can PostgreSQL grant read access to only specific columns?

Yes, PostgreSQL lets admins grant the read privilege on specific columns of a table. Still, queries that ask for all columns in that table will then fail.

Why can a read-only PostgreSQL role still run functions?

PostgreSQL grants function execution rights to the built-in public group by default. Every new role inherits those rights until the object owner revokes them from public.

Does a read-only role stop an OpenHands agent from reading sensitive data?

No, a read-only role can read every row and allowed column in granted tables by default. You need data masking to rewrite emails, phone numbers, or card numbers in results.

The query runs. The emails stay hidden.