【问题标题】:Airflow 2.0 API response 403 ForbiddenAirflow 2.0 API 响应 403 禁止
【发布时间】:2021-04-10 23:26:08
【问题描述】:

我正在尝试通过 Airflow 2.0 REST API 触发新的 dag 运行。如果我在远程机器上登录到 Airflow 网络服务器,然后我去 swagger 文档页面测试 API,则调用成功。如果我注销或者 API 调用是通过 Postman 或 curl 发送的,那么我会收到 403 禁止消息。无论我是否提供 Web 服务器用户名密码,curl 或 postman 都会收到相同的 403 错误消息。

curl -X POST --user "admin:blabla" "http://10.0.0.3:7863/api/v1/dags/tutorial_taskflow_api_etl/dagRuns" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{\"conf\":{},\"dag_run_id\":\"string5\"}"
{
  "detail": null,
  "status": 403,
  "title": "Forbidden",
  "type": "https://airflow.apache.org/docs/2.0.0/stable-rest-api-ref.html#section/Errors/PermissionDenied"
}

API 的安全性已更改为默认值,而不是 deny_all (auth_backend = airflow.api.auth.backend.default)。气流的安装是使用 ubuntu 18 仿生的 pip 完成的。如果手动或计划触发,Dags 运行良好。数据库后端是 postgres。

还尝试将 cookie 详细信息从 Chrome 复制到 postman 以解决此问题,但没有成功。

这是上面提到的两个调用在网络服务器上的日志。

airflowWebserver_container | 10.0.0.4 - - [05/Jan/2021:06:35:33 +0000] "POST /api/v1/dags/tutorial_taskflow_api_etl/dagRuns HTTP/1.1" 403 170 "http://10.0.0.3:7863/api/v1/ui/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
airflowWebserver_container | 10.0.0.4 - - [05/Jan/2021:06:35:07 +0000] "POST /api/v1/dags/tutorial_taskflow_api_etl/dagRuns HTTP/1.1" 409 251 "http://10.0.0.3:7863/api/v1/ui/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"

【问题讨论】:

标签: airflow airflow-scheduler


【解决方案1】:

我正在为 Airflow v2.0 使用 basic_auth。 AIRFLOW__API__AUTH_BACKEND 环境变量应设置为airflow.api.auth.backend.basic_auth。您将不得不重新启动 webserver 容器。然后,您应该能够使用带有--user 选项的 cURL 命令访问所有稳定的 API。

【讨论】:

    【解决方案2】:

    @AmitSingh 是正确的。将安全设置为默认值仅适用于实验性 api。我更改了气流中的相关配置,重新启动并在 api 路径中添加了“实验性”。请看https://airflow.apache.org/docs/apache-airflow/stable/rest-api-ref.html

    【讨论】:

      【解决方案3】:

      在 Airflow 2.0 中,似乎存在一些错误。

      如果你在airflow.cfg中设置了这个auth配置,它就不起作用了。

      auth_backend = airflow.api.auth.backend.basic_auth

      但是将其设置为环境变量是可行的

      AIRFLOW__API__AUTH_BACKEND: "airflow.api.auth.backend.basic_auth"

      【讨论】:

        【解决方案4】:

        也许也很高兴知道:

        您只能禁用实验性 API 的身份验证,而不是稳定的 REST API。

        见:https://airflow.apache.org/docs/apache-airflow/stable/security/api.html#disable-authentication

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-12-11
          • 2016-08-17
          • 2020-12-24
          • 1970-01-01
          • 2022-01-18
          • 1970-01-01
          相关资源
          最近更新 更多