How to Configure Gemini CLI Postgres Permissions
You set up gemini cli postgres permissions by making a dedicated database role for the agent. Next, you grant that role read rights only on the specific tables and columns it needs. Many teams give AI terminal tools their own admin database login to move fast. Broad roles let an agent drop tables, change rows, or read sensitive customer data by mistake. A tight role setup stops bad writes before they hit your database. How to set up gemini cli postgres permissions Start by creating a group ro
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 gemini cli postgres permissions by making a dedicated database role for the agent. Next, you grant that role read rights only on the specific tables and columns it needs. Many teams give AI terminal tools their own admin database login to move fast. Broad roles let an agent drop tables, change rows, or read sensitive customer data by mistake. A tight role setup stops bad writes before they hit your database.
How to set up gemini cli postgres permissions
Start by creating a group role that holds your read-only rules. In PostgreSQL, you can set up group roles to manage privileges across many users. You then grant your agent login membership in that group role. This keeps your permission rules clean as you add more tools or users.
Next, lock down the default privileges that every role gets at birth. PostgreSQL has a special role name called PUBLIC that grants rights to every role on the system. By default, PUBLIC gets the right to connect and make temp tables on databases. It also gets the right to run functions and procedures. The database owner can revoke these default rights from PUBLIC so your agent starts with zero power.
You also need to check the public schema on older databases. In PostgreSQL 15 and later, the default setup stops every user from making objects in the public schema. Older databases, or ones upgraded from older versions, might still allow this. An admin can fix that by revoking the create right on the public schema from PUBLIC.
Now you can grant explicit read rights to your agent group role. In PostgreSQL, the select privilege lets a role read from a whole table or view. You can also grant select on specific columns of a table or materialized view. Column-level grants let you leave out columns that hold passwords or secrets. Keep in mind that the select privilege also allows the copy-to command on those same columns.
What native database roles solve and what they miss
Native database roles do a great job of controlling who can log in. They also draw a hard line between tables a user can read and tables they cannot touch. If the AI tool tries to update a row without write rights, the database blocks it right away. If you use column grants, the database also blocks queries that ask for restricted columns.
Still, static database roles leave big operational gaps open when an AI agent runs queries. First, the agent needs a database password or key stored on the user machine. Any local script or prompt mistake can read that secret from the local shell. Second, column grants are all-or-nothing. Often, an agent needs to read a support table to debug an issue. That table might hold emails, phone numbers, card numbers, or national IDs inside free-text notes or needed columns.
AI Agent Permissions + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Native roles cannot rewrite those sensitive fields in flight. If a role has select rights on a column, it gets every raw value in that column. Native grants also cannot pause a risky query to ask a human for approval on the spot. Database roles decide who logs in and which objects they can touch. They do not inspect or filter what individual statements return in real time.
Managing credentials and query safety for AI agents
When an AI agent runs in a terminal, it acts with the full power of its database login. Giving each developer a static role secret creates secret sprawl across laptops. When someone leaves the team or a key leaks, rotating credentials breaks local setups.
A safer approach pairs strict PostgreSQL group roles with runtime controls outside the client machine. You keep the database role limited to select privileges on safe schemas. At the same time, you avoid storing long-lived database passwords in plain text on laptops. You also need a way to mask emails, phone numbers, card numbers, and national IDs in query results. Masking rewrites matched fields in results before the terminal agent ever receives the output. This lets the agent debug schema issues and read row counts while keeping private data safe.
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 I grant a PostgreSQL role read rights on just a few columns?
Yes, PostgreSQL lets you grant the select privilege on specific columns of a table, view, or materialized view. If the AI agent queries a column outside that grant, the database rejects the query.
Why can a new read-only role still run functions in PostgreSQL?
PostgreSQL grants default rights to a special group called PUBLIC, which includes every role on the system. By default, PUBLIC gets the right to run functions, connect to databases, and make temp tables unless the owner revokes them.
How do I stop a read-only role from creating tables in the public schema?
PostgreSQL 15 and newer versions block this by default. On older or upgraded databases, an admin must revoke the create privilege on the public schema from the PUBLIC role.
Related guides
In this post