Red Hat Training
A Red Hat training course is available for Red Hat Enterprise Linux
5.10.3. デフォルト SELinux コンテキストのチェック
matchpathcon コマンドでファイルやディレクトリーに正しい SELinux コンテキストがあるかどうかをチェックします。matchpathcon(8) man ページでが 「matchpathcon がシステムポリシーにクエリを行い、ファイルパスに関連するデフォルトのセキュリティーコンテキストを出力します。」となっています。[11]。以下の例では、matchpathcon コマンドを使って /var/www/html/ ディレクトリーが正しくラベル付けされているかを確認します。
- Linux root ユーザーで
touch /var/www/html/file{1,2,3}コマンドを実行し、3 つのファイルを作成します (file1、file2、file3)。これらのファイルは、/var/www/html/ディレクトリーからのhttpd_sys_content_tタイプを継承します。~]#
touch /var/www/html/file{1,2,3}~]#ls -Z /var/www/html/-rw-r--r-- root root unconfined_u:object_r:httpd_sys_content_t:s0 file1 -rw-r--r-- root root unconfined_u:object_r:httpd_sys_content_t:s0 file2 -rw-r--r-- root root unconfined_u:object_r:httpd_sys_content_t:s0 file3 - Linux root ユーザーで
chcon -t samba_share_t /var/www/html/file1コマンドを実行し、file1タイプをsamba_share_tに変更します。注記: Apache HTTP Server は、samba_share_tタイプでラベル付けされたファイルやディレクトリーを読み取れません。 matchpathcon-Vオプションは、現行の SELinux コンテキストを SELinux ポリシーの正しいデフォルトのコンテキストと比べます。matchpathcon -V /var/www/html/*コマンドを実行し、/var/www/html/ディレクトリー内の全ファイルをチェックします。~]$
matchpathcon -V /var/www/html/*/var/www/html/file1 has context unconfined_u:object_r:samba_share_t:s0, should be system_u:object_r:httpd_sys_content_t:s0 /var/www/html/file2 verified. /var/www/html/file3 verified.
以下の
matchpathcon コマンドの出力は、file1 は samba_share_t タイプでラベル付けされていますが、httpd_sys_content_t タイプでラベル付けされるべきであることを示しています。
/var/www/html/file1 has context unconfined_u:object_r:samba_share_t:s0, should be system_u:object_r:httpd_sys_content_t:s0
このラベル問題を解決して Apache HTTP Server が
file1 にアクセスできるようにするには、Linux root ユーザーで restorecon -v /var/www/html/file1 コマンドを実行します。
~]# restorecon -v /var/www/html/file1
restorecon reset /var/www/html/file1 context unconfined_u:object_r:samba_share_t:s0->system_u:object_r:httpd_sys_content_t:s0
[11]
Red Hat Enterprise Linux の libselinux-utils パッケージと出荷された matchpathcon(8) man ページは、Daniel Walsh が作成したものです。編集および変更はすべて、Muray McAllister によるものです