使用受IAP保护的应用对Google Composer http通话任务进行身份验证

时间:2019-07-10 07:34:11

标签: airflow google-cloud-composer google-iam google-iap

我有一个设置,其中有一个应用程序引擎REST应用程序和一个Google Composer / airflow DAG,其任务是从应用程序的其中一个端点获取数据。该应用受IAP保护。我已将运行Airflow的服务帐户添加到“ IAP安全的Web应用程序用户”列表中,但是,每当该步骤执行对http调用的响应时,便是Google登录页面。知道是否需要任何其他步骤?

我的DAG步骤的代码:

def get_data():
    r = requests.get(url="url-to-my-app-endpoint>")
    print('stuff:')
    print(r.status_code)
    print(r.content)
    return 1

# ...

python_fetch_data = PythonOperator(
    task_id='python_fetch_data',
    python_callable=get_data,
    dag=dag,
    depends_on_past=True,
    priority_weight=2
)

1 个答案:

答案 0 :(得分:0)

Durable Functions说明了如何扩展DAG代码,以便它将凭据发送到受IAP保护的API后端。

背景知识:由于Composer是在GCP之上构建的,因此您的Composer部署具有一个唯一的https://cloud.google.com/iap/docs/authentication-howto#authenticating_from_a_service_account身份作为其运行身份。您可以将该服务帐户添加到端点的IAP访问列表中。

我不知道Composer UI是否可以很容易地看到您的服务帐户的“电子邮件”地址,但是如果您在上面添加了代码并生成了service account,就会显示出来。