How to Configure Mastra CockroachDB Read Only Access

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up mastra cockroachdb read only access by creating a restricted database role. Next, you pass those read-only login keys to your Mastra agent workflow. Many engineering teams rush this step during early agent testing. They often reuse admin database keys to get the app running fast. Broad permissions let an AI agent alter or delete production tables by mistake. A small prompt error can wipe out vital customer records in seconds. How to set up mastra cockroachdb read only access First,

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 mastra cockroachdb read only access by creating a restricted database role. Next, you pass those read-only login keys to your Mastra agent workflow. Many engineering teams rush this step during early agent testing. They often reuse admin database keys to get the app running fast. Broad permissions let an AI agent alter or delete production tables by mistake. A small prompt error can wipe out vital customer records in seconds.

How to set up mastra cockroachdb read only access

First, you need a dedicated database user inside your CockroachDB cluster. Database admins create a custom role that only holds select privileges. This role must never receive insert, update, drop, or delete rights. You apply these read rules across the target schemas and tables. You also set default privileges so future tables follow the same rule. This step stops the database user from changing any stored records.

Next, you wire this restricted user into your Mastra project setup. Mastra agents use tools and workflows to query external data sources. You store the read-only connection string inside your app secret store. The Mastra database tool reads this string when it starts a task. When the agent runs a query, CockroachDB checks the role permissions first. The database runs select queries and blocks any write statements right away.

Why database roles alone leave gaps in AI workflows

Native database roles solve the big problem of unwanted data changes. Your Mastra agent cannot drop tables or alter billing rows anymore. Still, role checks only decide who logs in and what commands run. A read-only role still lets the agent read every single column. Customer tables often hold emails, phone numbers, card numbers, and national IDs. The database sends all these raw fields back to the Mastra workflow.

Once the agent reads those rows, the data enters the model context. External language models process those sensitive fields to build a final answer. Static roles also force you to store long-lived passwords in your app. If a bad actor steals that key, they can read all data. Also, standard database logs only show the shared app user name. Security teams cannot tell which specific user or agent ran a query. You also cannot block a slow query that scans millions of rows.

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.

What to check before moving Mastra agents to production

Before going live, review every table your read-only role can reach. Remove select rights from internal system tables and secret auth schemas. Give the Mastra role access only to the exact tables it needs. Set statement timeouts in CockroachDB so bad queries do not lock nodes. Test your agent with tricky prompts that try to write new data. Make sure the database rejects those commands and logs the failed attempts. Finally, plan how you will hide sensitive fields in query results.

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 runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values 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

Can a Mastra agent still slow down CockroachDB with read-only keys?

Yes, a read-only role can still run heavy joins and full scans. You should set query timeouts and row limits on the database role.

Does CockroachDB read-only access hide sensitive columns from Mastra?

No, standard select grants return every column in the allowed table by default. Without field masking, the agent receives raw emails, phone numbers, and card numbers.

How do we rotate the CockroachDB password used by Mastra?

With static keys, you must create a new user password in CockroachDB. Then you update the secret in your Mastra host and restart it.

The query runs. The emails stay hidden.