Take control of your releases with a free, instant demo.

Launch Now

BigQuery lets you restrict what different users see inside a sensitive column without copying the table or wrapping it in a view. The data stays where it is. What changes is the value a given user gets back when they run a query. This post walks through the policy tag workflow, from the taxonomy that organizes your sensitive columns down to the IAM roles that determine who sees the original values and who sees masked values.

What Is BigQuery Data Masking?

BigQuery data masking is a column-level access control mechanism that changes what users see when they query sensitive columns. Depending on their permissions, BigQuery can return the original value, substitute a masked value such as NULL, a hash, or a default, or deny access to the column.

In the policy tag workflow, two roles determine what a user sees. The BigQuery Masked Reader role lets a user see masked output. The Data Catalog Fine-Grained Reader role lets a user see the original value. Users still need the underlying permissions to query the table.

The underlying value stays unchanged in the table. The same SELECT statement can return different results depending on who runs it.

Build yourself a test data management plan.

Benefits of BigQuery Data Masking

The appeal of masking is that it solves an access problem without creating a data management problem.

  1. No duplicate tables. You can keep a single table for users with different levels of access.
  2. No custom views. You can apply the access rule to the column itself and avoid maintaining separate views for each audience.
  3. Enforcement at query time. BigQuery applies masking when a query runs against the table.
  4. Role-based access. Different users can query the same table and receive different results based on their permissions.

For example, a support team can query the same customer table as an analytics team while each group sees only the level of detail it needs.

The BigQuery Data Masking Workflow

Four pieces work together in a policy tag setup.

Taxonomies and policy tags come first. A taxonomy is a hierarchy of sensitivity labels. The policy tags inside it are what you attach to columns to identify personally identifiable information (PII), financial data, or other sensitive fields.

Data policies come next. A data policy associates a masking rule with a policy tag and determines what masked output BigQuery produces.

Then you apply the policy tags to columns. A tagged column is governed by the data policies associated with its tag.

Finally, IAM roles determine what users see. Grant Fine-Grained Reader access on the policy tag to users who need the original values. Grant Masked Reader access on the data policy to users who need masked values. BigQuery also supports assigning a data policy directly to a column. The steps below cover the policy tag approach.

How to Set Up Data Masking in BigQuery

Step 1. Create a Taxonomy and Policy Tags

A taxonomy is a hierarchy of sensitivity labels that you define once and reuse across tables. Inside it, policy tags are the individual labels you’ll apply to columns, such as a tag for email addresses nested under a broader PII group.

Create a taxonomy in the Policy tag taxonomies area of the Google Cloud console or through the API. Give the taxonomy a name, then add and nest policy tags to match your sensitivity categories. Create the taxonomy in the same location as the BigQuery tables you plan to tag.

To create and manage taxonomies, use the Data Catalog Policy Tag Admin role (roles/datacatalog.categoryAdmin). Plan the hierarchy before you build it, because permissions granted on parent tags can affect access to the tags beneath them.

Step 2. Create Data Policies

A data policy binds a masking rule to a policy tag. A tag can identify a sensitive column on its own. It needs a masking policy to produce masked output.

In the console, select the policy tag and choose Manage Data Policies to add a policy and select a rule. Three built-in rules are useful starting points. Nullify returns NULL. Default value returns a fixed placeholder appropriate to the column’s data type. SHA-256 returns a deterministic hash for supported types. BigQuery also offers other built-in rules and supports custom masking routines.

Choose Nullify when the masked audience has no need for the field. Choose Default value when a query needs a non-null placeholder to keep working. Consider SHA-256 when masked users need to match values across rows or tables. Someone can hash likely inputs and compare the results, so consider whether a deterministic hash provides enough protection for predictable values.

The BigQuery Data Policy Admin, BigQuery Admin, and BigQuery Data Owner roles include the permissions to create and manage data policies.

Step 3. Apply Policy Tags to Columns

With tags and data policies in place, attach a policy tag to the columns you want to protect. In the console, edit the table schema and assign the tag to a field. You can also use the bq CLI or the API.

Creating a masking data policy for a tag enables access control automatically. Once you apply that tag to a column, BigQuery evaluates access when users query the column.

Step 4. Assign IAM Roles

Grant the Data Catalog Fine-Grained Reader role on the policy tag to users or groups who need the original value. Grant the BigQuery Masked Reader role on the data policy to users or groups who should see the masked value. Assigning Masked Reader at the data policy level keeps the grant scoped to that policy.

A user who has access to the table but holds neither applicable role receives an access error when a query references the protected column. Because policy tags sit in a hierarchy, grants on a parent tag can affect access to columns tagged with its children. Check inherited access when testing the setup.

Step 5. Verify the Results

Suppose you tag customer_email and apply a Nullify policy for an analyst group. Run the same query against a table with sample data using three test identities. Give all three the underlying table access they need.

  1. A Fine-Grained Reader should see the original email address.
  2. A Masked Reader should see NULL.
  3. An identity with neither column-access role should receive an error when selecting customer_email.

Turn off cached results during the test, especially if you’ve just changed someone’s access.

Masking Rules Compared

These three rules differ in what they return and how the masked column behaves in a query. If masked users need to join on a protected field, check that the rule preserves the matches they expect.

Rule What the Masked User Sees Best Use Case Behavior in Joins
Nullify NULL Masked users don’t need the field Ordinary equality joins don’t match NULL values
Default value A type-appropriate placeholder A query needs a non-null value The shared placeholder can create false matches
SHA-256 A deterministic hash of the original value Masked users need to match values across rows or tables The same input produces the same hash under the same rule. Collisions are theoretically possible but negligible in practice

Restrictions and Limitations to Know

Data masking affects some BigQuery features differently. Check how your queries use the column before you tag it.

  1. Materialized views. An existing materialized view can cause masked queries on repeated records in the associated base table to fail.
  2. Wildcard table queries. Users need full access to every referenced column across the matching tables.
  3. Partitioned and clustered columns. Queries that apply masking to a partitioning or clustering column are unsupported.
  4. Query caching. After a user moves from unmasked to masked access, a repeated query can still return previously cached unmasked results.

Time travel works with masking. BigQuery applies the current schema’s policy tags to the historical data it retrieves. For the full set of restrictions, see Google Cloud’s data masking documentation.

When BigQuery Data Masking Isn’t Enough

BigQuery masking governs what users see when they query sensitive columns. That works well for restricting access to live data. Dev, test, and staging teams may also need masked or synthetic data, or test data that needs to be managed as a governed asset across a broader stack.

When teams need test data across multiple systems, a dedicated test data management platform can help them find sensitive fields, apply consistent masking rules, and validate the resulting datasets before they reach non-production environments.

 

Evaluate Now