BigQuery error · Permissions and access
Permission denied while getting Drive credentials
A query touched a Google Sheets or Drive external table, and the credentials running it can't read the file in Drive: either they lack the Drive OAuth scope or the file isn't shared with that identity. Share the Sheet with the user or service account and authenticate with the Drive scope.
The error message
Access Denied: BigQuery BigQuery: Permission denied while getting Drive credentials.
Causes
Credentials without the Drive OAuth scope
Drive-backed tables need the https://www.googleapis.com/auth/drive scope in addition to BigQuery's. Default gcloud auth login, plain Application Default Credentials, and many service account setups in Airflow, Cloud Run or notebooks don't request it.
The Sheet isn't shared with the identity running the query
Drive permissions are separate from BigQuery IAM. A dashboard or pipeline service account needs at least view access to the file itself, even when it has full access to the dataset.
Scheduled queries with stale credentials
A scheduled query over a Sheet runs with stored credentials. If they expired or the owner lost access, runs fail with PERMISSION_DENIED: BigQuery: Permission denied while getting Drive credentials.
A view hides the Sheet
Querying a view or model that selects from a Drive external table needs the same Drive access, which makes the error look unrelated to Sheets.
How to fix it
1. Share the file with the service account
In Google Sheets or Drive, share the file with the service account email (for example etl@my-project.iam.gserviceaccount.com) as a viewer.
2. Authenticate with the Drive scope
For the bq tool run gcloud auth login --enable-gdrive-access. For local Application Default Credentials, log in with both scopes: gcloud auth application-default login --scopes=https://www.googleapis.com/auth/drive,https://www.googleapis.com/auth/cloud-platform (Google's docs add --client-id-file with your own OAuth client). In code, request the same scopes when you build the credentials, for example google.auth.default(scopes=[...]) in Python.
3. Update scheduled query credentials
Edit the scheduled query and update its credentials, or have it run as a service account that has access to the Sheet. The BigQuery Data Transfer Service must be enabled for scheduled queries.
4. Copy the Sheet into a native table
Let one scheduled job with Drive access snapshot the Sheet, and point dashboards and pipelines at the native table. Only that job needs Drive credentials, and downstream queries stop depending on Drive.
CREATE OR REPLACE TABLE `my-project.finance.budget_targets` AS
SELECT
CAST(month AS DATE) AS month,
cost_center,
SAFE_CAST(target_usd AS NUMERIC) AS target_usd
FROM `my-project.finance.budget_targets_sheet`;How to prevent it
- Treat Sheets as an input, not a source for live dashboards: snapshot them on a schedule.
- Keep an inventory of Drive external tables and the identities allowed to read them.
- Use a dedicated service account for Sheet imports instead of a person's credentials, which break when they leave.
FAQ
I can open the Sheet in my browser. Why does the query fail?
Your browser session has Drive access, but the credentials BigQuery received may not include the Drive scope, or the query runs as a service account. Both the scope and the file permission must be present for the identity that runs the job.
Does granting BigQuery roles fix it?
No. BigQuery IAM roles don't grant access to Drive files. Share the file and add the Drive scope.
Is the failed query billed?
No. It fails before reading data, and failed queries aren't billed on-demand.
Related
SQL reference
More permissions and access
All BigQuery error messages · What 50M daily events say about BigQuery failures
