postfix2.5.5がFedora8で起動しない

2008/11/6追記 selinuxのポリシーファイル(selinux-policy-3.0.8-121.fc8)がyumで更新された場合もrailsでメールできなくなった。

Fedora8でyumの自動更新を使っていると2008/10/11にpostfixが2.4.5から2.5.5にバージョンアップされました。

selinuxの設定をenforcingにしている場合、postfixの起動時にエラーが発生します。

問題の原因は、postfix2.5.5に対応するselinuxの設定を変更する必要があるからです。

この問題を回避する手順を以下に述べます。

1. main.cfの設定が変更されているの注意してください。diffを実行して内容を確認しましょうね。今回の場合、data_directory = /var/lib/postfixが追加されていますので、現在のmain.cfへの反映をお忘れなく。

$ cd /etc/postfix
$ diff main.cf.rpmnew main.cf.ORG
....
.....
$ vi main.cf
# The data_directory parameter specifies the location of Postfix-writable
# data files (caches, random numbers). This directory must be owned
# by the mail_owner account (see below).
#
data_directory = /var/lib/postfix


2. postfix用のSELinuxの設定を保存するディレクトリを作成

$ mkdir /etc/selinux/postfix

3. postfix 2.5.5用のTE(Type Enforcement)を作成。僕の場合、setenforce 0にしてaudit2allowコマンドで下記の内容を集めました。

$ vi postfix.te
policy_module(postfix, 2.5.5)

require {
        type postfix_bounce_exec_t;
        type postfix_cleanup_exec_t;
        type postfix_cleanup_exec_t;
        type postfix_etc_t;
        type postfix_exec_t;
        type postfix_local_exec_t;
        type postfix_master_t;
        type postfix_map_exec_t;
        type postfix_private_t;
        type postfix_public_t;
        type postfix_pipe_exec_t;
        type postfix_pickup_exec_t;
        type postfix_private_t;
        type postfix_postdrop_exec_t;
        type postfix_postqueue_exec_t;
        type postfix_public_t;
        type postfix_qmgr_exec_t;
        type postfix_spool_t;
        type postfix_spool_maildrop_t;
        type postfix_spool_bounce_t;
        type postfix_spool_flush_t;
        type postfix_showq_exec_t;
        type postfix_showq_exec_t;
        type postfix_smtp_exec_t;
        type postfix_smtpd_exec_t;
        type postfix_var_run_t;
        type postfix_virtual_exec_t;
        type sendmail_t;
        type mqueue_spool_t;
        type var_log_t;
        type var_lib_t;
        type man_t;
        class sock_file { setattr create unlink };
        class fifo_file { create unlink setattr };
        class file { execute read lock create execute_no_trans write getattr };
        class dir { read write remove_name add_name };
        class sock_file write;
        class unix_stream_socket connectto;
        class dir { write read remove_name add_name };
        class file { rename execute setattr read lock create ioctl execute_no_trans write getattr unlink };
        class fifo_file { write read getattr };
}


#============= sendmail_t ==============
allow sendmail_t postfix_cleanup_exec_t:file { read execute execute_no_trans };
allow sendmail_t postfix_exec_t:file { read execute ioctl execute_no_trans getattr };
allow sendmail_t postfix_private_t:sock_file write;
allow sendmail_t postfix_public_t:fifo_file { write read getattr };
allow sendmail_t postfix_public_t:sock_file write;
allow sendmail_t postfix_showq_exec_t:file { read execute execute_no_trans };
allow sendmail_t postfix_smtp_exec_t:file { read execute execute_no_trans };
allow sendmail_t postfix_spool_maildrop_t:dir { read remove_name write };
allow sendmail_t postfix_spool_maildrop_t:file { read getattr unlink };
allow sendmail_t postfix_spool_t:dir { read write add_name remove_name };
allow sendmail_t postfix_spool_t:file { rename setattr read lock create write getattr unlink };
allow sendmail_t postfix_var_run_t:file { read write getattr lock };
allow sendmail_t self:unix_stream_socket connectto;
allow sendmail_t man_t:file getattr;
allow sendmail_t postfix_bounce_exec_t:file getattr;
allow sendmail_t postfix_cleanup_exec_t:file getattr;
allow sendmail_t postfix_etc_t:dir read;
allow sendmail_t postfix_local_exec_t:file { read getattr execute execute_no_trans };
allow sendmail_t postfix_map_exec_t:file getattr;
allow sendmail_t postfix_pickup_exec_t:file { read getattr execute execute_no_trans };
allow sendmail_t postfix_pipe_exec_t:file getattr;
allow sendmail_t postfix_postdrop_exec_t:file getattr;
allow sendmail_t postfix_postqueue_exec_t:file getattr;
allow sendmail_t postfix_private_t:dir { read remove_name write add_name };
allow sendmail_t postfix_private_t:sock_file { create unlink setattr };
allow sendmail_t postfix_public_t:dir { read remove_name write add_name };
allow sendmail_t postfix_public_t:fifo_file { create unlink setattr };
allow sendmail_t postfix_public_t:sock_file { create unlink setattr };
allow sendmail_t postfix_qmgr_exec_t:file { read getattr execute execute_no_trans };
allow sendmail_t postfix_showq_exec_t:file getattr;
allow sendmail_t postfix_smtp_exec_t:file getattr;
allow sendmail_t postfix_smtpd_exec_t:file getattr;
allow sendmail_t postfix_spool_bounce_t:dir read;
allow sendmail_t postfix_spool_flush_t:dir read;
allow sendmail_t postfix_virtual_exec_t:file getattr;
allow sendmail_t var_lib_t:dir { write add_name };
allow sendmail_t var_lib_t:file { read write create lock };
allow sendmail_t var_lib_t:file getattr;

#============= postfix_master_t ==============
allow postfix_master_t var_lib_t:file { read write getattr };
allow postfix_master_t var_lib_t:file lock;

require {
        type postfix_postdrop_t;
        type sendmail_t;
        type httpd_t;
        type postfix_etc_t;
        class unix_stream_socket { read write };
        class file read;
}

#============= httpd_t ==============
allow httpd_t postfix_etc_t:file read;
allow httpd_t postfix_etc_t:file getattr;

#============= postfix_postdrop_t ==============
allow postfix_postdrop_t sendmail_t:unix_stream_socket { read write };
allow postfix_postdrop_t sendmail_t:unix_stream_socket getattr;

4. TEファイルをPPファイルにコンパイル

$ make -f /usr/share/selinux/devel/Makefile

5. SELinuxpostfixのポリシーを反映

$ semodule -i postfix.pp

6. Fedora 8の再起動。これでめでたく、postfixが動作すると思います。

yumでパッケージを自動更新していると、ときどきプログラムが動作しなくなるので困りますねぇ。でもセキュリティのパッチだったりするので安心にはかえられません。