R.A. Epigonos et al.

[virtualbox] SELinux on Debian on VirtualBox

VirtualBox 上の Debian で SELinux 環境を作るまでのまとめ

ホスト側の作業

新しくインストールの hdd イメージ (10GiB) を作成。ゲスト仮想マシンを作成。

%gt; "c:\Program Files\Oracle\VirtualBox\VBoxManage.exe" createhd --filename "SELinux-10GiB.vdi" --sizebyte 10737418240
%gt; "c:\Program Files\Oracle\VirtualBox\VBoxManage.exe" createvm --name "dih_SELinux" --register
%gt; "c:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "dih_SELinux" --ostype "Debian_64" --memory 1024 --vram 128 --pae off
%gt; "c:\Program Files\Oracle\VirtualBox\VBoxManage.exe" showvminfo "dih_SELinux"

VirtualBox ゲストに ssh で接続する場合は、VirtualBox 仮想マシン設定でNATからホストオンリーアダプタまたはブリッジアダプタにしておく。VirtualBox ゲスト内の LXC コンテナでネットワークを使うには、VirtualBox 仮想マシン設定でプロミスキャスモードをすべて許可にしておく。

debian インストール DVD で作成した hdd イメージにシステムをインストール。

ゲスト側の作業

cdrom: を コメントアウト

# sed -i \
	-e 's/^\(deb\(-src\|\) cdrom:\)/# \1/' \
	/etc/apt/sources.list \
	;

openssh-server のインストール。

# apt-get install --no-install-recommends openssh-server;

ssh でゲストマシンにログインした後のゲスト側の作業

RecommendsとSuggestsパッケージは手作業で入れる方針。設定反映確認。

# cat << 'EOT' > "/etc/apt/apt.conf.d/01norecommend";
APT::Install-Recommends "0";
APT::Install-Suggests "0";
EOT
# apt-config dump \
	| grep -e 'APT::Install-';
APT::Install-Recommends "0";
APT::Install-Suggests "0";

apt ソースに unstable を追加 (selinux-policy-default を unstable から持ってくる必要がなければ、この操作も不要)。設定反映確認。

# cat << 'EOT' > "/etc/apt/apt.conf.d/01default-release";
APT::Default-Release "stable";
EOT
# cat << 'EOT' > "/etc/apt/sources.list.d/01unstable.list";
deb http://ftp.jp.debian.org/debian/ unstable main
EOT
# cat << 'EOT' > "/etc/apt/preferences.d/01stable-update.pref";
Package: *
Pin: release a=stable-updates
Pin-Priority: 990
EOT
# apt-get update;
(snip)
# apt-cache policy
Package files:
 100 /var/lib/dpkg/status
     release a=now
 500 http://ftp.jp.debian.org/debian/ unstable/main Translation-en
 500 http://ftp.jp.debian.org/debian/ unstable/main amd64 Packages
     release o=Debian,a=unstable,n=sid,l=Debian,c=main
     origin ftp.jp.debian.org
 500 http://ftp.jp.debian.org/debian/ jessie-updates/main Translation-en
 990 http://ftp.jp.debian.org/debian/ jessie-updates/main amd64 Packages
     release o=Debian,a=stable-updates,n=jessie-updates,l=Debian,c=main
     origin ftp.jp.debian.org
 500 http://security.debian.org/ jessie/updates/main Translation-en
 990 http://security.debian.org/ jessie/updates/main amd64 Packages
     release v=8,o=Debian,a=stable,n=jessie,l=Debian-Security,c=main
     origin security.debian.org
 500 http://ftp.jp.debian.org/debian/ jessie/main Translation-en
 990 http://ftp.jp.debian.org/debian/ jessie/main amd64 Packages
     release v=8.2,o=Debian,a=stable,n=jessie,l=Debian,c=main
     origin ftp.jp.debian.org
Pinned packages:

SELinux に必要なパッケージをインストール。

# apt-get install selinux-basics selinux-policy-default
(snip)

設定変更。

# selinux-activate
Activating SE Linux
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.16.0-4-amd64
Found initrd image: /boot/initrd.img-3.16.0-4-amd64
done
SE Linux is activated.  You may need to reboot now.
# grep -v -e '^$' -e '^#' /etc/default/grub
GRUB_DEFAULT=0
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet"
GRUB_CMDLINE_LINUX=" selinux=1 security=selinux"
# ls -la /.autorelabel
-rw-r--r-- 1 root root 0 Dec 26 16:59 /.autorelabel
# find /etc/pam.d/ -type f -print0 | xargs -0 -r grep selinux
/etc/pam.d/sshd:session [success=ok ignore=ignore module_unknown=ignore default=bad]        pam_selinux.so close
/etc/pam.d/sshd:session [success=ok ignore=ignore module_unknown=ignore default=bad]        pam_selinux.so open
/etc/pam.d/login:session [success=ok ignore=ignore module_unknown=ignore default=bad] pam_selinux.so close
/etc/pam.d/login:session [success=ok ignore=ignore module_unknown=ignore default=bad] pam_selinux.so open

再起動。最初の再起動時にラベル付け (fixfiles relabel) が行われる。ラベル付けが終わると自動的にもう一回再起動がかかる。

# shutdown -r now

check-selinux-installation で SELinux が有効化されているか調べる。最初は FSCKFIX の問題がある様子(false positive?)。ということで修正して再起動。再チェックで何も表示されなくなったのでOK。

# check-selinux-installation
FSCKFIX is not enabled - not serious, but could prevent system from booting...
# echo 'FSCKFIX=yes' >> /etc/default/rcS
# grep -v -e '^$' -e '^#' /etc/default/rcS
FSCKFIX=yes
# shutdown -r now
# check-selinux-installation
#

