我的问题是在使用Ansible时,如何限制一般使用者(regular user)在sudo权限下只能实行某些指令,而不是像root user一样无限制。
举例来说,如果在managed node中有个regular user叫做"ianyc",且sudoers file里这样规范:
"ianyc ALL=(ALL) /bin/ls"
代表此user仅能透过sudo执行ls指令。
然而在Ansible controller node中,如果我执行以下playbook:
###
- hosts: linux become: yes become_method: sudo vars_files:
- /etc/ansible/sensitiveData.yml vars: ansible_become_pass: "{{ linuxSudoPassword }}" tasks:
- name: list the directory command: ls /root register: result
- debug: var=result ###
其中linux代表managed node群组而sensitiveData是vault file,存着sudo password。会得到下列错误资讯:
"Sorry, user ianyc is not allowed to execute '/bin/sh -c echo BECOME-SUCCESS-orzksvkkqakoaplykpvjkycejidpddgv; /usr/bin/python /home/ianyc/.ansible/tmp/ansible-tmp-1554271272.93-107453846539342/AnsiballZ_setup.py' as root on localhost.localdomain."
请问这是什么意思以及为何会发生此错误?
除此之外,我亦尝试将"/bin/sh"加入到sudoer file中:
"ianyc ALL=(ALL) /bin/ls, /bin/sh"
如此一来,Ansible是可以执行的,但是问题就会变成...
"不止sudo ls可以执行,而是全部指令都可以执行"
因此,我想问在操作Ansible时,有没有什么方法可以限制regular user使用sudo权限时只能做特定的某些事?