How to Configure Claude Code CockroachDB Least Privilege

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up claude code cockroachdb least privilege by creating a read-only database user. Then you pass that restricted user into your Model Context Protocol server setup. Many teams skip this step and reuse their local admin database keys. Broad roles let an AI coding agent alter tables or read sensitive rows. A scoped role stops the agent from modifying or deleting production records. How claude code cockroachdb least privilege works in practice Claude Code talks to outside tools and databa

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 least privilege by creating a read-only database user. Then you pass that restricted user into your Model Context Protocol server setup. Many teams skip this step and reuse their local admin database keys. Broad roles let an AI coding agent alter tables or read sensitive rows. A scoped role stops the agent from modifying or deleting production records.

How claude code cockroachdb least privilege works in practice

Claude Code talks to outside tools and databases through the Model Context Protocol. The vendor docs list querying databases as a common use case for MCP. They show a PostgreSQL setup that uses the DBHub MCP server. Because CockroachDB speaks the PostgreSQL wire protocol, the same pattern applies here. You create a dedicated database role that only holds read permissions. You grant that role select rights on specific schemas and tables. Then you put that read-only user into the MCP server connection string. This ensures the queries the agent runs cannot modify your stored data. The agent can also run terminal commands through its built-in Bash tool. In Manual mode, the Bash tool asks for your approval before running commands. Only a small set of safe read-only commands run without a prompt. If a developer stores database keys in local files, shell commands might read them. Keeping the database user locked down limits damage if the agent runs a script. You should also verify that you trust any MCP server before you use it.

What native database roles solve and what they leave open

Native database roles control who can log in and which tables they can read. A read-only user stops the agent from dropping tables or changing rows. This setup is a strong first step for any team using AI agents. Still, database roles do not inspect individual queries while they run in flight. Once the agent logs in, it can read every column in an allowed table. If a customer table holds emails, phone numbers, or card numbers, the agent gets them. Those raw values then flow back into the model context window. Native roles also treat every read query the same way. They cannot pause a massive table scan or ask a human to approve one query. Also, the MCP server needs a real database password on the user machine. Developers must manage, rotate, and protect those local secret strings on every laptop. Static roles set the boundary at login, not at the level of each query.

Scoping tables and schemas for AI coding agents

To tighten your native setup, separate public app tables from private user records. Create a clean schema that holds only safe tables or filtered database views. Grant your AI agent role access to that single schema alone. Never grant select rights across an entire database when a few tables will do. Check your role grants often as your team adds new tables to the app. Set statement timeouts on the database user so bad queries fail fast. A runaway join from an AI agent can still slow down a cluster. Combine tight schema grants with resource limits to keep your cluster safe and fast.

Least Privilege Principle + Claude Code Security: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Add runtime guardrails and masking beside your databases and APIs

Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits inline in the protocol beside the service as an open-source proxy, a sidecar for your database or API. On every production query an agent or human runs, hoop.dev decides whether to pass, mask, block, or escalate it for review.

Before a query runs, hoop.dev guardrails check the statement against your rules, an AI Analyzer you configure can score intent or hold risky calls for human approval, and hoop.dev data masking rewrites sensitive fields in responses in memory. Explore the MIT-licensed project on GitHub.

Frequently asked questions

How does Claude Code connect to a CockroachDB database?

It connects through a Model Context Protocol server or by running terminal database tools. The vendor docs recommend using a read-only database user in your MCP connection string.

Why is a read-only database role not enough for AI agents?

A read-only role still lets the agent pull every column in an allowed table by default. Sensitive fields like emails, phone numbers, and national IDs can enter the model prompt.

Can the Bash tool bypass MCP database restrictions?

Yes, if local files hold admin database keys, a shell command could use them. In Manual mode, the Bash tool asks for approval before running non-basic commands.

The query runs. The emails stay hidden.