How to Configure Mastra Bigquery Read Only Access

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up mastra bigquery read only access with a restricted Google Cloud service account. You give that account roles that let the agent run queries and read table data. Many teams start by using a broad admin key to get their agent working fast. That shortcut creates huge risk if a bad prompt makes the agent delete or change tables. Using a read-only role stops the agent from changing data, though it still reads every row by default. How to set up mastra bigquery read only access First, yo

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 bigquery read only access with a restricted Google Cloud service account. You give that account roles that let the agent run queries and read table data. Many teams start by using a broad admin key to get their agent working fast. That shortcut creates huge risk if a bad prompt makes the agent delete or change tables. Using a read-only role stops the agent from changing data, though it still reads every row by default.

How to set up mastra bigquery read only access

First, you create a dedicated service account in your cloud project for the Mastra agent. Never share this identity with other apps or human team members on your staff. A dedicated identity keeps your audit logs clean and makes permission changes safe.

Next, you assign two basic permissions to that new service account in your cloud project. The agent needs permission to start query jobs and permission to read dataset tables. If you grant viewer access at the project level, the agent sees every dataset. Instead, grant table read permissions only on the specific datasets the agent needs to use.

Finally, you pass those credentials to the Mastra tool or workflow that runs the queries. Workload identity is safer than downloading a static key file to your server disk. Static keys can leak in code repos, build logs, or local developer laptops. Once linked, the Mastra agent can inspect schemas and run select queries on your tables.

What native cloud roles solve and what they miss

Native cloud roles do a great job of blocking write commands at the database level. If the Mastra agent tries to drop a table or insert rows, BigQuery blocks it. This setup protects your core analytics tables from accidental changes or bad agent prompts.

Still, cloud roles only check who logs in and which whole tables they can read. They do not inspect the actual query text or filter the results in flight. If an allowed table holds customer emails, phone numbers, or card numbers, the agent gets them. Data masking is needed to rewrite matched fields in results before the agent uses them.

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.

Cloud roles also cannot stop an agent from running a massive, expensive full table scan. A single bad prompt can trigger a query that reads terabytes of warehouse data. Native limits can cap daily usage, but they lack context about which prompt caused the spike. Teams also struggle to tie a specific database log back to the exact agent user.

Managing credentials and query safety for AI agents

When you run Mastra in production, static service account keys become a burden to rotate. Every team member who builds or tests the agent often ends up with a copy. If a key leaks, an attacker gets the exact same read access as your agent.

Even with workload identity, the agent process holds direct permission to query the allowed datasets. There is no human approval step when an agent decides to query a sensitive table. Teams need a way to inspect queries, rewrite sensitive fields, and log agent actions clearly.

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

Why does my Mastra agent fail to query BigQuery with a viewer role?

Data viewer roles only let the account read table rows, not run query jobs. You must also grant a role that allows creating and running jobs in the project.

Can BigQuery IAM roles hide specific columns like emails or phone numbers?

Standard dataset roles apply to whole tables, so the agent reads every column by default. Hiding specific fields requires separate column policy tags or a tool that masks query results.

How do I stop a Mastra agent from running huge BigQuery scans?

You can set a maximum bytes billed limit on the query job or project settings. This setting cancels any query that tries to scan more data than your set limit.

The query runs. The emails stay hidden.