GNU/Linux >> Linux の 問題 >  >> Linux

SELinux拒否メッセージを読んで修正する方法

Security Enhanced Linux(SELinux)は、Linuxシステム内のアプリケーションやファイルなどへのアクセスを許可および拒否するセキュリティフレームワークです。 SELinuxの完全な概要については、「SELinuxとは」を参照してください。

この記事では、目的のファイルまたはアプリケーションへのアクセスが拒否された場合に何が起こるかを見ていきます。どのようなメッセージが表示され、これらのメッセージはどこに保存され、情報は実際に何を意味しますか?誤検知やゴースト拒否によって引き起こされる、自分が遭遇する可能性のある異常な状況にはどのようなものがありますか?ここでそのすべてを探求します。

拒否とは何ですか?

拒否 サービス、アプリケーション、ファイルなどがSELinuxシステムによってアクセスを拒否されたときに生成されるイベントです。これが発生すると、拒否はAccess Vector Cache(AVC)にキャッシュされます。 AVC拒否と呼ばれる拒否メッセージが表示されることがあります。 。

拒否はどこに記録されますか?

現在、これらのAVC拒否は、Linuxの他のすべてと同様に、システムによってログに記録されます。これらのメッセージがログに記録される場所は、実行中のシステムデーモンによって異なります。

  • 監査-/var/log/audit/audit.log
  • 監査オフ; rsyslogd on-/ var / log / messages
  • setroubleshooted、rsyslogd、auditon-両方の場所。ただし、/ var / log/messagesのメッセージの方がわかりやすい

拒否はどのようになりますか?

デスクトップに拒否の警告が表示されることがあります。 表示を選択した場合 、このアラートは、何がうまくいかなかったのか、時には問題を解決するための解決策についての詳細を提供します。

もう1つできることは、次のコマンドを実行して拒否メッセージを引き出すことです。

[root@server ~]# grep "SELinux is preventing" /var/log/messages

ここでは、出力はより親しみやすい言語で書かれており、注意深く読むと、解決策が提示されます。

Sep 22 13:35:24 server setroubleshoot[3999]: SELinux is preventing rhsmcertd-worke from read access on the file virt.module. For complete SELinux messages run: sealert -l 97a1c0df-81ed-4c08-ba27-41c5067b713b
Sep 22 13:35:24 server platform-python[3999]: SELinux is preventing rhsmcertd-worke from read access on the file virt.module.#012#012*****  Plugin catchall_boolean (89.3 confidence) suggests   ******************#012#012If you want to allow daemons to dump core#012Then you must tell SELinux about this by enabling the 'daemons_dump_core' boolean.#012#012Do#012setsebool -P daemons_dump_core 1#012#012*****  Plugin catchall (11.6 confidence) suggests   **************************#012#012If you believe that rhsmcertd-worke should be allowed read access on the virt.module file by default.#012Then you should report this as a bug.#012You can generate a local policy module to allow this access.#012Do#012allow this access for now by executing:#012# ausearch -c 'rhsmcertd-worke' --raw | audit2allow -M my-rhsmcertdworke#012# semodule -X 300 -i my-rhsmcertdworke.pp#012

上記の最初のエントリから次のことがわかるため、この出力は実際に非常に役立ちます。

For complete SELinux messages run: sealert -l 97a1c0df-81ed-4c08-ba27-41c5067b713b

