
Digamos que hay un conjunto de comandos de shell {ls, cat, kill}
Quiero permitir que los usuarios del grupo A puedan ejecutar los comandos {ls, cat} y los usuarios del grupo B puedan ejecutar los comandos {cat, kill}
¿Cómo hacer eso? ¿Cuáles son los mejores enfoques?
Pensé en algunas soluciones, pero no parecen 100% seguras.
Respuesta1
Una de las formas de restringir la posibilidad de ejecutar comandos es lacaparazón restringido.
Extracto del manual, donde se dice que no se permiten o no se realizan lo siguiente:
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’.
Después de eso, puede agregar un enlace al comando que desea que puedan ejecutar.
Tal vez debería pasar por otro camino hacia tu objetivo.el uso desudo
.
En tu caso puedes editar sudoers
el archivo (con visudo
) y obtener algo similar 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:
- Un problema en el ejemplo: normalmente
kill
es uncomando incorporado del shell(compruébalo contype kill
). Si permite que los usuarios tengan un,shell
me temo que no encontrará una manera de evitar que lo utilicenkill
(a menos que modifique el código fuente del shell de manera adecuada y lo vuelva a compilar...). Si los comandos que desea cerrar para esos usuarios tienen
read
unexecution
atributo establecido para todos (p. ej.ls -l /usr/bin/zip
)-rwxr-xr-x 1 root root 188296 Oct 21 2013 /usr/bin/zip
tal vez puedas usar una solución alternativa, restringiendo el
execution
atributo solo al propietario y su gruposudo chattr o-x /usr/bin/zip
,-rwxr-xr-- 1 root root 188296 Oct 21 2013 /usr/bin/zip
agregar un nuevo usuario (p. ej.usuario genial) a ese grupo (tal vez con
/usr/sbin/nologin
asshell
), y escribiendo las siguientes 2 líneas en lugar de las correspondientes arriba: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).
La palabra clave
NOPASSWD:
es evitar la solicitud de la contraseña.
Sus usuarios pueden ejecutar los comandos consudo -u cooluser /usr/bin/zip
Efecto secundario: otros usuarios no podrán ejecutar ese comando hasta que no los incluyas en el grupo del propietario del archivo... y si es así
root
no debería ser tan seguro...
Referencias: