How to Configure OpenHands CockroachDB Least Privilege

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up openhands cockroachdb least privilege by making a scoped database role. Then you assign read or write grants on single tables to that role. Engineering teams often connect AI coding agents to databases using admin accounts. That approach speeds up early testing, but it puts production data at risk. An agent with broad rights can drop tables or alter schemas by mistake. Giving the agent only the rights it needs prevents many bad outcomes. How openhands cockroachdb least privilege wor

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 cockroachdb least privilege by making a scoped database role. Then you assign read or write grants on single tables to that role. Engineering teams often connect AI coding agents to databases using admin accounts. That approach speeds up early testing, but it puts production data at risk. An agent with broad rights can drop tables or alter schemas by mistake. Giving the agent only the rights it needs prevents many bad outcomes.

How openhands cockroachdb least privilege works in practice

OpenHands runs in a sandbox container and executes shell commands or scripts. When the agent needs database state, it uses a client driver to connect. CockroachDB checks the user identity and checks role grants before running queries. You start the setup by creating a dedicated role for the AI agent. Do not reuse a human developer account or a backend service role.

Next, you scope the database grants down to the exact schema and tables. If the agent only debugs data, grant it read rights on those tables. Never grant system admin rights or broad schema modification rights to an agent. You also strip away permission to create new roles or change cluster settings. Once the role is ready, you create a client certificate or password. The OpenHands container reads these secrets from its local runtime variables to connect.

Why teams scope agent roles before testing

AI coding agents work by trying out commands and reading the output. Sometimes a model misreads a prompt and writes a bad delete query. Other times, a loop causes the agent to run heavy table scans. Scoping the CockroachDB role stops the agent from touching unrelated business tables. It also keeps the agent out of system tables that hold cluster secrets.

Teams also use role separation to keep their database audit logs clean. When the agent has its own user name, every query shows its identity. Engineers can filter log entries to see what the agent ran during debugging. If a query slows down the cluster, the team knows which session caused it. Good role design forms the base of safe agent testing in any company.

Least Privilege Principle + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native database roles solve and what they miss

Native CockroachDB roles do a great job of controlling table access at login. They decide which user can read a table or write a new row. This setup blocks unauthorized access to whole databases or private schemas right away. Still, static database grants cannot inspect what a single query does in flight. Once the agent logs in, it can pull every row from allowed tables.

If an allowed table holds customer emails or phone numbers, the query returns them. Native roles cannot rewrite matched fields in results for sensitive columns like card numbers. Also, if the agent has write grants to fix one bad row, it can update the whole table. Database roles also leave static secrets sitting inside the agent runtime container. If the agent prints its runtime variables, those database credentials leak into chat logs.

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 beside the service as an open-source proxy, a sidecar for your database or API.

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 review. Next, hoop.dev data masking rewrites sensitive fields in responses, and each verdict is logged per listener. Explore the MIT-licensed project on GitHub.

Frequently asked questions

Should OpenHands share a CockroachDB role with human developers?

No, you should always create a separate role just for the AI agent. Separate roles keep audit logs clear and let you revoke agent rights fast.

Can CockroachDB roles stop an agent from reading customer phone numbers?

Native roles block whole tables or columns, not specific text patterns in results. To keep access while hiding phone numbers or national IDs, you need data masking.

What grants does OpenHands need for basic query debugging?

For basic debugging, the agent only needs read grants on the target tables. It can run select queries and check query plans without any write permissions.

The query runs. The emails stay hidden.