提案されたコマンドを実行すると、何が起こったのか、問題を解決するために何ができるのかについて、非常に冗長でありながら簡単な要約が表示されます。以下を参照してください:

    [root@server ~]# sealert -l 97a1c0df-81ed-4c08-ba27-41c5067b713b
    SELinux is preventing rhsmcertd-worke from read access on the file virt.module.
    
    *****  Plugin catchall_boolean (89.3 confidence) suggests   ******************
    
    If you want to allow daemons to dump core
    Then you must tell SELinux about this by enabling the 'daemons_dump_core' boolean.
    
    Do
    setsebool -P daemons_dump_core 1
    
    *****  Plugin catchall (11.6 confidence) suggests   **************************
    
    If you believe that rhsmcertd-worke should be allowed read access on the virt.module file by default.
    Then you should report this as a bug.
    You can generate a local policy module to allow this access.
    Do
    allow this access for now by executing:
    # ausearch -c 'rhsmcertd-worke' --raw | audit2allow -M my-rhsmcertdworke
    # semodule -X 300 -i my-rhsmcertdworke.pp
    
    
    Additional Information:
    Source Context                system_u:system_r:rhsmcertd_t:s0
    Target Context                system_u:object_r:root_t:s0
    Target Objects                virt.module [ file ]
    Source                        rhsmcertd-worke
    Source Path                   rhsmcertd-worke
    Port                          <Unknown>
    Host                          server.example.com
    Source RPM Packages           
    Target RPM Packages           
    Policy RPM                    selinux-policy-3.14.3-41.el8_2.5.noarch
    Selinux Enabled               True
    Policy Type                   targeted
    Enforcing Mode                Enforcing
    Host Name                     server.example.com
    Platform                      Linux server.example.com
                                  4.18.0-193.13.2.el8_2.x86_64 #1 SMP Mon Jul 13
                                  23:17:28 UTC 2020 x86_64 x86_64
    Alert Count                   265
    First Seen                    2020-06-24 13:55:40 EDT
    Last Seen                     2020-09-22 13:35:09 EDT
    Local ID                      97a1c0df-81ed-4c08-ba27-41c5067b713b
    
    Raw Audit Messages
    type=AVC msg=audit(1600796109.687:168): avc:  denied  { read } for  pid=3912 comm="rhsmcertd-worke" name="virt.module" dev="dm-0" ino=50331783 scontext=system_u:system_r:rhsmcertd_t:s0 tcontext=system_u:object_r:root_t:s0 tclass=file permissive=0
    
    
    Hash: rhsmcertd-worke,rhsmcertd_t,root_t,file,read

[読者も楽しんだ:SELinuxポリシードキュメントへのアクセス]

以下のコマンドを生の監査メッセージに使用することもできますが、これらのメッセージはあまり役に立ちません(sealertに含まれています)。 出力)。

[root@server ~]# grep "denied"/var/log/audit/audit.log

ここでは、この言語は使い勝手が悪く、推奨される手順はありません。

type=AVC msg=audit(1600796109.687:168): avc:  denied  { read } for  pid=3912 comm="rhsmcertd-worke" name="virt.module" dev="dm-0" ino=50331783 scontext=system_u:system_r:rhsmcertd_t:s0 tcontext=system_u:object_r:root_t:s0 tclass=file permissive=0

ゴースト拒否

特別な機会に(特別 、フラストレーションを生成する能力のように)、SELinux AVCは、拒否が発生したことをユーザーに警告することなく、サービスを拒否できます。これが発生した場合、少し法医学的な掘り下げが必要です。最近、私の同僚であり、ライターでもあるKen Hessが、CentOS仮想マシンにドキュメント管理システムをインストールしました。このインストール中に、DMSは説明なしでインストールできませんでした。長くて苛立たしいトラブルシューティングプロセスの後、ケンは/var/log/audit/audit.logに繰り返し拒否メッセージがあることを発見しました。 。

type=AVC msg=audit(1602171971.334:438): avc: denied { write } for pid=12398 comm="httpd" name="31b32f0dfa1f50d778065b767582bb9b.js" dev="dm-0" ino=553885 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:httpd_sys_content_t:s0 tclass=file permissive=0

/var/log/messagesをさらに詳しく調べたところ 、彼は次のことを発見しました:

