visudoを使用して再起動、停止、および終了権限を削除する方法は?

visudoを使用して再起動、停止、および終了権限を削除する方法は?

ユーザーRickに再起動権限を奪い取ろうとしています。私は試し!てみましたNOEXEC。別の方法がありますか?

Rick   ALL = (ALL)  !/sbin/reboot
Rick   ALL = NOEXEC: /sbin/reboot

ベストアンサー1

あなたはできません。特定のコマンドを除くすべてのコマンドを実行するためのユーザー権限を割り当てるために「否定的なsudo」を作成することは実際には不可能です。これは、ユーザーがこれらの制限を簡単にバイパスできるためです。

  • 拒否されたコマンドをシェルスクリプトに挿入して実行することによって
  • 拒否されたコマンドを別の名前にコピーする
  • 次のコマンドを実行します(あなたの場合、、、およびすべてinit 6telinit 6起動shutdown -r nowsystemctl isolate reboot.target実行し、コマンドを拒否しません)。
  • 拒否されたコマンドを実行してexec
  • テキストエディタや他のプログラムからシェルをエスケープする
  • または単にrootユーザーに切り替えてsu

これはマンページにも記載されていますsudoers

SECURITY NOTES
   Limitations of the ‘!’ operator
     It is generally not effective to “subtract” commands from ALL 
     using the ‘!’ operator.  A user can trivially circumvent this by copy-
     ing the desired command to a different name and then executing that.  
     For example:

     bill    ALL = ALL, !SU, !SHELLS

     Doesn’t really prevent bill from running the commands listed in SU
     or SHELLS since he can simply copy those commands to a different
     name, or use a shell escape from an editor or other program.  
     Therefore, these kind of restrictions should be considered advisory at
     best (and reinforced by policy).

     In general, if a user has sudo ALL there is nothing to prevent 
     them from creating their own program that gives them a root shell (or
     making their own copy of a shell) regardless of any ‘!’ elements 
     in the user specification.

代わりに、ユーザーに必要な一連の制限されたコマンドを識別し、そのコマンドにのみアクセス権を付与する必要があります。

NOEXEC単にシェルエスケープを無効にしても、他のすべての回避方法がブロックされるわけではありません。

おすすめ記事