SELinuxの設定

サーバのDesktopをみるとsetroubleshootがメッセージを出している筈だ。アイコンもしくはバルーンをクリックするとsetroubleshootのウィンドウが開き、詳細を確認できる。

setroubleshoot browserを開きメッセージを確認すると

SELinux prevented /usr/sbin/in.tftpd from reading files stored on a NFS filesytem.

書かれて、対処策として

Changing the "use_nfs_home_dirs" boolean to true will allow this access: "setsebool -P use_nfs_home_dirs=1"
The following command will allow this access:setsebool -P use_nfs_home_dirs=1

と書いてある。そこでメッセージに従い次のコマンドを実行する。

[root@vmserver ~]# setsebool -P use_nfs_home_dirs=1

気を取り直して、再度クライアントをブートしてみよう。しかし、また"Could not find kernel image"というメッセージと共にブートができない。再び、SELinuxがブロックしている。メッセージを見ると前回と同じだ。どうも「booleanパラメータ」の変更だけでは回避できないようだ。

ここからは次のどちらかの方法を取る必要がある。

  • SELinux を permissive か disabled にする
  • SELinuxにローカルポリシーを追加する

ここではローカルポリシーの追加について述べる。

まず、一旦、SELinuxを permissiveに変更し、クライアントをブートする。途中、エラーメッセージが色々とですが、進められるところまで進める。何処まで進むかは環境に依ってことなる。カーネルの起動の途中までかデーモンの起動のところで固まるか、もしくはログインまで進むかは環境と設定による。今回はautomountデーモンの起動のところで一回ひっかりはしたが、キーを押すことで先へ進み、ログインのプロンプトまで確認できた。(ただし、Xウィンドウは立ち上がらなかった。)

この状態で、サーバで次のコマンドを実行しローカルポリシーを作る。

[root@vmserver ~]# mkdir tmp
[root@vmserver ~]# cd tmp
[root@vmserver tmp]# audit2allow -a -l -m vmserver > vmserver.te
[root@vmserver tmp]# cat vmserver.te

module vmserver 1.0;

require {
        type lvm_control_t;
        type tftpd_t;
        type nfsd_t;
        type nfs_t;
        class chr_file write;
        class file { read getattr };
}

#============= nfsd_t ==============
allow nfsd_t lvm_control_t:chr_file write;

#============= tftpd_t ==============
allow tftpd_t nfs_t:file { read getattr };

このテキストベースのポリシーを元に、バイナリ形式(.pp)を生成する。

[root@vmserver tmp]# make -f /usr/share/selinux/devel/Makefile
Compiling targeted vmserver module
/usr/bin/checkmodule:  loading policy configuration from tmp/vmserver.tmp
/usr/bin/checkmodule:  policy configuration loaded
/usr/bin/checkmodule:  writing binary representation (version 6) to tmp/vmserver.mod
Creating targeted vmserver.pp policy package
rm tmp/vmserver.mod tmp/vmserver.mod.fc
[root@vmserver tmp]# ls
tmp  vmserver.fc  vmserver.if  vmserver.pp  vmserver.te

そして、このポリシーをシステムに登録する。

[root@vmserver tmp]# semodule -i vmserver.pp
[root@vmserver tmp]# semodule -l | grep vmserver
vmserver        1.0

さて、もう一度、クライアントをブートする。やはり先程と同じところまで進む筈だが、SELinuxの警告は出ていない。これでSELinuxの設定をEnforcingにしてもOKだ。

クライアントのSELinuxはdisabledに

クライアントのSELinuxはdisabledにした方が良い。NFSを通すと全てのファイルのコンテキストがタイプが"nfs_t"になってしまう。通常ルート直下ディレクトリのコンテキストは次のようになっている。

# ls -Z /tftpboot/f8/root/
drwxr-xr-x  root root system_u:object_r:bin_t:s0       bin
drwxr-xr-x  root root system_u:object_r:boot_t:s0      boot
drwxr-xr-x  root root system_u:object_r:root_t:s0      dev
	:
	:
drwxr-xr-x  root root system_u:object_r:usr_t:s0       usr
drwxr-xr-x  root root system_u:object_r:var_t:s0       var

しかし、NFSを通してアクセスするクライアントで実行すると次のようになってしまう。

# ls -Z /
drwxr-xr-x  root root system_u:object_r:nfs_t:s0       bin
drwxr-xr-x  root root system_u:object_r:nfs_t:s0       boot
drwxr-xr-x  root root system_u:object_r:tmpfs_t:s0     dev
	:
	:
drwxr-xr-x  root root system_u:object_r:nfs_t:s0       usr
drwxr-xr-x  root root system_u:object_r:nfs_t:s0       var

これは明らかのおかしい話しではあるが、これを解決する方法は見つからなかった。NFSを通しても元のコンテキストでアクセスできないとネットワーク環境でファイルを透過的に使えなくなってしまう。デフォルトが透過的ではなくてパラメータの設定によって変更できるのか探してみたが見つからなかった。となると私が知っている唯一の方法はクライアントはSELinuxをdisabledにする方法である。

クライアントのSELinuxをdisabledにするにはサーバ側で/tftpboot/f8/root/etc/selinux/configの中のSELINUXをdisabledに変更する。

[root@vmserver ~]# cat /tftpboot/f8/root/etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#       targeted - Targeted processes are protected,
#       mls - Multi Level Security protection.
SELINUXTYPE=targeted
# SETLOCALDEFS= Check local definition changes
SETLOCALDEFS=0