2

我有一个外部表格表,我想通过 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

在我的 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参数被忽略了一样。

4

2 回答 2

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

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

于 2019-01-30T03:43:24.840 回答
3

如果有人遇到同样的问题,(Composer 1.0.0,Airflow 1.9.0)会退回到gcloud auth除非Keyfile pathKeyfile json提供。这将忽略任何范围参数。

Airflow 的主分支修复了这个问题;但是现在您必须为服务帐户生成一个凭据文件并告诉 Airflow 这些文件的位置。

这里有分步说​​明。

对于我的用例,我为气流的服务帐户创建了一个密钥并设置了如下连接:

Conn Id: bigquery_with_gdrive_scope
Conn Type: google_cloud_platform
Project Id: <my project id>
Keyfile path: <none>
Keyfile JSON: <contents of keyfile for airflow service account>
Scopes: https://www.googleapis.com/auth/bigquery,https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/drive
于 2018-08-08T19:35:18.633 回答