【问题标题】:Adding BigQuery connection with gdrive scopes?添加与 gdrive 范围的 BigQuery 连接?
【发布时间】:2018-08-08 19:04:39
【问题描述】:

我有一个外部 Sheets 表,我想通过 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 参数被忽略了一样。

【问题讨论】:

    标签: google-cloud-composer


    【解决方案1】:

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

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

    如果您想在 Cloud Composer 上添加与 GCP 相关的范围,您必须在 create the environment 时这样做。事后不可修改。

    创建环境时,请务必添加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

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

    【讨论】:

    • 非常感谢。我希望我早点找到这个答案
    【解决方案2】:

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

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

    有一步一步的指示here

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

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-20
      • 2017-05-29
      相关资源
      最近更新 更多