
Digamos que haja um conjunto de comandos shell {ls, cat, kill}
Quero permitir que os usuários do grupo A possam executar os comandos {ls, cat} E os usuários do grupo B possam executar os comandos {cat, kill}
Como fazer isso, quais são as melhores abordagens?
Pensei em algumas soluções, mas elas não parecem 100% seguras.
Responder1
Uma das formas de restringir a possibilidade de execução de comandos é ashell restrito.
Trecho do manual, onde se diz que não são permitidos ou não são realizados:
Changing directories with the cd builtin.
Setting or unsetting the values of the SHELL, PATH, ENV, or BASH_ENV variables.
Specifying command names containing slashes.
Specifying a filename containing a slash as an argument to the . builtin command.
Specifying a filename containing a slash as an argument to the -p option to the hash builtin command.
Importing function definitions from the shell environment at startup.
Parsing the value of SHELLOPTS from the shell environment at startup.
Redirecting output using the ‘>’, ‘>|’, ‘<>’, ‘>&’, ‘&>’, and ‘>>’ redirection operators.
Using the exec builtin to replace the shell with another command.
Adding or deleting builtin commands with the -f and -d options to the enable builtin.
Using the enable builtin command to enable disabled shell builtins.
Specifying the -p option to the command builtin.
Turning off restricted mode with ‘set +r’ or ‘set +o restricted’.
Depois disso, você pode adicionar um link para o comando que deseja que eles possam executar.
Talvez outro caminho para o seu objetivo deva ser atravéso uso desudo
.
No seu caso você pode editar sudoers
o arquivo (com visudo
) e obter algo semelhante a:
User_Alias USERS_GROUP_A = joe, mike, cedric
User_Alias USERS_GROUP_B = jude, zoe, cedric
Cmnd_Alias COMMANDS_GROUP_A = /bin/ls, /bin/cat, /usr/bin/zip
Cmnd_Alias COMMANDS_GROUP_B = /bin/kill, /bin/cat, /usr/bin/zip
USERS_GROUP_A ALL= COMMANDS_GROUP_A
USERS_GROUP_B ALL= COMMANDS_GROUP_B
# users of the group USERS_GROUP_A may run /bin/ls, /bin/cat, and /usr/bin/zip
# from any machine (ALL).
# users of the group USERS_GROUP_B may run /bin/kill,/bin/cat and /usr/bin/zip
# from any machine (ALL).
Notas:
- Um problema no exemplo: geralmente
kill
é umcomando interno do shell(verifique comtype kill
). Se você permitir que os usuários tenham um,shell
receio que você não encontrará uma maneira de evitar o uso deleskill
(a menos que você modifique o código-fonte do shell de maneira adequada e o recompile...). Se os comandos que você deseja fechar para esses usuários estiverem com
read
umexecution
atributo definido para todos (por exemplols -l /usr/bin/zip
)-rwxr-xr-x 1 root root 188296 Oct 21 2013 /usr/bin/zip
talvez você possa usar uma solução alternativa, restringindo o
execution
atributo apenas ao proprietário e ao grupo delesudo chattr o-x /usr/bin/zip
,-rwxr-xr-- 1 root root 188296 Oct 21 2013 /usr/bin/zip
adicionando um novo usuário (por exemplousuário legal) para esse grupo (talvez com
/usr/sbin/nologin
asshell
) e escrevendo as 2 linhas a seguir em vez das correspondentes acima:USERS_GROUP_A ALL=(cooluser) NOPASSWD: COMMANDS_GROUP_A USERS_GROUP_B ALL=(cooluser) NOPASSWD: COMMANDS_GROUP_B # users of the USERS_GROUP_A may run /bin/ls, /bin/cat and /usr/bin/zip # as the user cooluser from any machine (ALL). # users of the USERS_GROUP_B may run /bin/kill,/bin/cat and /usr/bin/zip # as the user cooluser from any machine (ALL).
A palavra-chave
NOPASSWD:
é evitar a solicitação da senha.
Seus usuários podem executar os comandos comsudo -u cooluser /usr/bin/zip
Efeito colateral: outros usuários não poderão executar esse comando até que você os inclua no grupo do proprietário do arquivo... e se for
root
não deve ser tão seguro...
Referências: