如何在 Airflow 中使用 HashiCorp Vault?

sop*_*ros 6 python python-3.x airflow hashicorp-vault

我开始使用 Apache Airflow,我想知道如何有效地使用存储在 Vault 中的机密和密码。不幸的是,除了Airflow项目本身尚未实现的钩子之外,搜索不会返回有意义的答案。

我总是可以使用 Python 的hvac模块来一般地访问 Vault,PythonOperator但我想知道是否有更好的方法或好的做法(例如,我错过了一个 Airflow 插件)。

kax*_*xil 3

Airflow >=1.10.10支持 Secrets 后端并支持从 Hashicorp Vault 获取 Airflow 变量和连接。

Airflow 文档中的更多详细信息:https://airflow.apache.org/docs/stable/howto/use-alternative-secrets-backend.html#hashicorp-vault-secrets-backend

如果您想在本地测试它,请查看https://www.astronomer.io/guides/airflow-and-hashicorp-vault/上的教程

在 中设置以下配置airflow.cfg,根据您的环境进行更新:

backend = airflow.contrib.secrets.hashicorp_vault.VaultBackend
backend_kwargs = {"connections_path": "connections", "variables_path": "variables", "mount_point": "airflow", "url": "http://127.0.0.1:8200"}
Run Code Online (Sandbox Code Playgroud)

用于测试集成的 DAG 示例:

backend = airflow.contrib.secrets.hashicorp_vault.VaultBackend
backend_kwargs = {"connections_path": "connections", "variables_path": "variables", "mount_point": "airflow", "url": "http://127.0.0.1:8200"}
Run Code Online (Sandbox Code Playgroud)