小编Fra*_*tin的帖子

在 BashOperator 中将密码作为参数发送时如何屏蔽密码

我正在使用 BashOperator 运行需要多个参数才能工作的 bash 命令。在这些参数中,我发送了一个密码。

bash_task = BashOperator(
    task_id='bash_operator_example',
    bash_command=f'echo {param1} {password}',
)
Run Code Online (Sandbox Code Playgroud)

这里的问题是,即使我是从应该保密的气流连接中获取密码,当操作员运行命令时,密码也会在日志中的 clear test 中出现。

查看下面生成的日志:

[2021-03-06 17:42:14,079] {bash_operator.py:136} INFO - Temporary script location: /tmp/airflowtmp_mez12q_/bash_operator_examplena7hxdup
[2021-03-06 17:42:14,079] {bash_operator.py:146} INFO - Running command: echo my_param_1 my_password
[2021-03-06 17:42:14,092] {bash_operator.py:153} INFO - Output:
[2021-03-06 17:42:14,094] {bash_operator.py:157} INFO - my_param_1 my_password
[2021-03-06 17:42:14,094] {bash_operator.py:161} INFO - Command exited with return code 0
[2021-03-06 17:42:14,101] {taskinstance.py:1070} INFO - Marking task as SUCCESS.dag_id=TEST_running_DAG, task_id=bash_operator_example, execution_date=20210101T000000, start_date=20210306T174214, end_date=20210306T174214
Run Code Online (Sandbox Code Playgroud)

我尝试了几件事,例如,使用 bash 运算符中可用的参数,例如:

bash_task = BashOperator( …
Run Code Online (Sandbox Code Playgroud)

airflow

6
推荐指数
1
解决办法
116
查看次数

标签 统计

airflow ×1