我们使用气流作为调度程序。我想在DAG中调用一个简单的bash运算符。 bash脚本需要使用密码作为参数来进行进一步处理。
We are using airflow as a scheduler. I want to invoke a simple bash operator in a DAG. The bash script needs password as an argument to do further processing.
我如何安全地将密码存储在气流中(配置/变量/连接)并在dag定义文件中访问它。
How can I store a password securely in airflow (config/variables/connection) and access it in dag definition file.
我是气流和Python的新手,所以会感谢代码段。
I am new to airflow and Python so a code snippet will be appreciated.
推荐答案您可以将密码存储在挂钩中-只要您设置了Fernet密钥,该密码就会被加密。
You can store the password in a Hook - this will be encrypted so long as you have setup your fernet key.
以下是创建密码的方法连接。
Here is how you can create a connection.
from airflow.models import Connection def create_conn(username, password, host=None): new_conn = Connection(conn_id=f'{username}_connection', login=username, host=host if host else None) new_conn.set_password(password)然后,此密码在您设置的数据库中被加密。
Then, this password is encryted in the db you setup.
要访问此密码:
from airflow.hooks.base_hook import BaseHook connection = BaseHook.get_connection("username_connection") password = connection.password # This is a getter that returns the unencrypted password.编辑:
更容易通过UI创建连接的方法:
There is an easier way to create a connection via the UI:
然后:
Then:
更多推荐
使用Apache Airflow存储和访问密码
发布评论