使用 gdrive 范围添加 BigQuery 连接?

rxs*_*bjw 2 google-cloud-composer

我有一个外部表格表,我想通过 Airflow 中的 BigQueryOperator 进行查询。

我更愿意使用 Cloud Composer 服务帐户。

我通过 Airflow UI 使用以下参数创建了一个新连接:

Conn Id: bigquery_with_gdrive_scope
Conn Type: google_cloud_platform
Project Id: <my project id>
Keyfile path: <none>
Keyfile JSON: <none>
Scopes: https://www.googleapis.com/auth/bigquery,https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/drive
Run Code Online (Sandbox Code Playgroud)

在我的 DAG 中,我使用: BigQueryOperator(..., bigquery_conn_id='bigquery_with_gdrive_scope')

日志报告: Access Denied: BigQuery BigQuery: No OAuth token with Google Drive scope was found.

任务属性显示: bigquery_conn_id bigquery_with_gdrive_scope

就好像bigquery_conn_id参数被忽略了一样。

小智 6

添加 GCP API 范围(如已接受的答案)对我们不起作用。经过大量调试后,似乎 GCP 具有在创建期间分配给环境的“根”范围,并且无法通过 Airflow Connections 覆盖。这似乎只影响 GCP API 范围。

作为参考,我们正在使用composer 1.4.0airflow 1.10.0

如果您想在 Cloud Composer 上添加与 GCP 相关的范围,您必须在创建环境时这样做。事后无法修改。

创建环境时,请务必添加https://www.googleapis.com/auth/drive. 具体来说,您可以将以下标志添加到您的gcloud composer environment create命令中:

--oauth-scopes=https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/drive

最后,不要忘记与服务帐户电子邮件共享文档(除非您已授予服务帐户域范围的访问权限)