SELinux : SETroubleShoot を活用する2025/01/02 |
|
SELinux による AVC 拒否のログは リンク先のように、ログファイルの直接参照 または ツール経由でのレポート出力により確認可能ですが、SETroubleShoot を利用すると、問題解決に有用なログを追加出力することができます。 |
|
| [1] |
SETroubleShoot のメッセージは Audit イベント ディスパッチャーによって Systemd Journald ( Rsyslog 稼働の場合は [/var/log/messages] ) へ送信されます。 |
| [2] | SETroubleShoot は [Server] 構成等々で CentOS Stream をインストールした場合は、デフォルトでインストールされていますが、もしインストールされていない場合はインストールしておきます。 |
|
[root@dlp ~]# dnf -y install setroubleshoot-server
|
| [3] |
AVC 拒否が発生した場合は Systemd Journald や、Rsyslog 稼働の場合 [/var/log/messages] に以下のようなログが記録されます。
[/var/log/messages] に記録されたログを例にすると、下例の場合、2 行目に推測される原因と対策が 2 パターン記載されており、可能性のより高いとされている方は、[Plugin bind_ports (99.5 confidence) suggests] で提案された内容となります。下例の場合、その提案通り、[semanage port -a -t http_port_t -p tcp 82] とコマンド投入することで解決します。 解決しない場合は、[Plugin catchall (1.49 confidence) suggests] で提案された内容を試してみることになります。 |
|
[root@dlp ~]# grep -E 'setroubleshoot|preventing' /var/log/messages Jan 2 13:48:07 dlp setroubleshoot[2721]: SELinux is preventing /usr/sbin/httpd from name_bind access on the tcp_socket port 82. For complete SELinux messages run: sealert -l 96e2d232-7b22-4359-b6a6-a91a514ef574 Jan 2 13:48:07 dlp setroubleshoot[2721]: SELinux is preventing /usr/sbin/httpd from name_bind access on the tcp_socket port 82.#012#012***** Plugin bind_ports (99.5 confidence) suggests ************************#012#012If you want to allow /usr/sbin/httpd to bind to network port 82#012Then you need to modify the port type.#012Do#012# semanage port -a -t PORT_TYPE -p tcp 82#012 where PORT_TYPE is one of the following: http_cache_port_t, http_port_t, jboss_management_port_t, jboss_messaging_port_t, ntop_port_t, puppet_port_t.#012#012***** Plugin catchall (1.49 confidence) suggests **************************#012#012If you believe that httpd should be allowed name_bind access on the port 82 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 -X 300 -i my-httpd.pp#012 |
| [4] | なお、上記ログの例 1 行目には、より詳細な情報を出力可能なコマンドが記載されているため、その通りにコマンドを投入すると以下のように内容が確認できます。 原因と対策の内容についてはログに記載してある内容と同じですが、より詳細により読みやすく表示されます。 |
|
[root@dlp ~]# sealert -l 96e2d232-7b22-4359-b6a6-a91a514ef574
SELinux is preventing /usr/sbin/httpd from name_bind access on the tcp_socket port 82.
***** Plugin bind_ports (99.5 confidence) suggests ************************
If you want to allow /usr/sbin/httpd to bind to network port 82
Then you need to modify the port type.
Do
# semanage port -a -t PORT_TYPE -p tcp 82
where PORT_TYPE is one of the following: http_cache_port_t, http_port_t, jboss_management_port_t, jboss_messaging_port_t, ntop_port_t, puppet_port_t.
***** Plugin catchall (1.49 confidence) suggests **************************
If you believe that httpd should be allowed name_bind access on the port 82 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 -X 300 -i my-httpd.pp
Additional Information:
Source Context system_u:system_r:httpd_t:s0
Target Context system_u:object_r:reserved_port_t:s0
Target Objects port 82 [ tcp_socket ]
Source httpd
Source Path /usr/sbin/httpd
Port 82
Host dlp.srv.world
Source RPM Packages httpd-core-2.4.62-5.el10.x86_64
Target RPM Packages
SELinux Policy RPM selinux-policy-targeted-40.13.17-1.el10.noarch
Local Policy RPM selinux-policy-targeted-40.13.17-1.el10.noarch
Selinux Enabled True
Policy Type targeted
Enforcing Mode Enforcing
Host Name dlp.srv.world
Platform Linux dlp.srv.world 6.12.0-35.el10.x86_64 #1 SMP
PREEMPT_DYNAMIC Fri Dec 13 19:20:16 UTC 2024
x86_64
Alert Count 2
First Seen 2025-01-02 13:48:01 JST
Last Seen 2025-01-02 13:48:01 JST
Local ID 96e2d232-7b22-4359-b6a6-a91a514ef574
Raw Audit Messages
type=AVC msg=audit(1735793281.794:387): avc: denied { name_bind } for pid=2715 comm="httpd" src=82 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:reserved_port_t:s0 tclass=tcp_socket permissive=0
type=SYSCALL msg=audit(1735793281.794:387): arch=x86_64 syscall=bind success=no exit=EACCES a0=3 a1=55fd6b0c03c0 a2=10 a3=7ffde9f99e3c items=0 ppid=1 pid=2715 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm=httpd exe=/usr/sbin/httpd subj=system_u:system_r:httpd_t:s0 key=(null)
Hash: httpd,httpd_t,reserved_port_t,tcp_socket,name_bind
|
| Sponsored Link |
|
|