如何在Airflow中使用HashiCorp Vault?

ph

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

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

卡西尔

气流> = 1.10.10支持秘密后端,并支持从Hashicorp Vault获取气流变量和连接。

气流文档中的更多详细信息: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"}

DAG示例用于测试集成:

from airflow import DAG
from airflow.operators.python_operator import PythonOperator
from datetime import datetime
from airflow.hooks.base_hook import BaseHook


def get_secrets(**kwargs):
    conn = BaseHook.get_connection(kwargs['my_conn_id'])
    print(f"Password: {conn.password}, Login: {conn.login}, URI: {conn.get_uri()}, Host: {conn.host}")

with DAG('example_secrets_dags', start_date=datetime(2020, 1, 1), schedule_interval=None) as dag:


    test_task = PythonOperator(
        task_id='test-task',
        python_callable=get_secrets,
        op_kwargs={'my_conn_id': 'smtp_default'},
    )

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Hashicorp Vault使Vault生成多个关键值

Hashicorp Vault加密数据

Hashicorp Vault用于文件存储?

HashiCorp Vault密封问题

HASHICORP VAULT:如何从文件中读取多个项目并将其写入Vault

如何使用Hashicorp Vault设置用户名/密码验证

HashiCorp Vault填充kubernetes秘密

如何在Kubernetes中使用Vault HA进行滚动更新?

尝试使用KV时,Hashicorp Vault cli CLI返回403

如何在我使用kubernetes的领事(Hashicorp-consul)中将Vault(Hashicorp-vault)注册为服务?

如何在Android中使用Azure Key Vault

Hashicorp Vault:无法使用Node-Vault写入秘密

在Hitcorp管道上使用Hashicorp Vault的最佳方法是什么?

如何在Kubernetes中为HashiCorp Vault UI设置入口

在不同的环境中使用Hashicorp Vault和Spring Cloud

如何在生产中使用Hashicorp Vault的AppRole?

关闭hashicorp Vault服务器开发

Hashicorp Vault如何列出所有角色

如何在 Centos 8 和 cloud-init 中使用 Hashicorp 的 Linux 存储库来安装 Vault

如何像登录网站一样使用 Hashicorp Vault

如何在链接模板中使用 Azure Key Vault 机密

如何让 HashiCorp Vault 政策正确?

Jenkins hashicorp-vault-plugin 空结果

Hashicorp Vault for PostgreSQL 动态凭证出错

从hashicorp vault 填充kubernetes Configmap

Hashicorp Vault:“代码:400。错误”错误消息

如何使用已生成的 AES 256 GCM 96 密钥(来自 Hashicorp Vault)加密数据?

如何连接到远程 hashicorp vault 服务器

如何使用 HashiCorp Vault 簽名