Oct 8 12:33:17 dms python: SELinux is preventing /usr/sbin/httpd from name_connect access on the tcp_socket port 25.#012#012***** Plugin catchall_boolean (32.5 confidence) suggests ******************#012#012If you want to allow httpd to can network connect#012Then you must tell SELinux about this by enabling the 'httpd_can_network_connect' boolean.#012#012Do#012setsebool -P httpd_can_network_connect 1#012#012***** Plugin catchall_boolean (32.5 confidence) suggests ******************#012#012If you want to allow httpd to can sendmail#012Then you must tell SELinux about this by enabling the 'httpd_can_sendmail' boolean.#012#012Do#012setsebool -P httpd_can_sendmail 1#012#012***** Plugin catchall_boolean (32.5 confidence) suggests ******************#012#012If you want to allow nis to enabled#012Then you must tell SELinux about this by enabling the 'nis_enabled' boolean.#012#012Do#012setsebool -P nis_enabled 1#012#012***** Plugin catchall (4.5 confidence) suggests ***************************#012#012If you believe that httpd should be allowed name_connect access on the port 25 tcp_socket by default.#012Then you should report this as a bug.#012You can generate a local policy module to allow this access.#012Do#012allow this access for now by executing:#012# ausearch -c 'httpd' --raw | audit2allow -M my-httpd#012# semodule -i my-httpd.pp#012 Oct 8 12:33:20 dms setroubleshoot: SELinux is preventing /usr/sbin/httpd from name_connect access on the tcp_socket port 25. For complete SELinux messages run: sealert -l ce75fc38-5696-4b21-b099-7780db5960f3

最後に、何か便利なもの。次に、次のコマンドを実行しました:

# sealert -l ce75fc38-5696-4b21-b099-7780db5960f3

この情報を提供したのは:

[user@host ~] # SELinux is preventing /usr/sbin/httpd from name_connect access on the tcp_socket port 25. ***** Plugin catchall_boolean (32.5 confidence) suggests ****************** If you want to allow httpd to can network connect Then you must tell SELinux about this by enabling the 'httpd_can_network_connect' boolean. Do setsebool -P httpd_can_network_connect 1 ***** Plugin catchall_boolean (32.5 confidence) suggests ****************** If you want to allow httpd to can sendmail Then you must tell SELinux about this by enabling the 'httpd_can_sendmail' boolean. Do setsebool -P httpd_can_sendmail 1 ***** Plugin catchall_boolean (32.5 confidence) suggests ****************** If you want to allow nis to enabled Then you must tell SELinux about this by enabling the 'nis_enabled' boolean. Do setsebool -P nis_enabled 1 ***** Plugin catchall (4.5 confidence) suggests *************************** If you believe that httpd should be allowed name_connect access on the port 25 tcp_socket by default. Then you should report this as a bug. You can generate a local policy module to allow this access. Do allow this access for now by executing: # ausearch -c 'httpd' --raw | audit2allow -M my-httpd # semodule -i my-httpd.pp Additional Information:
    
Additional Information: [root@dms dms]# more sealert.txt SELinux is preventing /usr/sbin/httpd from name_connect access on the tcp_socket port 25. ***** Plugin catchall_boolean (32.5 confidence) suggests ****************** If you want to allow httpd to can network connect Then you must tell SELinux about this by enabling the 'httpd_can_network_connect' boolean. Do setsebool -P httpd_can_network_connect 1 ***** Plugin catchall_boolean (32.5 confidence) suggests ****************** If you want to allow httpd to can sendmail Then you must tell SELinux about this by enabling the 'httpd_can_sendmail' boolean. Do setsebool -P httpd_can_sendmail 1 ***** Plugin catchall_boolean (32.5 confidence) suggests ****************** If you want to allow nis to enabled Then you must tell SELinux about this by enabling the 'nis_enabled' boolean. Do setsebool -P nis_enabled 1 ***** Plugin catchall (4.5 confidence) suggests *************************** If you believe that httpd should be allowed name_connect access on the port 25 tcp_socket by default. Then you should report this as a bug. You can generate a local policy module to allow this access. Do allow this access for now by executing: # ausearch -c 'httpd' --raw | audit2allow -M my-httpd # semodule -i my-httpd.pp Additional Information: Source Context system_u:system_r:httpd_t:s0 Target Context system_u:object_r:smtp_port_t:s0 Target Objects port 25 [ tcp_socket ] Source httpd Source Path /usr/sbin/httpd Port 25 Host dms Source RPM Packages Target RPM Packages Policy RPM selinux-policy-3.13.1-252.el7.noarch Selinux Enabled True Policy Type targeted Enforcing Mode Permissive Host Name dms Platform Linux dms 3.10.0-1062.el7.x86_64 #1 SMP Wed Aug 7 18:08:02 UTC 2019 x86_64 x86_64 Alert Count 2 First Seen 2020-10-08 12:33:15 CDT Last Seen 2020-10-08 12:33:15 CDT Local ID ce75fc38-5696-4b21-b099-7780db5960f3 Raw Audit Messages type=AVC msg=audit(1602178395.253:461): avc: denied { name_connect } for pid=12565 comm="httpd" dest=25 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:smtp_port_t :s0 tclass=tcp_socket permissive=1 Hash: httpd,httpd_t,smtp_port_t,tcp_socket,name_connect

