SE-PostgreSQL用のRPMパッケージを作るべく、ゴニョゴニョやっていたらこんな時間に…。(現在4:08AM)
ひとまず、RPMパッケージの形で提供できるモノを作った。
もう少しチェックを加えて、コミュニティにはα版としてリリースしたいと思う。ちょっと試してみたいという親切な方が居られれば、ぜひとも↓からダウンロードして試して頂きたい。
環境は Fedora Core 6 で SELinux がインストールされていることを前提とする。
セキュリティポリシー
http://www.kaigai.gr.jp/pub/selinux-policy-2.5.2-5.sepgsql.noarch.rpm
http://www.kaigai.gr.jp/pub/selinux-policy-targeted-2.5.2-5.sepgsql.noarch.rpm
http://www.kaigai.gr.jp/pub/selinux-policy-2.5.2-5.sepgsql.src.rpm (ソース)
SE-PostgreSQL本体
http://www.kaigai.gr.jp/pub/sepostgresql-8.2.3-0.179a.i386.rpm
http://www.kaigai.gr.jp/pub/sepostgresql-8.2.3-0.179a.src.rpm (ソース)
最初にセキュリティポリシーをインストールし、次にSE-PostgreSQLをインストールする。
# rpm -Uvh selinux-policy-2.5.2-5.sepgsql.noarch.rpm \この順番を厳守しないと、SE-PostgreSQL用のポリシーモジュールがリンクできない。
selinux-policy-targeted-2.5.2-5.sepgsql.noarch.rpm
# rpm -ivh sepostgresql-8.2.3-0.179a.i386.rpm
インストールが完了したら、先ず初期データベースを作成し、続いてサーバプロセスを起動する。
# /etc/init.d/sepostgresql initdb
# /etc/init.d/sepostgresql start
問題がなければ、これでデータベースが利用可能になるはずだ。
テスト用のDBユーザを作成する。createdbコマンドやpsqlコマンドは、postgresqlのパッケージに含まれているものと互換なので、インストールされていなければそれも導入する。
# su - sepgsql
$ createuser kaigai ← お好みで
$ exit
# su - kaigai
$ psql postgres
これで、SE-PostgreSQLにログインできるはず。
まずは自分のセキュリティコンテキストを見てみる。
[kaigai@masu ~]$ psql -q postgres postgres=# select sepgsql_getcon(); sepgsql_getcon ------------------------------------------------- root:system_r:unconfined_t:SystemLow-SystemHigh (1 row) postgres=#
こんな感じ。
以下のサンプルを使えば、実際にアクセス制御の様子が見て取れます。unconfined_t かつ SystemLow-SystemHighのユーザでDBに流し込んでみてください。
create table drink ( id serial primary key, name text, price integer, cost integer, alcohol bool ); insert into drink(name, price, cost, alcohol) values('coffee', 120, 80, false); insert into drink(name, price, cost, alcohol) values('tea', 120, 70, false); insert into drink(name, price, cost, alcohol) values('wine', 360, 260, true); insert into drink(name, price, cost, alcohol) values('beer', 240, 180, true); insert into drink(name, price, cost, alcohol) values('water', 110, 40, false); insert into drink(name, price, cost, alcohol) values('coke', 110, 50, false); update drink set security_context = 'user_u:object_r:sepgsql_table_t:SystemHigh' where alcohol = true; create table person ( uid serial primary key, uname text, passwd varchar(24) ); insert into person (uname, passwd) values('KaiGai', 'aaa'); insert into person (uname, passwd) values('ymj', 'bbb'); insert into person (uname, passwd) values('tak', 'xyz'); create function check_person_passwd (integer, text) returns bool language 'sql' as 'select passwd = $2 from person where uid=$1'; alter table person alter passwd context = 'user_u:object_r:sepgsql_secret_table_t'; alter function check_person_passwd (integer, text) context = 'user_u:object_r:sepgsql_trusted_proc_t';
ヒント1:runcon -t initrc_t で psql を実行すると権限の弱いユーザになります。sepgsql_secret_table_t のカラムにアクセスできません。
ヒント2:boolean値の sepgsql_enable_audit(allow|deny|tuple) を操作すると、どういうアクセス制御が行われているか見えます。
setsebool -P sepgsql_enable_auditallow=1 sepgsql_enable_audittuple=1
正直そろそろ眠いです。お休みなさい。