How to Configure Claude Code CockroachDB Permissions
You set up claude code cockroachdb permissions by creating a read-only database user. Then you pass that user string to a Model Context Protocol server. Teams often reuse an admin account just to make a quick fix. Broad roles let an agent change live rows or drop tables by mistake. A strict setup limits the agent to safe read queries from the start. How claude code cockroachdb permissions work in practice Claude Code talks to outside databases through the Model Context Protocol, or MCP. The o
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 claude code cockroachdb permissions by creating a read-only database user. Then you pass that user string to a Model Context Protocol server. Teams often reuse an admin account just to make a quick fix. Broad roles let an agent change live rows or drop tables by mistake. A strict setup limits the agent to safe read queries from the start.
How claude code cockroachdb permissions work in practice
Claude Code talks to outside databases through the Model Context Protocol, or MCP. The official docs state that MCP servers give the agent access to databases. One common path uses the DBHub MCP server with a database connection string. Because CockroachDB speaks the PostgreSQL wire protocol, this setup works well for teams. The vendor docs tell you to use a read-only database user here. That way, the queries the agent runs cannot modify your live data.
Inside CockroachDB, you build a dedicated role for the coding agent. You grant this role select privileges only on the schemas it needs. You skip grants for insert, update, delete, and drop statements on all tables. Next, you create a dedicated user and assign it to that read-only role. You put those user keys into your local MCP server settings. You also verify that you trust the MCP server before connecting it.
Claude Code can also reach your database through its built-in Bash tool. An engineer might ask the agent to run a local database client command. In Manual mode, the Bash tool asks for human approval before running commands. It only skips approval for basic local read commands like listing files. Even so, the database role must still enforce read-only rules at the database.
What native database roles solve and what they miss
Native database roles do a good job of stopping direct writes and deletes. When the agent connects with a read-only user, CockroachDB blocks any data changes. This stops a bad prompt from wiping a table or altering schemas. It gives your team a clear baseline for safe database checks.
Still, native database roles only check who logs in and which tables they read. They do not inspect what individual queries return while in flight. A read-only user can still run a select query on a customer table. That query will pull raw emails, phone numbers, card numbers, and national IDs. Those sensitive fields then flow straight into the model context window.
Claude Code Security + AI Agent Permissions: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Native roles also rely on static connection strings stored on developer laptops. Every engineer needs a copy of the database password in local settings. If a laptop gets lost, you must rotate that shared password across the team. Static grants also cannot require a quick peer approval for a one-off write. And database logs only show the shared agent user, not which engineer ran it.
Closing the gap for live database queries
To fix these gaps, teams need controls that work on each query in flight. First, you want to tie every agent query to a real human user. Second, you need field masking that rewrites matched fields in query results. When a query runs, masking replaces emails and card numbers before results return. Third, you want to stop storing static database passwords on developer machines. These steps keep data safe while letting engineers use coding agents every day.
Check database and API queries on the wire
Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev sits inline in the wire protocol beside those services as an open-source proxy, a sidecar for your Postgres or API. On every query an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.
Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run, and hoop.dev data masking rewrites matched sensitive values in responses in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.
Frequently asked questions
How does Claude Code connect to a CockroachDB cluster?
Claude Code reaches databases through an MCP server like DBHub or through its Bash tool. You pass a standard connection string to the MCP server to link the cluster.
Why should I use a read-only user for Claude Code?
A read-only user stops the agent from changing rows or dropping tables by accident. The vendor docs advise using a read-only user in your MCP connection string.
Do read-only CockroachDB roles stop sensitive data exposure?
No, a read-only role can still read every column in an allowed table by default. You need result masking to rewrite emails, phone numbers, and card numbers in results.
Related guides
In this post