
シェルコマンドのセット{ls、cat、kill}があるとします。
グループAのユーザーがコマンド{ls、cat}を実行できるようにし、グループBのユーザーがコマンド{cat、kill}を実行できるようにしたい。
それをどうやって行うのか、最善のアプローチは何でしょうか?
いくつかの解決策を考えましたが、100%安全ではないようです。
答え1
コマンド実行の可能性を制限する方法の1つは、制限されたシェル
マニュアルからの抜粋ですが、以下のことは禁止または実行されないと記載されています。
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’.
その後、実行したいコマンドへのリンクを追加できます。
おそらく、あなたの目標に到達する別の道はの用法sudo
あなたの場合、ファイルを編集して(sudoers
を使用visudo
)、次のようなものを取得できます。
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).
ノート:
- 例の問題:通常
kill
はシェル組み込みコマンド( で確認してくださいtype kill
)。 ユーザーに を許可した場合、shell
の使用を回避する方法は見つからないと思いますkill
(シェルのソース コードを適切に変更して再コンパイルしない限り)。 これらのユーザーに対して閉じたいコマンドが であり
read
、execution
属性がすべてに設定されている場合(例ls -l /usr/bin/zip
: )-rwxr-xr-x 1 root root 188296 Oct 21 2013 /usr/bin/zip
回避策として、
execution
属性を所有者とそのグループのみに制限することができますsudo chattr o-x /usr/bin/zip
。-rwxr-xr-- 1 root root 188296 Oct 21 2013 /usr/bin/zip
新しいユーザーの追加(例:クールユーザー) をそのグループに追加し (
/usr/sbin/nologin
as を使用する場合もありますshell
)、対応する上記の代わりに次の 2 行を記述します。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).
キーワードは
NOPASSWD:
パスワードの入力を要求されないようにするためのものです。
ユーザーは以下のコマンドを実行することができます。sudo -u cooluser /usr/bin/zip
副作用: ファイルの所有者のグループに他のユーザーを含めない限り、他のユーザーはそのコマンドを実行できません...もし含めたとしても、
root
それほど安全ではないはずです...
参考文献: