Red Hat Training

A Red Hat training course is available for Red Hat Enterprise Linux

4.10.3. デフォルトの SELinux コンテキストの確認

matchpathcon ユーティリティーを使用して、ファイルおよびディレクトリーに正しい SELinux コンテキストがあるかどうかを確認します。このユーティリティーは、system policy にクエリーを行い、ファイルパスに関連付けられたデフォルトのセキュリティーコンテキストを提供します。[6] 以下の例では、matchpathcon を使用して、/var/www/html/ディレクトリーのファイルに正しくラベル付けされていることを確認します。

手順4.16 matchpathconを使用したデフォルトの SELinux Conxtext の確認

  1. root ユーザーとして、/var/www/html/ ディレクトリーに 3 つのファイル (file1file2、および 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
    
  2. root で、file1 タイプを samba_share_t に変更します。Apache HTTP Server は、samba_share_t タイプのラベルが付けられたファイルまたはディレクトリーを読み取ることができないことに注意してください。
    ~]# chcon -t samba_share_t /var/www/html/file1
  3. matchpathcon -V オプションは、現在の SELinux コンテキストを SELinux ポリシー内の正しいデフォルトコンテキストと比較します。以下のコマンドを実行して、/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
ラベルの問題を解決し、root で Apache HTTP Server が file1 にアクセスできるようにするには、restorecon ユーティリティーを使用します。
~]# 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


[6] matchpathcon の詳細は、matchpathcon(8) man ページを参照してください。