带有“ run_as_user”的气流模拟不起作用 [英] Airflow Impersonation with 'run_as_user' Not Working

查看:66
本文介绍了带有“ run_as_user”的气流模拟不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使模拟工作没有成功。我正在按照说明进行操作- https://airflow.apache.org/security.html#impersonation

I am trying to get impersonation working without success. I am following the instructions here - https://airflow.apache.org/security.html#impersonation

我以sudo身份启动了气流网络服务器,调度程序和工作程序,并在 airflow用户下运行。在sudoers文件中设置了该用户,不允许任何密码登录。

I launched airflow webserver, scheduler, and worker as sudo running under the 'airflow' user. This user is setup in the sudoers file to allow no password logins.

我创建了一个BashOperator和PythonOperator,并将run_as_user参数设置为服务器上一个名为 linus的现有用户。当我以气流身份登录时,可以通过运行 sudo -u linus 来切换用户,而不会提示我输入密码。

I created a BashOperator and a PythonOperator with the run_as_user parameter set to an existing user named 'linus' on the server. When I am logged in as 'airflow', I am able to switch users by running sudo -u linus without it prompting me for a password.

dag = DAG('test_impersonation', default_args=args)

def print_user(**kwargs):
    print('USER:', getpass.getuser())

t1 = BashOperator(task_id='bash_task', 
                  bash_command='touch /home/linus/test.x',
                  run_as_user='linus',
                  dag=dag)

t2 = PythonOperator(task_id='py_task',
                    python_callable='print_user', 
                    run_as_user='linus',
                    dag=dag)

我是在终端中使用以下命令测试这些任务:

I am testing these tasks with the following commands in the terminal:

airflow test test_impersonation bash_task 2018-03-30
airflow test test_impersonation py_task 2018-03-30

第一个命令(BashOperator任务)失败,权限拒绝错误告诉我仍然以气流用户身份运行。

The first command (BashOperator task) fails with a permission denied error telling me it's still running as the 'airflow' user.

第二个命令(PythonOperator任务)显示以下内容:

The second command (PythonOperator task) prints the following:

USER: airflow

我希望它能打印 USER:linus

我缺少什么吗?任何帮助将不胜感激。

Is there anything I am missing? Any help would be greatly appreciated.

谢谢阅读!

推荐答案

我不确定,但是看起来 sudo -u 前缀已应用在 task_runner 中,该文件由执行者设置,并且可能运行cli run命令;而cli test 命令仅在测试模式下在 task_instance 上运行时调用,并且不会在<$之前c $ c> sudo -u 。

I'm not exactly certain, but it looks like the sudo -u prepend is applied in a task_runner, which is setup by the executor, and probably runs the cli run command; while the cli test command only calls run on the task_instance in test mode, and this doesn't prepend the sudo -u.

这篇关于带有“ run_as_user”的气流模拟不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