How to Configure AutoGen CockroachDB Read Only Access
You set up autogen cockroachdb read only access by creating a restricted database role. You then pass those database keys to the SQL tool of your agent. Many teams start by giving agents the same broad database login that their main app uses. When an AI agent holds write permissions, a bad prompt can alter rows or drop tables. Limiting the database role to read actions stops the agent from changing data. How to set up autogen cockroachdb read only access AutoGen agents interact with databases
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 autogen cockroachdb read only access by creating a restricted database role. You then pass those database keys to the SQL tool of your agent. Many teams start by giving agents the same broad database login that their main app uses. When an AI agent holds write permissions, a bad prompt can alter rows or drop tables. Limiting the database role to read actions stops the agent from changing data.
How to set up autogen cockroachdb read only access
AutoGen agents interact with databases through custom Python functions registered as agent tools. When an agent needs data, it writes a query and runs the Python function. That function opens a session to CockroachDB using a standard PostgreSQL driver. The database checks the role of the user before it runs the query.
To lock this down, an admin creates a dedicated user inside CockroachDB. The admin grants this user select permissions on specific schemas or tables. The admin also revokes any default rights to create, update, or delete records. Next, the team puts the new user credentials into the host system where the agent runs. The agent reads these values from local variables and logs in with read privileges.
Where native database roles fall short for AI agents
Database roles control who logs in and which tables they can read. They do not inspect what individual queries do while they run in flight. A read role still allows an agent to pull every row from a customer table by default. If that table holds emails, phone numbers, or card numbers, the agent gets them all. Those sensitive values then travel straight to the external language model provider in the prompt context.
Static database credentials also create key management work for the engineering team. The host running the AutoGen worker must store the password or certificate in plain text. If an agent has a code execution tool, a prompt trick might read those local variables. Native database logs also group all agent actions under one shared service account name. When ten different users trigger the agent, the database log shows only one generic user.
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.
Protecting sensitive data and queries in flight
Safe agent setups need controls that work at the query and column level. First, teams should limit which tables the read role can see in the database. Rather than granting read rights across a whole schema, pick only the safe tables. You can also build database views that leave out columns with national IDs or emails.
Teams also need to watch out for heavy queries that slow down the cluster. AI agents often write bad joins or forget to add row limits to queries. Setting statement timeouts on the database role kills long queries before they hurt production traffic. Even with timeouts and views, maintaining separate database views for every agent task takes ongoing work.
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
Can an AutoGen agent change data if it has a read role?
No, CockroachDB blocks insert, update, and delete statements when the user role only has select rights. The database returns a permission error to the agent tool instead of changing the table.
Why do read roles still expose sensitive data to language models?
A read role lets the agent run select queries on allowed tables. If those tables contain phone numbers or card numbers, the query returns them to the model.
How can teams stop AI agents from running slow database queries?
Admins can set a statement timeout on the specific CockroachDB role used by the agent. If an agent runs a full table scan that takes too long, the database cancels it.
Related guides
In this post