« 06.19 COPYはスーパーユーザの権利 | ココ | 06.20 「深く」考えずに仕事をする »

2007年6月19日

ポリシーは作れども  このエントリーを含むはてなブックマーク 

SELinuxでは、プログラムがリソースとしてファイルの状態であれば「タイプ」、実行されているプロセスの状態では「ドメイン」と、同じセキュリティコンテキストが「タイプ」でも呼び方が変わる。一般的に、あるドメインが、異なるドメインに属するタイプのファイルにアクセスする場合はアクセス許可がなければならない。

これが単純な場合やと、アクセスを許可するポリシーファイル(.te)を作るだけでいいんで楽なんですが。場合によっては『このプログラムだけ特別扱いしたい』とかそういうことが起こるとややこしい。特に、ドメインがhttpd_sys_script_t(CGI)のとき。


[selinux-users:00672] Re: XOOPSGalleryからNetpbmが使用できない

これを見てみると,実行されているプログラムは
/home/xoops/public_html/netpbm/giftopnm
のようです。
こいつに,netpbm_exec_tとでもタイプをつけ,
実行可能にすれば完璧です。

- domains/programs/apache.te
type netpbm_exec_t, file_type,sysadmfile;
can_exec(httpd_sys_script_t,netbpm_exec_t)
- file_contexts/programs/apache.fc
/home/xoops/public_html/netpbm/giftopnm system_u:object_r:netbpm_exec_t
他にも実行されているプログラムがあれば,apache.fcに追加して下さい。

ここまでは分かるのよね。
そんで、そのプログラムに対するポリシーを作るツールがある(自分で直書きしてもいいけど)。

# /usr/share/selinux/devel/policygentool ポリシー名 /path/to/program

This tool generate three files for policy development, A Type Enforcement (te) file, a File Context (fc), and a Interface File(if). Most of the policy rules will be written in the te file. Use the File Context file to associate file paths with security context. Use the interface rules to allow other protected domains to interact with the newly defined domains.

After generating these files use the /usr/share/selinux/devel/Makefile to compile your policy package. Then use the semodule tool to load it.

# /usr/share/selinux/devel/policygentool myapp /usr/bin/myapp
# make -f /usr/share/selinux/devel/Makefile
# semodule -l myapp.pp
# restorecon -R -v /usr/bin/myapp "all files defined in myapp.fc"

Now you can turn on permissive mode, start your application and avc messages will be generated. You can use audit2allow to help translate the avc messages into policy.

# setenforce 0
# service myapp start
# audit2allow -R -i /var/log/audit/audit.log

Return to continue:

If the module uses pidfiles, what is the pidfile called?

If the module uses logfiles, where are they stored?

If the module has var/lib files, where are they stored?

Does the module have a init script? [yN]

Does the module use the network? [yN]

これで、指定した場所にポリシーファイル(.te, .if, .fc)ができあがるので、適宜編集してmakeしてsemoduleする。

で、問題はここから先なんですよ。あるドメインが、別タイプのプログラムを呼び出し、そいつがさらにファイルにアクセスするときに、アクセス対象となるファイルにアクセスするためには呼び出されたプログラムのドメインでなければアクセスできない。なんかややこしいけど、要は呼び出し元のドメインでは起動したプログラムがファイルにアクセスできない。それを解決するのが、「ドメイン遷移」。

Refpolicy三昧(ref. himainuの日記)

ドメイン遷移設定
myapp.teに以下を追加。

domain_auto_trans(unconfined_t, myapp_exec_t, myapp_t)

これで、ドメインが別のタイプのプログラムを起動したとき、起動したプログラムのドメインに一時的に変化する。

しかし…。sysytem関数でプログラムを呼び出したとき、なぜかドメイン遷移が起こらんのよね。httpd_sys_script_tのまま、postgresql_db_tが呼び出されて『アクセスできません』と。ドメイン変わってくれよ。というか、httpd_sys_script_tで別タイプのプログラム(.sh)実行できてるし。なにがおかしいのか。system関数があかんのか? ようわからん。SELinuxは深い。

By ただ at 22:55 カテゴリー ; mein Erbe

« 06.19 COPYはスーパーユーザの権利 | 06月の記事 | 06.20 「深く」考えずに仕事をする »




トラックバック

このエントリーのトラックバックURL:
http://pinmarch.sakura.ne.jp/mt/mt-tb.cgi/992