google-big-queryHow do I set up IAM permissions for Google BigQuery?
To set up IAM permissions for Google BigQuery, you first need to create a service account and grant it the necessary permissions.
-
Create a service account in the Google Cloud Console.
-
Grant the service account the necessary IAM roles for BigQuery. For example, to grant a service account the BigQuery Data Viewer role, use the following command:
gcloud projects add-iam-policy-binding PROJECT_ID \
--member serviceAccount:SERVICE_ACCOUNT_EMAIL --role roles/bigquery.dataViewer
- For each dataset, grant the service account the necessary BigQuery permissions. For example, to grant a service account the BigQuery Data Viewer role for a dataset, use the following command:
bq show --format=prettyjson --transfer_config PROJECT_ID:DATASET
The output should look like this:
{
"destinationDataset": {
"datasetId": "DATASET_ID",
"projectId": "PROJECT_ID"
},
"name": "projects/PROJECT_ID/locations/US/transferConfigs/DATASET",
"params": {
"destination_dataset_id": "DATASET_ID"
},
"schedule": "every 24 hours",
"state": "ENABLED",
"updateTime": "2020-03-06T18:39:00.902Z"
}
- Add the service account to the dataset's access list with the following command:
bq update --transfer_config PROJECT_ID:DATASET \
--access_filter="(role:READER AND serviceAccount:SERVICE_ACCOUNT_EMAIL)"
- Verify that the service account is added to the dataset's access list with the following command:
bq show --format=prettyjson --transfer_config PROJECT_ID:DATASET
The output should look like this:
{
"destinationDataset": {
"datasetId": "DATASET_ID",
"projectId": "PROJECT_ID"
},
"name": "projects/PROJECT_ID/locations/US/transferConfigs/DATASET",
"params": {
"destination_dataset_id": "DATASET_ID"
},
"schedule": "every 24 hours",
"state": "ENABLED",
"updateTime": "2020-03-06T18:39:00.902Z",
"access": [
{
"role": "READER",
"serviceAccount": "SERVICE_ACCOUNT_EMAIL"
}
]
}
The service account now has the necessary permissions to access the BigQuery dataset.
More of Google Big Query
- How can I use Google BigQuery to retrieve data from a specific year?
- How can I use Google Big Query to integrate with Zephyr?
- How do I use the YEAR function in Google BigQuery?
- How do I use Google Big Query with Excel?
- How can I export data from Google Big Query to an XLSX file?
- How can I use Google Big Query to process XML data?
- How can I use the CASE WHEN statement in Google Big Query?
- How do I use wildcards in Google BigQuery?
- How can I compare Google BigQuery and AWS Redshift for software development?
- How do Google BigQuery and Hadoop compare in terms of performance and scalability?
See more codes...