Skip to main content
← Back to Patterns

BigQuery tenant access starts with the query identity

By Ivan Richter LinkedIn

Last updated:

7 min read

In brief

Choose tenant isolation from the identity BigQuery sees on the report's query.

  • Use tenant-scoped datasets and accounts for external customers. A shared account leaves authorization to the application.
  • Test cross-tenant reads and cached results through the same path customers use.
On this page

A customer opens a report and sees only their orders. That shows the normal request selected the intended rows.

What happens when the application selects another customer, omits a predicate, or reuses someone else’s result is still untested.

For external tenant data, we’d start with a tenant dataset and a service account limited to that tenant’s surface. For internal teams querying a shared table under their own identities, BigQuery row policies can be a reasonable fit. A shared application account can also work. The application then owns the distinction between its users. BigQuery can’t recover an end-user identity that the caller never sent as an authenticated principal.

Observe the identity at the warehouse

In a controlled test, run this through the same connector or backend path that serves the report:

SELECT SESSION_USER() AS query_principal;

SESSION_USER() returns the executing user’s email address or, for a third-party identity, its principal identifier. Record that value alongside the authenticated application user, resolved tenant, job project, and requested data object. Repeat with two users from different tenants.

Suppose Maya belongs to tenant 17 and Leon to tenant 42. Both requests produce report-reader@app-project.iam.gserviceaccount.com. A row policy that compares a column with SESSION_USER() sees the same principal twice. Mapping that principal to tenant 17 gives both requests the tenant-17 slice. Giving it both tenants makes both slices available to either request’s SQL.

Data Studio can query with a credential owner’s authorization, an individual viewer’s credentials, or a service account. Check the configured path and the resulting job to see which identity reaches the warehouse.

A product can also enforce a viewer restriction before sending the query, as Data Studio’s email filtering does. That may be an intentional access design, but it places trust in the product’s filtering and editing controls. The viewer-email parameter is a value the product chose to send. SESSION_USER() is the principal BigQuery authenticated.

External tenants deserve a smaller readable surface

For shared SaaS infrastructure, Google recommends dedicated tenant datasets and tenant-scoped service accounts. Row policies are recommended within an organization, because observations such as timing and billing can leak information.

We’d follow that distinction when customers can explore data independently.

For tenant 17, the readable dataset contains tenant 17’s approved tables. The tenant’s query identity has no read grant on tenant 42’s dataset or the combined internal warehouse. Grant job execution separately in the intended execution project. A missing tenant predicate can now expose extra rows within tenant 17’s approved dataset, but the query still can’t read tenant 42’s table.

Dataset separation still depends on correct placement. The publishing pipeline must reject a tenant-42 row in tenant 17’s output.

It also needs a defined rule for shared reference data and for users who legitimately represent more than one tenant. If those rules exist only in a naming convention, the data can be wrong before the permission check starts.

Use a trusted server-side mapping from the authenticated tenant to the dataset and query identity. A request field containing a dataset name or service-account email mustn’t choose its own privilege. Where one backend can impersonate every tenant account, the narrower accounts limit each submitted query. That backend remains trusted across all tenants.

A fixed authorized view can be a smaller alternative when maintaining a physical subset would add an unnecessary refresh process. The consumer gets access to the approved view and no direct source-table grant. Keep its SQL and editors controlled. Choose separate physical tables when shared-source inference, independent retention, or administrative separation rules out a view.

A separate project per customer is worth it for a tenant with dedicated infrastructure or a separate administrative requirement, but dataset permissions don’t need one. The decision should name what the project isolates that the dataset doesn’t. Evaluate a service perimeter when the requirement concerns where supported API operations can move the data.

Internal row policies depend on all applicable grants

For internal readers, a row policy can use a known group and a fixed tenant predicate, or compare the executing identity with an approved mapping. The reader still needs table access in addition to a place on the policy’s grantee list.

Inspect every policy that applies to a principal. BigQuery combines their allowed rows: a tenant-17 policy plus a tenant-42 policy allows both tenants. Adding a narrower policy doesn’t subtract the broader grant.

A maintenance policy with FILTER USING (TRUE) allows every row. Keep that identity away from interactive tenant-serving requests.

Manage the Filtered Data Viewer role through row policies instead of granting it directly at a broad IAM scope. Keep filtered readers out of table-writing and policy-management roles. Otherwise the same person may be able to change the rows or the rule meant to constrain them. When replacing policies, don’t leave a readable table with no row policies during the transition.

Row security is unavailable in the Standard edition, so check the reservation assignment the workload uses before designing around it.

A shared account makes the application an authorization service

Sometimes an internal application already owns authentication and exposes a small set of aggregate reports. Splitting every query identity may then cost more operating work than it removes. Keeping a shared account can be defensible if the organization has chosen to trust the application to decide which data each user receives.

Resolve tenant membership from authenticated server-side state, bind the query parameter from that decision, and allow only the reviewed query shapes. The client can request a date range. It can’t promote itself to another tenant by changing a hidden form field. If a query legitimately spans several tenants, authorize that exact set before building the request.

An application defect that removes the tenant predicate can use all data readable by the shared account. A row policy giving that account every supported tenant adds no second, independent tenant check.

Decide whether that failure scope is acceptable. If it isn’t, narrow the data surface or identity before adding more application conditions.

Apply the same ownership to background work.

A report job needs the tenant decision saved with its request. The result downloader must authorize access to that job’s output. Knowing an artifact’s identifier isn’t enough to fetch it.

A cache keyed only by SQL and the shared service account can also mix audiences. Include the effective tenant scope and authorization version in the application’s cache key, or don’t share those results.

Test the requests that should fail

Use synthetic tenants with unmistakable rows and fixed expected identifiers. Include Maya’s allowed tenant-17 row, Leon’s tenant-42 row, and a user with no tenant membership. Run the cases through the serving path as well as any direct warehouse access the reader gets. Record failures too: an empty chart looks the same whether the request was denied or the query selected nothing.

TestRequired observation
Normal tenant-17 requestExpected tenant-17 rows appear
Tenant-17 user submits tenant 42’s identifierRejected or constrained to the authorized tenant
Query omits its normal tenant predicateWarehouse boundary still limits rows, or the application refuses that query shape
Principal gains a second applicable row policyTest detects the expanded readable set
Tenant-17 user requests tenant 42’s saved job or cache entryNo tenant-42 output is delivered
Former tenant member starts a fresh requestNo newly authorized access through an old mapping

Record the observed principal and data object for each result. Test as the intended user, or through an approved impersonation test with the exact service account, because an administrator can read what a restricted reader can’t. Keep the forbidden-row assertion independent of what the UI happens to display.

BigQuery doesn’t reuse query-result cache entries for queries against tables protected by row policies. That rule doesn’t reach a report extract, an application cache, or a downloaded file. Test those delivery paths separately.

An extract job exports the rows visible to its executing principal, and a copied table has its own continuing policy state. Once delivered by either route, data no longer follows changes to the source policy.

Rerun the same cases before changing a connector, adding a report worker, or broadening a support account. Keep the expected principal and the forbidden tenant rows in the acceptance criteria for any authentication change.

More in this domain: Data

Browse all

Related patterns