プロセスのセキュリティコンテキストを表示するには ps -Z (ps --context) を使う。ユーザのセキュリティコンテキストを表示するには id -Z (id --context) を使う。ファイルのセキュリティコンテキストを表示するには ls -Z (ls --context) を使う。

$ ps -Z -C 'sshd'
LABEL                             PID TTY          TIME CMD
system_u:system_r:sshd_t:s0-s0:c0.c1023 406 ?  00:00:00 sshd
system_u:system_r:sshd_t:s0-s0:c0.c1023 427 ?  00:00:00 sshd
system_u:system_r:sshd_t:s0-s0:c0.c1023 429 ?  00:00:01 sshd
$ id -Z
unconfined_u:unconfined_r:unconfined_t:SystemLow-SystemHigh
$ ls -Z -1 ~/.profile /usr/bin/ssh
unconfined_u:object_r:user_home_t:SystemLow /home/raphael/.profile
     system_u:object_r:ssh_exec_t:SystemLow /usr/bin/ssh

SELinux モジュールの管理

現在インストール済みのモジュールのバージョンを見るには semodule --list-modules を使う。

# semodule --list-modules | head
accountsd       1.1.0
acct    1.6.0
ada     1.5.0
afs     1.9.0
aiccu   1.1.0
aide    1.8.0
aisexec 1.2.0
alsa    1.13.0
amanda  1.15.0
amavis  1.15.0

モジュールをインストールするには semodule --install を使う。

# semodule --install /usr/share/selinux/default/abrt.pp.bz2
# semodule --list-modules | grep -e '^abrt'
abrt    1.5.0   Disabled

モジュールを有効化するには semodule --enable を使う。

# semodule --enable abrt
# semodule --list-modules | grep -e '^abrt'
abrt    1.5.0

モジュールを無効化するには semodule --disable を使う。

# semodule --disable abrt
# semodule --list-modules | grep -e '^abrt'
abrt    1.5.0   Disabled

モジュールを削除するには semodule --remove を使う。

# semodule --remove abrt
# semodule --list-modules | grep -e '^abrt'

semodule は現在の設定、すなわち SELinux の設定ファイルの SELINUXTYPE で指定された設定に対して操作を行う。ここでは default という設定に対して操作を行う。設定できる値は default(selinux-policy-default) ,mls(selinux-policy-mls), src(selinux-policy-src)。今回は selinux-policy-default をインストールしたので default にした。カッコ内に書いた対応するバイナリパッケージは refpolicy からビルドされる。

# grep -v -e '^$' -e '^#' /etc/selinux/config
SELINUX=permissive
SELINUXTYPE=default
SETLOCALDEFS=0

Unix ログイン名と SELinux ユーザ名の対応付け

Unix ログイン名と SELinux ユーザ名の対応付け (ログインオブジェクト) を表示するには semanage login --list を使う。

# semanage login --list

Login Name           SELinux User         MLS/MCS Range        Service

__default__          unconfined_u         SystemLow-SystemHigh *
root                 unconfined_u         SystemLow-SystemHigh *
system_u             system_u             SystemLow-SystemHigh *

エントリを追加するには semanage login --add を使う。以下で raphael という Unix ログイン名を持つユーザに SELinux ユーザ名 user_u を与える。

# semanage login --add --seuser user_u raphael
# semanage login --list | grep -e '^raphael'
raphael              user_u               SystemLow            *

エントリを削除するには semanage login --delete を使う。以下で raphael という Unix ログイン名を持つユーザに対するエントリを削除する。

# semanage login --delete raphael
# semanage login --list | grep -e '^raphael'

SELinux ユーザ名とロールの対応付け

SELinux ユーザ名とロールの対応付けを表示するには semanage user --list を使う。

# semanage user --list

                Labeling   MLS/       MLS/
SELinux User    Prefix     MCS Level  MCS Range                      SELinux Roles

root            sysadm     SystemLow  SystemLow-SystemHigh           staff_r sysadm_r system_r
staff_u         staff      SystemLow  SystemLow-SystemHigh           staff_r sysadm_r
sysadm_u        sysadm     SystemLow  SystemLow-SystemHigh           sysadm_r
system_u        user       SystemLow  SystemLow-SystemHigh           system_r
unconfined_u    unconfined SystemLow  SystemLow-SystemHigh           system_r unconfined_r
user_u          user       SystemLow  SystemLow                      user_r

エントリを追加するには semanage user --add を使う。以下で test_u という SELinux ユーザ名を持つユーザに staff_r と user_r の SELinux ロールを与えて、ファイルラベル付けのプレフィックスに staff を指定している。

# semanage user --add --roles 'staff_r user_r' --prefix staff test_u
# semanage user --list | grep -e '^test_u'
test_u          staff      SystemLow  SystemLow                      staff_r user_r

エントリを削除するには semanage user --delete を使う。以下で test_u という SELinux ユーザ名に対するエントリを削除する。

# semanage user ---delete test_u
# semanage user --list | grep -e '^test_u'

リファレンス

  1. Chapter 8. VBoxManage
  2. Ubuntu Manpage: sources.list - List of configured APT data sources
  3. StableUpdates - Debian Wiki
  4. SELinux/Setup - Debian Wiki
  5. Debian -- sid の refpolicy ソースパッケージに関する詳細

ソーシャルブックマーク

  1. はてなブックマーク
  2. Google Bookmarks
  3. del.icio.us

ChangeLog

  1. Posted: 2008-05-19T15:57:25+09:00
  2. Modified: 2008-05-19T15:57:25+09:00
  3. Generated: 2023-08-27T23:09:15+09:00