气流-如何使用REST API的安全授权 导言:

气流-如何使用REST API的安全授权 导言:,rest,authentication,post,airflow,Rest,Authentication,Post,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),但我需要一些安全性,因为它不能公开,所以

大家好,我正在尝试使用气流的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身份验证,我可以在
aiffort.cfg
上设置auth_backend,它的工作原理与用于Web界面的密码身份验证非常相似


[api]
auth_backend = airflow.contrib.auth.backends.password_auth 
但是现在,答案是(401-未经授权),我不知道如何配置RESTAPI以使用具有这种安全性的外部触发器

  • 是否需要在页眉上传递我的用户密码才能工作
  • 我怎么能做到

  • 我们假设存在一个用户:admin通过:admin权限:admin


链接:

您必须传递带有base 64编码头的授权头,该头带有字符串user:pass

您可以在此处查看它是如何发生的:

用法示例:

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