Saltstack限制某些shell命令执行

在cmdmod模块中cmd.run、cmd.run_all、cmd.run_stdout等都可以执行shell命令,要静止某些shell命令,可以修改_run()这个函数来彻底的静止调用这个命令。

centos 7:/usr/lib/python2.7/site-packages/salt/modules/cmdmod.py文件第235行

centos 6:/usr/lib/python2.6/site-packages/salt/modules/cmdmod.py文件第235行

例如rm命令:

    '''
    Do the DRY thing and only call subprocess.Popen() once
    '''
#禁止rm命令
    if r'rm ' in cmd:
       ret = {}
       ret['stdout'] = "'rm' is dangerous!!! MISSION FAILED!!!"
       ret['stderr'] = ''
       ret['pid'] = ''
       ret['retcode'] = 0
       return ret

if _is_valid_shell(shell) is False:

   .......

如果是修改_run()函数后就不用修改run()等其它函数了,修改文件后重启minion后生效,测试下效果。

[root@perf023 master.d]# salt '10.159.59.10' cmd.run "rm -f /tmp/123.log"
10.159.59.10:
    'rm' is dangerous!!! MISSION FAILED!!!
[root@perf023 master.d]# 

 

posted @ 2019-05-08 20:38  ShawHe  阅读(774)  评论(0编辑  收藏  举报