検索

5.10.3. デフォルト SELinux コンテキストのチェック

download PDF
matchpathcon コマンドでファイルやディレクトリーに正しい SELinux コンテキストがあるかどうかをチェックします。matchpathcon(8) man ページでが 「matchpathcon がシステムポリシーにクエリを行い、ファイルパスに関連するデフォルトのセキュリティーコンテキストを出力します。」となっています。[11]。以下の例では、matchpathcon コマンドを使って /var/www/html/ ディレクトリーが正しくラベル付けされているかを確認します。
  1. Linux root ユーザーで touch /var/www/html/file{1,2,3} コマンドを実行し、3 つのファイルを作成します (file1file2file3)。これらのファイルは、/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. Linux root ユーザーで chcon -t samba_share_t /var/www/html/file1 コマンドを実行し、file1 タイプを samba_share_t に変更します。注記: Apache HTTP Server は、samba_share_t タイプでラベル付けされたファイルやディレクトリーを読み取れません。
  3. 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 コマンドの出力は、file1samba_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 によるものです
Red Hat logoGithubRedditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

© 2024 Red Hat, Inc.