Rupert Schiessl
Rupert Schiessl

Reputation: 829

Permission Denied Error When Accessing Google Drive via BigQuery Service Account

I am encountering a persistent issue when trying to access data stored in Google Drive through a BigQuery external table using a service account. Despite having the Google Drive API enabled, the service account added to the Google Sheet and the service account set up, I keep receiving a permission denied error related to Drive credentials.

Issue Description:

When executing queries from an external application using the service account, I receive the following error:

"Access Denied: BigQuery BigQuery: Permission denied while getting Drive credentials."

This error occurs consistently across different queries attempting to access the external table linked to a Google Shet source.

Steps Taken:

Questions:

Any insights or suggestions from the community would be greatly appreciated, as I've hit a roadblock with this issue.

Upvotes: 0

Views: 1169

Answers (1)

Shakti Rai
Shakti Rai

Reputation: 11

You need to provide scope with the credentials -

Using python bigquery client

SCOPES = [
"https://www.googleapis.com/auth/bigquery",
"https://www.googleapis.com/auth/drive.readonly"]

from google.cloud import bigquery
from google.auth import default
from google.auth.transport.requests import Request

credentials, project = default(scopes=SCOPES)
credentials.refresh(Request())
bq_client = bigquery.Client(credentials=credentials, project=<GCP_PROJECT>)

Using Airflow composer (BigQueryHook)

  • Modify connection configuration (In my case it was default connection i.e google_cloud_default) via Airflow composer web UI's Admin > connections tab to provide scope.

enter image description here

Upvotes: 1

Related Questions