私がケンに彼の経験を検討するように頼んだとき、彼は次のように言っていました:

エラーまたはエラーの欠如がSELinuxによって引き起こされたのはいつかを知るのは難しいです。ファイアウォールの例外、ファイルシステムのアクセス許可、およびアプリケーションの前提条件を確認したら、次のステップはSELinuxコンテキストの問題を確認することです。最も一般的な解決策は、SELinuxをPermissiveモードにして無効にすることです。これを行うと、システムが脆弱になるため、これはお勧めできません。より良い方法は、/ var / log /messagesファイルと/var/log/audit/audit.logファイルでSELinux拒否を確認し、そこからアプリケーションが機能するまで拒否を個別に修正することです。これを行うには、SELinuxを強制モードのままにする必要があります。

新しいアプリケーションをセットアップするときのトラブルシューティングリストは次のようになります。

1.アプリケーションのポートのファイアウォール例外を確認します。

2.ファイルシステムのアクセス許可をチェックして、サービスアカウントに、必要に応じて読み取り、書き込み、および実行するための正しいアクセス許可があることを確認します。

3.アプリケーションの前提条件と依存関係を確認します。

4./var/log/messagesファイルと/var/log/audit/audit.logファイルでSELinuxの拒否を確認します。

SELinuxパーミッシブモードを簡単に使用して、SELinuxがアプリケーションの動作を妨げている原因であるかどうかを確認できます。問題があると判断したら、強制モードに戻し、関連するコンテキストの変更を開始します。 SELinuxコンテキストについては、この情報を参照してください。

[この役立つガイドを使用して、SELinuxの管理と使用のスキルを向上させてください。 ]

まとめ

SELinuxは効果的なセキュリティフレームワークであり、正しく実装すると非常に便利です。他の優れたセキュリティシステムと同様に、時間の経過とともに拒否されます。自由に使える情報をどう処理するかを知ることは、存在する可能性のある問題を解決するため、またはシステムを介して正当なプロセスを許可するために最も重要です。これで、ログが保存されている場所と、ログを最適に解釈する方法がわかりました。将来的には、システムにフラグを立てるSELinuxアラートに応答できるようになります。


Linux
  1. SELinuxを一時的または永続的に無効にする方法

  2. Linux環境変数:LinuxVPSでの読み取りと設定の方法

  3. 任意のユーザーとしてWindowsNTFSドライブを読み書きする方法

  1. CentOSでSELinuxを無効にする方法は?

  2. SELinux ユーザーとは何か、および Linux ユーザーを SELinux ユーザーにマップする方法

  3. Cでシリアルポートを開き、読み書きする方法は?

  1. IPアドレスを逆方向に読み取る方法は?

  2. 方法:DRBDのレプリケーションと構成

  3. Linux カーネル パニックを読み取り、理解し、分析し、デバッグする方法は?