带有“ run

编程入门 行业动态 更新时间:2024-10-14 20:18:55
本文介绍了带有“ run_as_user”的气流模拟不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I am trying to get impersonation working without success. I am following the instructions here - airflow.apache/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 上运行时调用,并且不会在 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

本文发布于:2023-11-24 13:17:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1625354.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:run

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!