7.2. コマンドラインアシスタントを使用した SELinux の問題のトラブルシューティング
コマンドラインアシスタントを使用して、SELinux の問題をトラブルシューティングできます。このトラブルシューティングプロセスの例では、コマンドラインアシスタントの診断機能を説明します。
前提条件
- コマンドラインアシスタントを有効にした。
- システムへの root アクセス権がある。
手順
ターミナルで次のコマンドを入力して、システムにインストールされている
httpdパッケージのバージョンをリスト表示します。$ sudo rpm -qa httpd httpd-2.4.62-2.fc40.x86_64すべての
httpdパッケージを検索します。$ sudo rpm -qa httpdWeb サーバーが着信リクエストを受け入れるポートを特定します。
$ cat /etc/httpd/conf/httpd.conf | grep Listen # Listen: Allows you to bind Apache to specific IP addresses and/or # Change this to Listen on a specific IP address, but note that if #Listen 12.34.56.78:80 Listen 80httpdサービスを再起動します。$ systemctl restart httpd Job for httpd. Service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xeu httpd.service" for details.journalctlコマンドを実行して、失敗したサービスの詳細を確認します。$ sudo journalctl -xeu httpd.service
コマンドラインアシスタントを使用して問題のトラブルシューティングを行い、サービスが失敗する理由を質問します。
$ sudo c "why did httpd fail to start"コマンドラインアシスタントに
selinux httpdポートについて質問します。$ c "selinux httpd port"アシスタントが、次のように
sestatusコマンドを使用して、現在の SELinux ステータスと httpd サービスの内容を確認することを提案します。$ sudo sestatus SELinux status: enabled SELinuxfs mount: /sys/fs/selinux SELinux root directory: /etc/selinux Loaded policy name: targeted Current mode: enforcing Mode from config file: enforcing Policy MLS status: enabled Policy deny_unknown status: allowed Memory protection checking: actual (secure) Max kernel policy version: 33次のコマンドを実行して、httpd サービスの特定の SELinux ポリシーを表示します。
$ sudo cat /usr/share/selinux/targeted/contexts/httpd_var_run_t No such file or directoryコマンドラインアシスタントにコンテキストについて質問します。
$ c "i don't have a httpd_var_run_t contexts"コマンドラインアシスタントが要求を処理するまでに、しばらく時間がかります。処理が終わると、提案がいくつか提供されます。
コンテキストがない可能性があるため、次のコマンドでコンテキストを設定する必要があるという指示が表示されます。
$ sudo chcon -R -t httpd_var_run_tコマンドラインアシスタント (CLA) にポートについて質問します。
$ c "selinux won't let httpd listen on port 12345"次の提案を試して、コマンドを実行します。
$ sudo semanage port -a -t httpd_port_t -p tcp 12345 ValueError: Type httpd_port_t is invalid, must be a port type出力に表示されたエラーについて CLA に質問します。
$ c "how do I fix ValueError: Type httpd_port_t is invalid, must be a port type"
CLA によって提供された手順を実行します。
$ sudo ls -Z /usr/sbin/httpd system_u:object_r:httpd_exec_t:s0 /usr/sbin/httpd $ chcon -t httpd_exec_t /usr/sbin/httpd $ sudo setenforce 1httpdサービスを再起動し、httpd.serviceのステータスを確認します。$ sudo systemctl restart httpd Job failed $ sudo systemctl status httpd.service Failed to start the Apache Server
httpdがport12345 で待ち受けできるようにする方法について、CLA に質問します。$ c "how do I enable httpd to listen on port 12345 selinux"CLA によって提案されたコマンドを実行します。
$ sudo setsebool -P httpd_can_network_connect=1
httpdサービスを再起動し、httpd.serviceのステータスを再度確認します。$ sudo systemctl status httpd $ sudo systemctl restart httpd Job failed, see journalctljournalctlサービスを確認します。$ journalctl -xeu httpd Output: An ExecStart= process belonging to unit httpd.service has exited.出力を使用して CLA にトラブルシューティングを実行するよう求めます。
$ c "An ExecStart= process belonging to unit httpd.service has exited."CLA の応答で返されるコマンドを実行します。
$ sudo ausearch -m AVC,USER_AVC -ts recent Output: "avc: denied {name_bind} for pid=7184 comm="httpd" src=12345 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r: unreserved_port_t:s0 tclas=tcp_socket permissive=0"前のコマンドの出力をコピーします。
$ sudo c "avc: denied {name_bind} for pid=7184 comm="httpd" src=12345 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r: unreserved_port_t:s0 tclas=tcp_socket permissive=0""SELinux is preventing Apache Server (httpd) from binding to port 12345" というエラーを解決するために、次のコマンドを実行します。
$ sudo semanage port -a -t http_port_t -p tcp 12345
検証
httpd サービスを再起動し、
httpd.serviceのステータスを確認します。$ sudo systemctl restart httpd No error $ sudo systemctl status httpd.serviceサーバーが設定されて起動し、
port 443、port 12345で待ち受けるようになります。