This document describes how to use BigQuery Table ACL to control access to tables and views. For an overview of BigQuery Table ACL, see Introduction to table access controls.
After you create a table or view, you can set its policy in the following ways:
- using the Cloud Console
- using the
bq set-iam-policy
command - calling the
tables.setIamPolicy
method
You can use BigQuery Table ACL to set access on both logical views and dataset-level authorized views. A logical view can also reference other source tables and views that you shared using BigQuery Table ACL.
Before you begin
Create the table or view that you want to use with BigQuery Table ACL.
Grant the BigQuery Data Owner (
roles/bigquery.dataOwner
) role or the BigQuery Admin (roles/bigquery.admin
) role to the person that will perform the steps in this topic.For more information about Identity and Access Management (IAM) policies, see Understanding policies and the Policy reference topic.
Creating an access policy
To create an access policy on a table or view:
Console
Open the BigQuery page in the Cloud Console.
In the Explorer panel, select the project.
Select the dataset that contains the table or view.
Select the table or view.
If you are modifying access for a table, click Share table. If you are modifying access for a view, click Share view.
The Table permissions or View permissions page opens. For Add members, enter the email address of the user that will receive access to the table or view.
From the Select a role dropdown, select the role that you want to grant to the user. The following shows granting
joe@example.com
to the BigQuery Data Viewer (roles/bigquery.dataViewer
) role.Click Done.
bq
Retrieve the existing policy to a local file.
bq get-iam-policy \ project-id:dataset.table_or_view \ > policy.json
where:
- project-id is your project ID.
- dataset is the name of the dataset that contains the resource (table or view) that you are updating.
- table_or_view is the name of the resource that you are updating.
More examples of identifying a table or view, and redirecting the policy output to a file:
bq get-iam-policy dataset1.table1 > policy.json
bq get-iam-policy --project_id=project1 -t dataset1.table1 > policy.json
bq get-iam-policy project1:dataset1.table1 > policy.json
If you haven't yet added any members to the policy, the
policy.json
file will contain anetag
value and no other fields. See For more information about how to format thepolicy.json
file, see Understanding policies.To add the first member, add a
bindings
field to the policy. For example, to grant the BigQuery Data Viewer (roles/bigquery.dataViewer
) role tojoe@example.com
:"bindings": [ { "members": [ "user:joe@example.com" ], "role": "roles/bigquery.dataViewer" } ]
If you need to add more members to an existing binding, just add the member. This example shows granting
jane@example.com
the BigQuery Data Viewer (roles/bigquery.dataViewer
) role, for a binding that already exists."members": [ "user:joe@example.com", "user:jane@example.com" ], "role": "roles/bigquery.dataViewer" }
Update the policy.
bq set-iam-policy \ project-id:dataset.table_or_view \ policy.json
For information about IAM policy schema versions, see Policy versions.
API
Call
tables.getIamPolicy
to retrieve the current policy.Edit the policy to add members and/or bindings. See the
bq
example for the format of the policy.Call
tables.setIamPolicy
to write the new policy.
For information about IAM policy schema versions, see Policy versions.
Java
Before trying this sample, follow the Java setup instructions in the BigQuery Quickstart Using Client Libraries. For more information, see the BigQuery Java API reference documentation.
Updating an access policy
To update an access policy on a table or view:
Console
Open the BigQuery page in the Cloud Console.
In the Explorer panel, select the project.
Select the dataset that contains the table or view.
Select the table or view.
If you are modifying access for a table, click Share table. If you are modifying access for view, click Share view.
The Table permissions or View permissions page opens.
If you want to add new members, use the same technique shown in Creating an access policy.
If you want to remove access for a user, search for the user by using the Search members field. For each group where you want to remove the user, expand the group, and then click the Delete
button for the user.If you want to change group membership for a user, make additions and/or deletions as described in the immediate 2 steps above.
Repeat as needed for other users whose access you want to add, modify, or remove. When you are done, click Done.
bq
Retrieve the existing policy to a local file.
bq get-iam-policy --format=prettyjson \ project-id:dataset.table_or_view \ > policy.json
where:
- project-id is your project ID.
- dataset is the name of the dataset that contains the table that you are updating.
- table_or_view is the name of the table or view you are updating.
More examples of identifying a table or view, and redirecting the policy output to a file:
bq get-iam-policy dataset1.table1 > policy.json
bq get-iam-policy --project_id=project1 -t dataset1.table1 > policy.json
bq get-iam-policy project1:dataset1.table1 > policy.json
Modify policy.json as needed.
For more information about how to format the
policy.json
file, see Understanding policies.For information about IAM policy schema versions, see Policy versions.
Update the policy.
bq set-iam-policy \ project-id:dataset.table_or_view \ policy.json
API
Call
tables.getIamPolicy
to retrieve the current policy.Edit the policy to add members and/or bindings.
For the format required for the policy, see the Policy reference topic.
Call
tables.setIamPolicy
to write the updated policy.
Java
Before trying this sample, follow the Java setup instructions in the BigQuery Quickstart Using Client Libraries. For more information, see the BigQuery Java API reference documentation.
For more information about Identity and Access Management policies, see Understanding policies and the Policy reference topic.
What's next
- Read the FAQ.
- Learn about audit logging of BigQuery Table ACL admin activities at Audit logging.