CentOSをSELinuxのstrict モードで動かしてみよう
更新しないでかなり放置状態となっていました。。。
SELinuxに興味が出てきて、無謀にもstrictモードで動かしたくなりました。
ということで実験。
まずは…
まずは普通にtargetedモードで動く事を確認することに。
環境をみてみる
# uname -a Linux myhost 2.6.18-128.2.1.el5xen #1 SMP Tue Jul 14 07:49:50 EDT 2009 i686 i686 i386 GNU/Linux # cat /etc/redhat-release CentOS release 5.3 (Final)
SELinuxが有効になっているかをみてみる
# sestatus -v SELinux status: enabled SELinuxfs mount: /selinux Current mode: enforcing Mode from config file: enforcing Policy version: 21 Policy from config file: targeted Process contexts: Current context: user_u:system_r:unconfined_t Init context: system_u:system_r:init_t /sbin/mingetty system_u:system_r:getty_t /usr/sbin/sshd system_u:system_r:unconfined_t:SystemLow-SystemHigh File contexts: Controlling term: user_u:object_r:devpts_t /etc/passwd system_u:object_r:etc_t /etc/shadow system_u:object_r:shadow_t /bin/bash system_u:object_r:shell_exec_t /bin/login system_u:object_r:login_exec_t /bin/sh system_u:object_r:bin_t -> system_u:object_r:shell_exec_t /sbin/agetty system_u:object_r:getty_exec_t /sbin/init system_u:object_r:init_exec_t /sbin/mingetty system_u:object_r:getty_exec_t /usr/sbin/sshd system_u:object_r:sshd_exec_t /lib/libc.so.6 system_u:object_r:lib_t -> system_u:object_r:lib_t /lib/ld-linux.so.2 system_u:object_r:lib_t -> system_u:object_r:ld_so_t
有効になっている模様
プロセスをみてみる
# ps -feZ LABEL UID PID PPID C STIME TTY TIME CMD system_u:system_r:init_t root 1 0 0 00:03 ? 00:00:00 init [3] (以下略)
targetedモードで動いている模様
ということで…
strictモードに変更してみる事に
strictモードに変更してみる
/etc/selinux/configを編集
# vi /etc/selinux/config SELINUX=enforcing SELINUXTYPE=strict
再起動時にラベルをつけなおす
# touch /.autorelabel
再起動
# shutdown -r now
strictモードで起動してみる
起動メッセージ
--- 一応順調そう---
起動メッセージ
(一部略)
Red Hat nash version 5.1.19.6 starting
***以下エラー***
INIT: cannot execute "/etc/rc.d/rc.sysinit"
INIT: Entering runlevel: 3
INIT: cannot execute "/etc/rc.d/rc"
INIT: Id "1" respawning too fast: disabled for 5 minutes
INIT: Id "2" respawning too fast: disabled for 5 minutes
INIT: Id "3" respawning too fast: disabled for 5 minutes
INIT: Id "6" respawning too fast: disabled for 5 minutes
INIT: Id "4" respawning too fast: disabled for 5 minutes
INIT: Id "5" respawning too fast: disabled for 5 minutes
INIT: no more processes left in this runlevel
…駄目らしい(失敗)。
このままだと起動すら出来ず…
permissiveモードで起動しよう
このままだとログすら見られないので、permissiveモードでブートすることにします
permissiveモードを指定して起動してみる
grub のブートオプションを起動時に編集する
root (hd0.0)
kernel /xen.gz-2.6.18-128.2.1.el5
module /vmlinuz-2.6.18-128.2.1.el5xen ro root=/dev/md1 rhgb quiet
module /initrd-2.6.18-128.2.1.el5xen.img
↓
root (hd0.0)
kernel /xen.gz-2.6.18-128.2.1.el5
module /vmlinuz-2.6.18-128.2.1.el5xen ro root=/dev/md1 rhgb quiet enforcing=0
module /initrd-2.6.18-128.2.1.el5xen.img
としてとりあえず起動…
audit.logを確認してみる
ログイン後、 /var/log/audit/audit.log を見てみると、、、
…なんかこんなのがいっぱい出てました(汗
type=AVC msg=audit(1249399459.600:124): avc: denied { read } for pid=4197 comm="bash" name="init" dev=md1 ino=4948032 scontext=user_u:user_r:user_t:s0 tcontext=system_u:object_r:init_exec_t:s0 tclass=file type=SYSCALL msg=audit(1249399459.600:124): arch=40000003 syscall=33 success=yes exit=0 a0=9b1c7b8 a1=4 a2=ffffffff a3=9b1c7b8 items=0 ppid=4196 pid=4197 auid=500 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=1 comm="bash" exe="/bin/bash" subj=user_u:user_r:user_t:s0 key=(null) type=AVC msg=audit(1249399459.600:125): avc: denied { execute_no_trans } for pid=4243 comm="bash" path="/sbin/init" dev=md1 ino=4948032 scontext=user_u:user_r:user_t:s0 tcontext=system_u:object_r:init_exec_t:s0 tclass=file type=SYSCALL msg=audit(1249399459.600:125): arch=40000003 syscall=11 success=yes exit=0 a0=9b1c7b8 a1=9b2fa10 a2=9b1be60 a3=0 items=0 ppid=4197 pid=4243 auid=500 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=1 comm="init" exe="/sbin/init" subj=user_u:user_r:user_t:s0 key=(null) type=AVC msg=audit(1249399459.608:126): avc: denied { write } for pid=4243 comm="init" name="initctl" dev=tmpfs ino=1381 scontext=user_u:user_r:user_t:s0 tcontext=system_u:object_r:initctl_t:s0 tclass=fifo_file type=SYSCALL msg=audit(1249399459.608:126): arch=40000003 syscall=5 success=yes exit=3 a0=804f0af a1=1 a2=0 a3=bfa20c69 items=0 ppid=4197 pid=4243 auid=500 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts0 ses=1 comm="init" exe="/sbin/init" subj=user_u:user_r:user_t:s0 key=(null) type=AVC msg=audit(1249399460.628:127): avc: denied { execute } for pid=4274 comm="init" name="bash" dev=md1 ino=41189411 scontext=system_u:system_r:init_t:s0 tcontext=system_u:object_r:shell_exec_t:s0 tclass=file
どうやら、SELinuxが効き過ぎて、起動すらできないらしい…
audit2allow
困ったときのaudit2allowということで、とりあえずaudit2allowを実行してみる
audit2allowの実行
# audit2allow -M local -d
******************** IMPORTANT ***********************
To make this policy package active, execute:
作成された local.teを開いてみる
# more local.te module local 1.0; require { type udev_t; type udev_tbl_t; type init_t; type shell_exec_t; type insmod_t; type lvm_t; type initrc_t; class capability sys_nice; class lnk_file create; class file { read execute }; class dir { write search rmdir create getattr add_name }; } #============= init_t ============== allow init_t shell_exec_t:file { read execute }; #============= insmod_t ============== allow insmod_t self:capability sys_nice; #============= lvm_t ============== allow lvm_t initrc_t:dir search; #============= udev_t ============== allow udev_t udev_tbl_t:dir { write search rmdir create getattr add_name }; allow udev_t udev_tbl_t:lnk_file create;
#定義の意味がよくわからないがとりあえず進めよう。。
モジュールの読み込み
とりあえず、出来たモジュールを読みこませてみる
# semodule -i local.pp
再挑戦
モジュール読みこんだようなので…再挑戦
再起動時にラベルをつけなおす
念のため
# touch /.autoreralabel
再起動
# shutdown -r now
再び起動
どうやら起動するようにはなった模様
ログインも出来ました
がしかし
こんなメッセージが大量に出力されているので、まだ設定が足りないらしい。。
udevd[480]: delete_path: rmdir(/dev/.udev/failed) failed: Permission denied
先は長そうです。
気長にやってみるという事で、一旦今日はここまで。