gpt4 book ai didi

rest - Airflow - 如何使用 REST API 的安全授权

转载 作者:行者123 更新时间:2023-12-04 12:24:35 25 4
gpt4 key购买 nike

介绍:

大家好,我正在尝试使用 Airflow 的 REST API 来激活具有外部触发器的 DAG,例如:
POST: http://{{url}}:{{port}}/api/experimental/dags/MY_DAG_ID/dag_runs

headers = {
'Content-Type': 'application/json',
'Cache-Control': 'no-cache',
}

问题:

效果很好 (答案:状态 200) ,但我需要一些安全性,因为它不能对公众开放,所以我阅读了 API 身份验证,我可以设置 auth_backend airflow.cfg这将与用于 Web 界面的密码身份验证非常相似。

[api]
auth_backend = airflow.contrib.auth.backends.password_auth

但现在,答案是 (401 - 未经授权) 而且我不知道如何配置 REST API 以将我的外部触发器与此安全性结合使用。
  • 有没有必要通过我的用户 密码 在标题上工作?
  • 我怎么能做到这一点?
  • 让我们假设存在一个 用户:管理员 , 通行证:管理员 权限:管理员


  • 链接:
  • https://airflow.apache.org/docs/stable/api.html#authentication
  • 最佳答案

    您必须使用字符串 user:pass 传递带有 base 64 编码 header 的授权 header

    你可以在这里查看它是如何发生的:https://github.com/apache/airflow/blob/029c84e5527b6db6bdbdbe026f455da325bedef3/airflow/contrib/auth/backends/password_auth.py#L205

        header = request.headers.get("Authorization")
    if header:
    userpass = ''.join(header.split()[1:])
    username, password = base64.b64decode(userpass).decode("utf-8").split(":", 1)

    用法示例:

    https://github.com/apache/airflow/blob/7cba83333c5227ce37967c65d189a5e994898c68/tests/www/api/experimental/test_password_endpoints.py
            response = c.post(
    url_template.format('example_bash_operator'),
    data=json.dumps(dict(run_id='my_run' + datetime.now().isoformat())),
    content_type="application/json",
    headers={'Authorization': 'Basic aGVsbG86d29ybGQ='} # hello:world
    )

    关于rest - Airflow - 如何使用 REST API 的安全授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60744050/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com