How to Configure Dify Bigquery Least Privilege

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up dify bigquery least privilege by making a custom service account. You give this account read rights only on specific datasets and tables. Teams often rush this step when they build new AI workflows. They attach broad project roles to get a quick prototype running. Broad roles let an AI agent read every table or drop production data. A single bad prompt can then expose private records or break tables. How to set up dify bigquery least privilege roles Start by making a new service ac

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 dify bigquery least privilege by making a custom service account. You give this account read rights only on specific datasets and tables. Teams often rush this step when they build new AI workflows. They attach broad project roles to get a quick prototype running. Broad roles let an AI agent read every table or drop production data. A single bad prompt can then expose private records or break tables.

How to set up dify bigquery least privilege roles

Start by making a new service account in your cloud console. Do not use the default compute service account for your AI app. The default account holds wide rights across your whole cloud project. Next, split your permissions into two parts: running jobs and reading data. Your AI agent needs a role that lets it start a query job. Assign that job role at the project level so the app can run queries. Do not grant data reading rights at the project level. Instead, open the exact dataset or table the AI workflow needs. Grant data viewer rights to the service account on that single table. If the agent only needs a few columns, make an authorized view. An authorized view lets the agent query a filtered slice of the table. The service account does not need read rights on the base table. Finally, generate the account credential and add it to your Dify tool settings. Test the workflow with a simple read query to check the setup.

What native cloud roles solve and what they miss

Native cloud roles do a great job of blocking unauthorized logins. They stop the Dify app from touching tables outside its assigned scope. They also block the service account from deleting tables or changing schemas. Still, cloud roles only check who logs in and which table they touch. They do not inspect the actual SQL statement while it runs in flight. Once a table is open to the service account, every row is open. An AI agent can still run a massive scan that drives up costs. It can also pull sensitive columns that live inside that allowed table. If that table holds emails, phone numbers, or card numbers, the model gets them. Native roles cannot rewrite matched fields in results on the fly. You have to build and keep up dozens of custom views by hand. Also, shared service accounts make it hard to trace which user triggered a query. Every query in the cloud log just shows the same service account name.

How to keep narrow roles easy to manage

Security teams need to pair narrow cloud roles with strict query habits. Start by setting query size limits on your cloud project or user group. This stops a rogue AI loop from scanning terabytes of warehouse data. Next, review your service account keys and rotate them on a set schedule. Remove old keys right away so leaked credentials cannot open your warehouse. Audit your dataset rules every month to remove tables the app no longer uses. Keep production customer tables in a separate project from your AI test data. When you separate projects, a mistake in one role will not expose everything. Clear boundaries help your team move fast while keeping data safe.

Least Privilege Principle + BigQuery IAM: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

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 should Dify use a separate service account for each workflow?

Separate accounts keep each AI agent inside its own small data boundary. If one workflow needs sales data, it cannot read human resources tables. This setup limits the damage if a user tricks a single prompt.

Can BigQuery roles hide emails or card numbers inside an allowed table?

Standard table roles grant read rights to the whole table at once. To restrict specific columns or rows, you must set up extra policy tags or views. Otherwise, any query on that table returns the raw emails and card numbers.

How do we stop an AI agent from running expensive queries?

You can set a maximum bytes billed limit on the query job. If the AI agent writes a huge scan, the database blocks the query. This protects your cloud budget before the query runs.

The query runs. The emails stay hidden.