[Linux][Apache] SELinux 上での mod_proxy_ajp
SELinux の有効になっているサーバ上で Apache 2.2 + Tomcat 6 の連携をやろうとしてちょっとはまった。
普通に proxy_ajp.conf を設定したのだが、
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so ProxyPass /webapp/ ajp://127.0.0.1:8009/webapp/
error_log に以下のようなエラーがでて接続できない。
[error] (13)Permission denied: proxy: AJP: attempt to connect to 127.0.0.1:8009 (127.0.0.1) failed [error] ap_proxy_connect_backend disabling worker for (127.0.0.1) [error] proxy: AJP: failed to make connection to backend: 127.0.0.1 [error] proxy: AJP: disabled connection for (127.0.0.1)
/var/log/messages を見てみると、以下のエラーが出ていた(*** は実際には16進らしき数字)。
setroubleshoot: SELinux is preventing the http daemon from connecting to network port 8009 For complete SELinux messages. run sealert -l ********-****-****-****-************
で、messages に記載されている sealert コマンドを実行すると、以下の出力を得た。
Summary: SELinux is preventing the http daemon from connecting to network port 8009 Detailed Description: SELinux has denied the http daemon from connecting to 8009. An httpd script is trying to do a network connect to a remote port. If you did not setup httpd to network connections, this could signal a intrusion attempt. Allowing Access: If you want httpd to connect to network ports you need to turn on the httpd_can_network_network_connect boolean: "setsebool -P httpd_can_network_connect=1" The following command will allow this access: setsebool -P httpd_can_network_connect=1 Additional Information: Source Context user_u:system_r:httpd_t Target Context system_u:object_r:port_t Target Objects None [ tcp_socket ] Source httpd Source Path /usr/sbin/httpd Port 8009 Host *******.********.**.** Source RPM Packages httpd-2.2.3-22.el5 Target RPM Packages Policy RPM selinux-policy-2.4.6-203.el5 Selinux Enabled True Policy Type targeted MLS Enabled True Enforcing Mode Enforcing Plugin Name httpd_can_network_connect Host Name *******.********.**.** Platform Linux *******.********.**.** 2.6.18-128.1.1.el5xen #1 SMP Mon Jan 26 14:19:09 EST 2009 x86_64 x86_64 Alert Count 6 First Seen Thu Apr 16 11:43:17 2009 Last Seen Thu Apr 16 11:55:37 2009 Local ID ********-****-****-****-************ ....
どうも SELinux の httpd_can_network_connect という設定で、httpd プロセスからのネットワーク接続を制限しているらしい。setsebool コマンドで設定を変更できるとかいてあるので、その通りやってみたら問題が解決した。getsebool コマンドで設定値を確認できる。
# getsebool httpd_can_network_connect httpd_can_network_connect --> off # setsebool -P httpd_can_network_connect 1 # getsebool httpd_can_network_connect httpd_can_network_connect --> on
しかし、SELinux ってどれだけ普及してるんやろうね。難解すぎて結局あまり普及してない気がする。