0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ユーザ(グループ)・コマンド・引数(ファイル)を限定して、ルート権限(sudo)を可能にする

Last updated at Posted at 2021-11-07

root権限が必要な作業があるが全機能開放が不可なので、ユーザ・コマンド・操作対象ファイルを限定してルート権限を委譲する。個人だと全委任でよいのだが、複数人が携わるPRJや、セキュリティ対策のため開発者がrootパスワードを知り得ない場合でも、root権限を限定して使用可能とするため。

基本的な考え方

  • ユーザ・グループ : ユーザに対し補助グループを割り当てて、補助グループに対してsudo設定をする。
  • sudoers : 利用者には、sudoコマンドを使用させるがsudo可能なコマンドを限定する

設定例

ユーザ設定

  • ユーザ「foo,bar」はすでに作成されている前提。
  • 新たにグループ「SUDO1」を作成し、「foo,bar」の補助グループとして割り当てする。グループIDは5000とするが(-g 5000)任意設定可能。
## グループ追加
# groupadd -g 5000 SUDO1
# getent group
	foo:x:1001:
	bar:x:1002:
	SUDO1:x:5000:
## ユーザに補助グループを割り当て
# usermod -a -G SUDO1 foo 
# usermod -a -G SUDO1 bar
# id foo; id bar
uid=1001(foo) gid=1001(foo) groups=1001(foo),5000(SUDO1)
uid=1002(bar) gid=1002(bar) groups=1002(bar),5000(SUDO1)

sudoers

ローカルホストのシスログを解放するので

  • sudo可能なホストは「localhost」
  • sudo可能なコマンドは、コマンド+引数で指定する
  • sudo可能なユーザは、グループで指定する
/etc/sudoers
Host_Alias H_LOCAL = localhost
Cmnd_Alias C_MESSAGES1 = /bin/view /var/log/messages*
Cmnd_Alias C_MESSAGES2 = /bin/cp   /var/log/messages*
Cmnd_Alias C_MESSAGES3 = /bin/tail -f /var/log/messages*

# who  where   = (as_whom)  what
%SUDO1 H_LOCAL = (ALL) NOPASSWD: C_MESSAGES1, C_MESSAGES2, C_MESSAGES3
  • %SUDO1 : グループ「SUDO1」に許可する
  • H_LOCAL : loalhostから
  • (ALL) NOPASSSWD: : どのユーザにでもsudo可能で、パスワード確認を省略する
  • C_MESSAGESxx : sudo可能なコマンドを指定する。Alias定義で引数を指定しているので、指定された引数意外の場合は許可されない。

参考:sudoersの記法
参考:sudo

トレーサビリティ

ユーザfooが sudo view /var/log/messages を実行した時

/var/log/secure
Nov  7 10:13:01 localhost sudo[13450]:     foo : TTY=pts/1 ; PWD=/home/admin ; USER=root ; COMMAND=/bin/view /var/log/messages
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?