How to Configure Codex Postgres Read Only Access

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up codex postgres read only access by creating a limited database role. Then you grant that role select permissions on specific tables or columns. Many teams connect AI coding agents using a standard app user. When roles are too broad, an agent can change rows or drop tables by mistake. A strict read role stops the agent from writing to your database. How codex postgres read only access works in PostgreSQL PostgreSQL manages permissions through roles. You can set up a group role to ho

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 codex postgres read only access by creating a limited database role. Then you grant that role select permissions on specific tables or columns. Many teams connect AI coding agents using a standard app user. When roles are too broad, an agent can change rows or drop tables by mistake. A strict read role stops the agent from writing to your database.

How codex postgres read only access works in PostgreSQL

PostgreSQL manages permissions through roles. You can set up a group role to hold your read permissions. Then you grant your AI agent user membership in that group role. The select privilege lets a role read from a table, view, or materialized view. You can also grant select on specific columns rather than the whole table. Keep in mind that select also allows the copy to operation.

You must also check the built-in public role. By default, every role on the system gets permissions granted to public. The public role gets connect and temporary rights on databases by default. It also gets execute rights on functions and procedures. An object owner can revoke these default rights to lock down the database. In older database versions, users could create new objects in the public schema. Upgraded databases may still allow this unless an admin revokes that create right.

What native database roles solve and what they miss

A native read role solves the problem of accidental data writes. When the AI agent runs a query, the database blocks any insert or delete. You can also limit which tables the agent sees by scoping schema rights. This setup decides who can log in and which objects they can read.

Still, database roles do not inspect what individual queries do in flight. A read role still lets an agent run a huge query that slows down production. If a table holds sensitive columns, a table-wide select grant exposes all of them. Granting select on each clean column one by one takes a lot of time. Schema changes can also add new columns with emails, phone numbers, or card numbers. Also, stored functions might still run with write rights if execute keeps the session active to public. Finally, giving the agent raw database keys means storing secrets on developer machines.

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.

Best practices for managing AI agent database sessions

Start by creating a dedicated group role just for AI coding agents. Revoke default execute rights from the public role on any function that modifies data. Revoke temporary table rights if the agent only needs to read existing views. Check upgraded databases to make sure the public role cannot create schema objects.

Limit permissions to the exact schemas and columns the agent needs for its task. Even with column grants, raw results can still contain emails or national IDs. Database roles alone cannot rewrite matched fields in results while a query runs. Teams need a way to inspect queries and mask sensitive fields in flight.

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 sits inline in the Postgres protocol beside Postgres, RDS, or Aurora as a sidecar for your Postgres. On every production query from an engineer or AI agent, hoop.dev decides whether to pass, mask, block, or hold it for approval.

First, hoop.dev guardrails refuse disallowed drops or deletes before they run, and risky statements can pause for human review. Next, hoop.dev data masking rewrites sensitive fields in returned rows in memory. 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 a PostgreSQL read role still run functions that change data?

Yes, it can if the function has public execute permissions. By default, the public role gets execute rights on new functions and procedures. You must revoke execute from public so the read role cannot run them.

Does the select permission allow bulk data exports?

Yes, the select privilege in PostgreSQL also allows the copy to command. An agent with select rights on a table can export all rows it can read. You can restrict access to specific columns to limit what gets exported.

Why can my read-only user create tables in the public schema?

Databases created before PostgreSQL 15 let the public role create objects in the public schema. Databases upgraded from older versions keep this old setting until you change it. An admin must revoke the create right on the public schema from public.

The query runs. The emails stay hidden.