How to Configure Mastra Bigquery Credentials

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up mastra bigquery credentials by linking a Google Cloud service account to your agent. Your agent then uses this identity to run data queries in your warehouse. Most teams start by making a shared key file for the app. They load this key into the runtime host so the agent can read tables. When teams pick broad project roles, the agent gains access to every dataset. A bad prompt can then pull private rows or rack up high query costs. How mastra bigquery credentials work in practice A

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 credentials by linking a Google Cloud service account to your agent. Your agent then uses this identity to run data queries in your warehouse. Most teams start by making a shared key file for the app. They load this key into the runtime host so the agent can read tables. When teams pick broad project roles, the agent gains access to every dataset. A bad prompt can then pull private rows or rack up high query costs.

How mastra bigquery credentials work in practice

A Mastra agent needs two main things from Google Cloud to run queries. First, it needs a valid identity, such as a service account or workload identity. Second, that identity needs a role that allows running jobs and reading tables. When the agent runs a tool, the client library reads the local key settings. It trades those secrets for a short token from the cloud auth server. The agent then sends the SQL text and the token to the data API. Google Cloud checks if the role allows the job to start on that project. It also checks if the role can read the target dataset and table. Teams can use workload identity on cloud hosts instead of static JSON key files. This method binds the app container to a cloud service account without saving files. Both paths give the agent a fixed set of permissions for every single query.

What native roles solve and where they fall short

Google Cloud roles do a great job of blocking outside users from your warehouse. You can Scope a service account to one dataset or a few specific tables. You can also turn on cloud audit logs to see which service account ran a job. Still, cloud roles only check who logs in to the database API. They do not inspect what individual SQL statements do while the query is in flight. Every user who talks to the Mastra agent shares the exact same service account. The warehouse logs show the agent identity, not the human who asked the question. If a table holds emails, phone numbers, or card numbers, the query returns them. You have to build extra views or tags for each table to hide fields. Native roles also cannot pause a single drop or delete query for human review. Once the role has write access, any query from the agent runs right away.

Steps to tighten native service account access

Start by making a separate service account just for your Mastra agent workloads. Never reuse a default compute account or an admin key from another app. Grant the job user role at the project level so the agent can run queries. Then grant the data viewer role only on the specific datasets the agent needs. Avoid giving project-wide data viewer or editor roles to an automated agent. Set a maximum bytes billed limit on your query jobs to stop huge scans. Rotate any exported key files on a set schedule, or switch to workload identity. Review your cloud audit logs each week to spot strange table scans early.

Ephemeral Credentials + BigQuery IAM: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.

First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

Should I use a JSON key file or workload identity for my agent?

Use workload identity whenever your Mastra app runs on a supported cloud host. It removes the need to store, copy, or rotate static key files on disk. Use a JSON key file only for local testing on a developer laptop.

What is the minimum role needed to run read queries?

The service account needs permissions to create query jobs and read table rows. In Google Cloud, you assign a job runner role and a dataset viewer role. Grant the viewer role on single tables rather than the whole project.

How do I stop an agent from reading private columns like emails?

With native tools, you must set up policy tags or authorized views beforehand. Alternatively, runtime data masking rewrites emails, phone numbers, and card numbers in query results.

The query runs. The emails stay hidden.