Request a demo

Glossary · Governance and security

What is Row-level security?

Row-level security limits which rows of a table each user can see. In BigQuery you create row access policies: each one grants a filter expression to a list of users or groups, and anyone not covered by any policy sees no rows at all, without an error.

Also called: RLS, row access policy, BigQuery row-level security, CREATE ROW ACCESS POLICY, row-level access control

How it works in BigQuery

A row access policy has a name, a target table, a grantee list and a filter that works like a WHERE clause. A user sees the union of the rows granted to them by every policy they are in. Granting a policy adds the system-managed bigquery.filteredDataViewer role to its grantees; manage that role only through policies, not directly in IAM.

-- Regional sales managers see their region only
CREATE ROW ACCESS POLICY emea_sales
ON `my-project.sales.orders`
GRANT TO ('group:sales-emea@example.com')
FILTER USING (region = 'EMEA');

-- Account managers see only their own accounts
CREATE ROW ACCESS POLICY own_accounts
ON `my-project.sales.orders`
GRANT TO ('domain:example.com')
FILTER USING (account_manager_email = SESSION_USER());

-- Pipelines and admins keep full access
CREATE ROW ACCESS POLICY full_access
ON `my-project.sales.orders`
GRANT TO ('group:data-platform@example.com', 'serviceAccount:etl@my-project.iam.gserviceaccount.com')
FILTER USING (TRUE);

Filters can also use a subquery against a lookup table, for example FILTER USING (region IN (SELECT region FROM security.user_regions WHERE email = SESSION_USER())), so access changes become row updates instead of new policies. Remove policies with DROP ROW ACCESS POLICY, or DROP ALL ROW ACCESS POLICIES for the last one, which can't be dropped individually. Creating and managing policies requires BigQuery Admin or BigQuery Data Owner.

Behavior that surprises people

  • Adding the first policy locks everyone else out. Users who had full access need a TRUE policy.
  • Overwrites drop policies. CREATE OR REPLACE TABLE, loads or queries with WRITE_TRUNCATE, and table copies that overwrite it remove its row access policies. TRUNCATE TABLE keeps them.
  • No pruning from policy filters. Policy predicates don't help partition or cluster pruning, so a user's query still needs its own partition filter.
  • Hidden bytes. total_bytes_billed and total_bytes_processed are empty in the JOBS views for queries that read tables with row access policies, which affects cost attribution.
  • Feature limits. No legacy SQL, no wildcard table queries, no table preview or sampling, no policies on JSON columns or temporary tables, and BI Engine and materialized views don't accelerate such tables. Subquery policies are incompatible with the Storage Read API.

Availability and combinations

Row-level security is available with Enterprise and Enterprise Plus editions and on-demand pricing, not with Standard edition reservations. It combines with column-level access control and data masking: masking applies on top of the row filter, but only with non-subquery policies. Audit logs and the INFORMATION_SCHEMA.ROW_ACCESS_POLICIES view show which policies exist and which were applied to reads.

FAQ

Why does my query on a table with row-level security return no rows?

Once a table has any row access policy, users who aren't in the grantee list of at least one policy see zero rows; BigQuery returns an empty result rather than an error. Add them to a policy, or to a policy with FILTER USING (TRUE) for full access.

Does row-level security cost extra?

There is no charge for the feature, but it can raise query costs: policy filters don't take part in partition and cluster pruning, policies with subqueries read the lookup tables, and some user filters may be applied later than usual.

Row-level security or authorized views?

Authorized views are flexible and fast for sharing a filtered result. Row access policies keep one table and one query path for everyone, which suits dashboards used by people with different scopes. Google recommends separate tables when even the number of rows must stay secret.

Read next

Browse the full glossary

Observability for every BigQuery table, in about 15 minutes

Masthead detects freshness, volume and schema anomalies, monitors pipeline errors and maps column-level lineage across all your projects, from logs and metadata only.