2008-02-03 DokuWiki + SELinux (その1)
■[SELinux] DokuWiki + SELinux 
ようやくまともな時間が出来たので久しぶりに書きます。
前置き
現在、ITProで連載中の「第一人者がやさしく教える新SELinux入門」を参考に
DokuWiki + SELinux(strict policy) を実践してみました。
# そのままPukiWikiでも良かったのですが芸がない気がして…。
参考URL:
第一人者がやさしく教える新SELinux入門
http://itpro.nikkeibp.co.jp/article/COLUMN/20070827/280411/
第7回 モジュール・パッケージを作成する
http://itpro.nikkeibp.co.jp/article/COLUMN/20070828/280548/?ST=lin-os
環境構築
まずDokuWikiの動作環境を構築します。
本日の環境は以下の通り。
今回はDokuWiki以外、全てyumでインストールをしています。
- CentOS 5.1 (Kernel 2.6.18-53.1.6.el5)
- selinux-policy-* (2.4.6-106.el5_1.3)
- Apache (2.2.3-11.el5_1.centos.3)
- PHP (5.1.6-15.el5)
- DokuWiki (2007-06-26b)
環境構築後、ラベルを張り直します。
# touch /.autorelabel
# reboot
再起動後、booleanパラメータの「httpd_builtin_scripting」の値を記事と環境を合わせるため『OFF』にします。
「httpd_builtin_scripting」は、httpdデーモンのコンテンツに対する書き許可/不許可を制御するパラメータです。
# getsebool httpd_builtin_scripting
httpd_builtin_scripting --> on
# setsebool -P httpd_builtin_scripting=0
以上で準備は完了です。
モジュール・パッケージを作成する (該当記事: 第7回)
まずは第7回にある様に、DokuWikiに独自のタイプを付与せずにアクセス許可を与えます。
permissiveモードでのテスト
まず、permissiveモードで動作をさせ、どのようなアクセスが発生するのかを確認します。
# setenforce 0
# newrole -r sysadm_r
# run_init /etc/init.d/auditd restart
# ps auxZ | grep httpd
system_u:system_r:httpd_t root 2494 1.8 0.9 17860 5120 ? Ss 06:29 0:00 /usr/sbin/httpd
system_u:system_r:httpd_t apache 2496 0.2 0.5 17992 3020 ? S 06:29 0:00 /usr/sbin/httpd
…
表示や編集をすると、audit.logに以下のようなログが出力されます。
type=AVC msg=audit(1201987902.315:216): avc: denied { write } for pid=2500 comm="httpd" name="pages" dev=dm-0 ino=3506475 scontext=system_u:system_r:httpd_t:s0 tcontext=root:object_r:httpd_sys_content_t:s0 tclass=dir
type=SYSCALL msg=audit(1201987902.315:216): arch=40000003 syscall=33 success=yes exit=0 a0=8414d2c a1=2 a2=12b825c a3=0 items=0 ppid=2494 pid=2500 auid=0 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) comm="httpd" exe="/usr/sbin/httpd" subj=system_u:system_r:httpd_t:s0 key=(null)
type=AVC msg=audit(1201987902.553:217): avc: denied { write } for pid=2500 comm="httpd" name="users.auth.php" dev=dm-0 ino=3508495 scontext=system_u:system_r:httpd_t:s0 tcontext=root:object_r:httpd_sys_content_t:s0 tclass=file
type=SYSCALL msg=audit(1201987902.553:217): arch=40000003 syscall=33 success=yes exit=0 a0=863188c a1=2 a2=12b825c a3=0 items=0 ppid=2494 pid=2500 auid=0 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) comm="httpd" exe="/usr/sbin/httpd" subj=system_u:system_r:httpd_t:s0 key=(null)
type=AVC msg=audit(1201987904.723:218): avc: denied { add_name } for pid=2496 comm="httpd" name="b842c1342cf104605e068c00e78d4cbe" scontext=system_u:system_r:httpd_t:s0 tcontext=root:object_r:httpd_sys_content_t:s0 tclass=dir
type=AVC msg=audit(1201987904.723:218): avc: denied { create } for pid=2496 comm="httpd" name="b842c1342cf104605e068c00e78d4cbe" scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:httpd_sys_content_t:s0 tclass=dir
type=SYSCALL msg=audit(1201987904.723:218): arch=40000003 syscall=39 success=yes exit=0 a0=8758114 a1=1ed a2=12b825c a3=8758114 items=0 ppid=2494 pid=2496 auid=0 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) comm="httpd" exe="/usr/sbin/httpd" subj=system_u:system_r:httpd_t:s0 key=(null)
type=AVC msg=audit(1201987904.727:219): avc: denied { create } for pid=2496 comm="httpd" name="974e3ab0d237d95be8c446a6c93c90bd.i" scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:httpd_sys_content_t:s0 tclass=file
type=SYSCALL msg=audit(1201987904.727:219): arch=40000003 syscall=5 success=yes exit=11 a0=8758114 a1=241 a2=1b6 a3=4 items=0 ppid=2494 pid=2496 auid=0 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) comm="httpd" exe="/usr/sbin/httpd" subj=system_u:system_r:httpd_t:s0 key=(null)
type=AVC msg=audit(1201987904.730:220): avc: denied { write } for pid=2496 comm="httpd" path="/var/www/html/dokuwiki/data/cache/9/974e3ab0d237d95be8c446a6c93c90bd.i" dev=dm-0 ino=3508543 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:httpd_sys_content_t:s0 tclass=file
type=SYSCALL msg=audit(1201987904.730:220): arch=40000003 syscall=4 success=yes exit=824 a0=b a1=878d9ec a2=338 a3=878d9ec items=0 ppid=2494 pid=2496 auid=0 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) comm="httpd" exe="/usr/sbin/httpd" subj=system_u:system_r:httpd_t:s0 key=(null)
type=AVC msg=audit(1201987904.732:221): avc: denied { remove_name } for pid=2496 comm="httpd" name="b842c1342cf104605e068c00e78d4cbe" dev=dm-0 ino=3508542 scontext=system_u:system_r:httpd_t:s0 tcontext=root:object_r:httpd_sys_content_t:s0 tclass=dir
type=AVC msg=audit(1201987904.732:221): avc: denied { rmdir } for pid=2496 comm="httpd" name="b842c1342cf104605e068c00e78d4cbe" dev=dm-0 ino=3508542 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:httpd_sys_content_t:s0 tclass=dir
type=SYSCALL msg=audit(1201987904.732:221): arch=40000003 syscall=40 success=yes exit=0 a0=8758114 a1=0 a2=12b825c a3=8758114 items=0 ppid=2494 pid=2496 auid=0 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) comm="httpd" exe="/usr/sbin/httpd" subj=system_u:system_r:httpd_t:s0 key=(null)
type=AVC msg=audit(1201987924.265:222): avc: denied { append } for pid=2502 comm="httpd" path="/var/www/html/dokuwiki/data/meta/start.changes" dev=dm-0 ino=3508550 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:httpd_sys_content_t:s0 tclass=file
type=SYSCALL msg=audit(1201987924.265:222): arch=40000003 syscall=4 success=yes exit=47 a0=b a1=88ea43c a2=2f a3=88ea43c items=0 ppid=2494 pid=2502 auid=0 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) comm="httpd" exe="/usr/sbin/httpd" subj=system_u:system_r:httpd_t:s0 key=(null)
type=AVC msg=audit(1201987924.273:223): avc: denied { unlink } for pid=2502 comm="httpd" name="ea2b2676c28c0db26d39331a336c6b92.lock" dev=dm-0 ino=3508545 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:httpd_sys_content_t:s0 tclass=file
type=SYSCALL msg=audit(1201987924.273:223): arch=40000003 syscall=10 success=yes exit=0 a0=87203c4 a1=0 a2=12b825c a3=87203c4 items=0 ppid=2494 pid=2502 auid=0 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) comm="httpd" exe="/usr/sbin/httpd" subj=system_u:system_r:httpd_t:s0 key=(null)
type=AVC msg=audit(1201987924.677:224): avc: denied { rename } for pid=2496 comm="httpd" name="page.tmp" dev=dm-0 ino=3508553 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:httpd_sys_content_t:s0 tclass=file
type=AVC msg=audit(1201987924.677:224): avc: denied { unlink } for pid=2496 comm="httpd" name="page.idx" dev=dm-0 ino=3508479 scontext=system_u:system_r:httpd_t:s0 tcontext=root:object_r:httpd_sys_content_t:s0 tclass=file
type=SYSCALL msg=audit(1201987924.677:224): arch=40000003 syscall=38 success=yes exit=0 a0=8477da4 a1=85d741c a2=12b825c a3=123834b items=0 ppid=2494 pid=2496 auid=0 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) comm="httpd" exe="/usr/sbin/httpd" subj=system_u:system_r:httpd_t:s0 key=(null)
がっつり怒られました。
audit2allowでteファイルを作成
続いて、audit2allowを使用してteファイルを作成します。
# コマンドの解説は記事をご参照ください。
# mkdir ~/policy_work
# audit2allow -a -l -m local > ~/policy_work/local.te
きっと、httpd_tに関係ないログまで出力されていると思います。
今回は出力された物の中からhttp_tに関係あるものだけを抽出します。
不要なものはばっさりと消してしまいます。
消すのが面倒な場合は、audit.logを消去し、再度DokuWikiにアクセスを行います。
# echo > /var/log/audit/audit.log
# run_init /etc/init.d/httpd restart
(ここでアクセス)
# audit2allow -a -l -m local > ~/policy_work/local.te
出力結果:
module local 1.0;
require {
type httpd_t;
type httpd_sys_content_t;
class dir { remove_name create add_name rmdir };
class file { create unlink };
}
#============= httpd_t ==============
allow httpd_t httpd_sys_content_t:dir { remove_name create add_name rmdir };
allow httpd_t httpd_sys_content_t:file { create unlink };
パッケージに変換
local.teファイルをモジュール・パッケージに変換します。
変換を行うためにはmakeコマンドを実行します。(ベンリ!)
makeを行うにはMakefileが必要なのでMakefileを取得します。
# cp /usr/share/selinux/devel/Makefile ~/policy_work
# ls ~/policy_work
Makefile local.te
selinux-policy-develが入っていないとディレクトリごと存在しなかったような…。
準備が整ったところで、makeコマンドを実行します。
# cd ~policy_work
# make
Compiling strict local module
/usr/bin/checkmodule: loading policy configuration from tmp/local.tmp
/usr/bin/checkmodule: policy configuration loaded
/usr/bin/checkmodule: writing binary representation (version 6) to tmp/local.mod
Creating strict local.pp policy package
rm tmp/local.mod.fc tmp/local.mod
# ls
Makefile local.fc local.if local.pp local.te tmp
設定を反映
なにやら色々と出来上がりました。
「local.pp」が変換されたモジュール・パッケージです。
早速、local.ppを適用します。
# semodule -i local.pp
# semodule -l | grep local
local 1.0
動作確認と修正
SELinuxをEnforcingに変更し、DokuWikiにアクセスを行ってみます。
# setenforce 1
(ここでアクセス)
残念ながらトップページでエラーが出力されてしまいました。
audit.logにもお叱りの言葉が吐かれています。
type=AVC msg=audit(1201989317.644:284): avc: denied { write } for pid=2884 comm="httpd" name="pages" dev=dm-0 ino=3506475 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:httpd_sys_content_t:s0 tclass=dir
type=SYSCALL msg=audit(1201989317.644:284): arch=40000003 syscall=33 success=no exit=-13 a0=9865ba4 a1=2 a2=12c625c a3=0 items=0 ppid=2877 pid=2884 auid=0 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) comm="httpd" exe="/usr/sbin/httpd" subj=system_u:system_r:httpd_t:s0 key=(null)
ディレクトリへの書き込み権限が不足しているようです。
再度、SELinuxをPermissiveに設定し、audit2allowでの設定追加とモジュール・パッケージのインストールを行います。
# setenforce 0
# audit2allow -a -l -r
require {
type httpd_t;
type httpd_sys_content_t;
class dir write;
}
#============= httpd_t ==============
allow httpd_t httpd_sys_content_t:dir write;
編集して出来上がったlocal.teが以下になります。
module local 1.0;
require {
type httpd_t;
type httpd_sys_content_t;
class dir { remove_name create add_name rmdir write };
class file { create unlink };
}
#============= httpd_t ==============
allow httpd_t httpd_sys_content_t:dir { remove_name create add_name rmdir write };
allow httpd_t httpd_sys_content_t:file { create unlink };
local.teが出来上がったところで再度適用を行います。
# semodule -r local
# make clean
# make
# semodule -i local.pp
# setenforce 1
(ここでアクセス)
無事、アクセスすることができました。
今回は管理などの機能をしようしていないので、また何かエラーでるかも知れません。
その時は上記の手順を繰り返し設定を修正してください。
次回予告
次回は、DokuWikiに独自のタイプを付与した上でアクセス許可を与えます。
緩過ぎますからね…。
- 3 http://search.goo.ne.jp/blogreader.jsp?url=http://d.hatena.ne.jp/ishikawa84g/20080203/1201986129&MT=CentOS5.1+インストール&DC=10&RD=&IU=&snum=1
- 3 http://www.google.co.jp/search?hl=ja&q=mcstrans&lr=lang_ja
- 3 http://www.google.co.jp/search?q=postgresql8.3+RC2&lr=lang_ja&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:ja:official&client=firefox
- 2 http://d.hatena.ne.jp/keyword/SELinux
- 2 http://search.yahoo.co.jp/search?p=+mcstrans&search.x=1&fr=top_ga1&tid=top_ga1&ei=UTF-8
- 2 http://www.google.com/search?hl=ja&lr=lang_ja&ie=UTF-8&oe=UTF-8&q=ishikawa84g&num=50
- 1 http://72.14.235.104/search?q=cache:VuYDGtmi81gJ:d.hatena.ne.jp/ishikawa84g/20071014+Linux+莎桁??audit+selinux+auid&hl=ja&ct=clnk&cd=1&gl=jp&lr=lang_ja
- 1 http://d.hatena.ne.jp/diarylist
- 1 http://d.hatena.ne.jp/diarylist?of=0&mode=rss&type=public
- 1 http://d.hatena.ne.jp/keyword/トップページ