Show Table of Contents
第13章 Apache HTTP Server
Apache HTTP Server は、現行の HTTP 標準を備えたオープンソースの HTTP サーバーを提供します[17]。
Red Hat Enterprise Linux では、httpd パッケージが Apache HTTP Server を提供します。httpd パッケージがインストールされていることを確認するには、以下のコマンドを実行します。
~]$ rpm -q httpd
package httpd is not installed
パッケージがインストールされておらず Apache HTTP Server を使用したい場合は、root で
yum ユーティリティーを使用してインストールします。
~]# yum install httpd13.1. Apache HTTP Server と SELinux
SELinux を有効にすると、Apache HTTP Server (
httpd) はデフォルトで制限のあるサービスとして実行されます。制限のあるプロセスはそのプロセス自体のドメインで実行され、他の制限のあるプロセスとは分離されます。制限のあるプロセスが攻撃を受けると、SELinux ポリシー設定に応じて、攻撃側がリソースにアクセスして加えることができる被害は限定されます。以下の例では、httpd プロセス自体のドメイン内で実行しているプロセスを示します。ここでは、httpd、setroubleshoot、setroubleshoot-server、policycoreutils-python の各パッケージがインストールされていることを前提としています。
getenforceコマンドを実行して、SELinux が enforcing モードで実行していることを確認します。~]$
getenforceEnforcingSELinux が enforcing モードで実行していれば、Enforcingが返されます。- root で以下のコマンドを実行して、
httpdを起動します。~]#
systemctl start httpd.serviceサービスが稼働していることを確認します。出力は以下のようになり、タイムスタンプのみが異なります。~]#
systemctl status httpd.servicehttpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled) Active: active (running) since Mon 2013-08-05 14:00:55 CEST; 8s ago httpdプロセスを表示するには、以下のコマンドを実行します。~]$
ps -eZ | grep httpdsystem_u:system_r:httpd_t:s0 19780 ? 00:00:00 httpd system_u:system_r:httpd_t:s0 19781 ? 00:00:00 httpd system_u:system_r:httpd_t:s0 19782 ? 00:00:00 httpd system_u:system_r:httpd_t:s0 19783 ? 00:00:00 httpd system_u:system_r:httpd_t:s0 19784 ? 00:00:00 httpd system_u:system_r:httpd_t:s0 19785 ? 00:00:00 httpdhttpdプロセスに関連する SELinux コンテキストはsystem_u:system_r:httpd_t:s0です。コンテキストの末尾から 2 番目の部分であるhttpd_tがタイプになります。タイプはプロセスのドメインやファイルのタイプを定義します。この例の場合、httpdプロセスはhttpd_tドメインで実行されています。
SELinux ポリシーは、
httpd_t などの制限のあるドメイン内で実行しているプロセスがファイルや他のプロセス、システムなどとどのように交信するのかを定義します。httpd がファイルにアクセスができるよう、ファイルには適切なラベルを付ける必要があります。たとえば、httpd_sys_content_t タイプのラベルが付いたファイルの場合、httpd はこのファイルの読み取りはできますが書き込みはできません。この場合、Linux (DAC) のパーミッションで書き込みのアクセスが許可されていても書き込みはできません。特定の動作を許可する場合、たとえば、スクリプトによるネットワークへのアクセスを許可する、httpd による NFS や CIFS ファイルシステムへのアクセスを許可する、httpd による CGI (Common Gateway Interface) スクリプトの実行を許可するなどの場合には、ブール値を有効にする必要があります。
httpd が TCP ポート 80、443、488、8008、8009、8443 以外のポートでリッスンするように /etc/httpd/conf/httpd.conf ファイルを設定する場合は、semanage port コマンドを使って SELinux ポリシー設定に新しいポート番号を追加する必要があります。以下では、まだ SELinux ポリシー設定で httpd 用には定義されていないポートでリッスンするよう httpd を設定した結果、httpd の起動に失敗する例を示します。また、httpd がポリシーにまだ定義されていない非標準のポートで正しくリッスンするよう SELinux システムを設定する方法についても示します。この例では、httpd パッケージがインストールされていることを前提としています。各コマンドは root ユーザーで実行してください。
- 以下のコマンドを実行して、
httpdが稼働していないことを確認します。~]#
systemctl status httpd.servicehttpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled) Active: inactive (dead)出力が上記と異なる場合は、このプロセスを停止します。~]#
systemctl stop httpd.service semanageユーティリティーを使って、SELinux でhttpdにリッスンを許可しているポートを表示します。~]#
semanage port -l | grep -w http_port_thttp_port_t tcp 80, 443, 488, 8008, 8009, 8443- root で
/etc/httpd/conf/httpd.confを編集します。Listenオプションを設定し、SELinux ポリシー設定でhttpd用に設定されていないポートを記入します。この例では、httpdがポート 12345 をリッスンするように設定します。# Change this to Listen on specific IP addresses as shown below to # prevent Apache from glomming onto all bound IP addresses (0.0.0.0) # #Listen 12.34.56.78:80 Listen 127.0.0.1:12345
- 以下のコマンドを実行して、
httpdを起動します。~]#
systemctl start httpd.serviceJob for httpd.service failed. See 'systemctl status httpd.service' and 'journalctl -xn' for details.次のような SELinux 拒否メッセージがログ記録されます。setroubleshoot: SELinux is preventing the httpd (httpd_t) from binding to port 12345. For complete SELinux messages. run sealert -l f18bca99-db64-4c16-9719-1db89f0d8c77
- この例で
httpdがポート 12345 をリッスンできるように SELinux で許可するには、以下のコマンドが必要になります。~]#
semanage port -a -t http_port_t -p tcp 12345 - 再度
httpdを起動して、新しいポートをリッスンするようにします。~]#
systemctl start httpd.service - これで
httpdが非標準ポート (この例では TCP 12345) をリッスンできるようにする SELinux 設定が完了したので、httpdがこのポートで正常に起動するようになります。 httpdが TCP ポート 12345 でリッスンし通信しているかを確認するには、以下のようにそのポートに telnet 接続を開き HTTP GET コマンドを発行します。~]#
telnet localhost 12345Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. GET / HTTP/1.0 HTTP/1.1 200 OK Date: Wed, 02 Dec 2009 14:36:34 GMT Server: Apache/2.2.13 (Red Hat) Accept-Ranges: bytes Content-Length: 3985 Content-Type: text/html; charset=UTF-8 [...continues...]

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.