airflow - 使用受 IAP 保护的应用程序验证 Google Composer http 调用任务
问题描述
我有一个设置,我有一个应用程序引擎 REST 应用程序和一个 Google 作曲家/气流 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
)
解决方案
https://cloud.google.com/iap/docs/authentication-howto#authenticating_from_a_service_account解释了如何扩展您的 DAG 代码,以便将凭据发送到受 IAP 保护的 API 后端。
一点背景知识:由于 Composer 是在 GCP 之上构建的,因此您的 Composer 部署具有运行时所用的唯一服务帐户身份。您可以将该服务帐户添加到终端节点的 IAP 访问列表中。
我不知道 Composer UI 是否可以轻松查看您的服务帐户的“电子邮件”地址,但如果您添加上面的代码并解码它生成的令牌,就会显示出来。
推荐阅读
- dart - 在 Dart / Flutter 中比较 List 和 Value
- azure - 将 Thales payshield 9000 迁移到 Azure Key Vault
- php - Docker-Symfony-Mysql: SQLSTATE[HY000] [2002] 连接被拒绝
- json - 如何将带有单元 ML 测试示例的 json 文件加载到 jmeter http 请求有效负载中
- swift - RxSwift 缓冲区性能
- java - 遍历一个类型的所有代理
- javascript - WordPress 颜色选择器不适用于克隆 jQuery
- android - 用 Retrofit-gson 解析 JSON?
- javascript - `是什么意思!函数(...){...}(...);`?
- arrays - 为什么 Spring 将我的对象变成属性数组?