什么是 setroubleshootd

SELinux(Security Enhanced Linux)提供对 Linux 操作系统的强制访问控制。
SELinux 非常普遍,即使只是在 PERMISSIVE 模式下。
这可能会暴露非 SELinux 组件中的潜在错误,除非 SELinux 正在运行,否则这些错误是不可见的。
沮丧的用户已经形成了 SELinux 难以使用的看法。

setroubleshoot 服务旨在使 SELinux 更加友好。
它从内核收集 SELinux 审计事件并运行一系列分析插件来检查 SELinux 检测到的访问冲突。
然后它会记录分析结果并向任何请求通知这些事件的客户端发出信号。
使用此功能的工具是 Sealert 工具,它提供类似于电子邮件 biff 警报的桌面通知。

必须启用 SELinux 才能运行此服务。

服务控制

在 CentOS/RHEL 6 及更高版本上,setroubleshootd 不需要 init 脚本来启动/停止,而它使用 dbus 来启动它,但它仍然用于分析 AVC 消息。
两个新程序充当在需要时启动 setroubleshoot 的方法,例如:sedispatch 和 seapplet。
“sedispatch”从审计系统获取所有消息并使用审计库搜索AVC消息,当它发现AVC拒绝发生消息时,如果它已经在运行,它将转到setroubleshootd,否则将启动setroubleshootd运行步。
seapplet 实用程序在系统工具列中运行,等待 setroubleshootd 中的 dbus 消息。
它启动通知气泡,允许用户查看 AVC 消息。

测试功能

将 sshd 守护进程绑定到非标准端口。
例如:在 /etc/sshd/sshd_config 文件上定义添加端口:

Port 22
Port 222

重新启动 sshd,它将成功绑定到端口 22,但不允许绑定到端口 222.
因为它被 SELinux 阻止为 ssh_port_t 端口类型的非标准端口。
在重新启动 sshd 服务时,验证“ps aux | grep setroubleshoot”命令输出,dbus 服务会触发 setroubleshoot 进程。

# service sshd restart;ps aux|grep setroubleshoot
Stopping sshd: [ OK ]
Starting sshd: [ OK ]
root 31779 41.4 8.5 420396 175700 ? Rl 12:44 0:03 /usr/bin/python -Es /usr/sbin/setroubleshootd -f

在重新启动 SSHD 服务时,它将尝试绑定到端口 222,但 setroubleshoot 会阻止它,并且日志详细信息将被捕获在 /var/log/audit/audit.log 文件中以拒绝访问非标准端口 222 .

# cat /var/log/audit/audit.log
type=AVC msg=audit(1427956913.700:7926): avc: denied { name_bind } for pid=30949 comm="sshd" src=222 scontext=unconfined_u:system_r:sshd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:reserved_port_t:s0 tclass=tcp_socket
type=SYSCALL msg=audit(1427956913.700:7926): arch=c000003e syscall=49 success=no exit=-13 a0=3 a1=7fc9e4d25410 a2=10 a3=7ffff48bd62c items=0 ppid=1 pid=30949 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 ses=1296 tty=(none) comm="sshd" exe="/usr/sbin/sshd" subj=unconfined_u:system_r:sshd_t:s0-s0:c0.c1023 key=(null)
type=AVC msg=audit(1427956913.703:7927): avc: denied { name_bind } for pid=30949 comm="sshd" src=222 scontext=unconfined_u:system_r:sshd_t:s0-s0:c0.c1023 tcontext=system_u:object_r:reserved_port_t:s0 tclass=tcp_socket

可以使用 Sealert 工具读取 audit.log 文件。

# sealert -a /var/log/audit/audit.log
100% donefound 1 alerts in /var/log/audit/audit.log
-------------------------------------------------------------------------------
SELinux is preventing /usr/sbin/sshd from name_bind access on the tcp_socket .
* Plugin bind_ports (99.5 confidence) suggests *
If you want to allow /usr/sbin/sshd to bind to network port 222
Then you need to modify the port type.
Do
# semanage port -a -t PORT_TYPE -p tcp 222
where PORT_TYPE is one of the following: pki_tks_port_t, condor_port_t, ptal_port_t, ups_port_t, sieve_port_t, milter_port_t, pki_tps_port_t, zented_port_t, postgresql_port_t, winshadow_port_t, ntop_port_t, tor_port_t, squid_port_t, 
。。。
* Plugin catchall (1.49 confidence) suggests ***
If you believe that sshd should be allowed name_bind access on the 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:
# grep sshd /var/log/audit/audit.log | audit2allow -M mypol
# semodule -i mypol.pp
on  it road.com

安装

  1. 安装 setroubleshoot 包。
# yum install setroubleshoot
  1. 验证selinux状态,确保设置为Enforcing
# sestatus
  1. setroubleshoot服务由/etc/setroubleshoot/setroubleshoot.cfg配置文件控制。

注意:在大多数情况下,我们可以使用默认配置,但可能希望查看它的其他功能,例如为每次访问拒绝发送电子邮件消息的能力。

如何在 CentOS/RHEL 上安装和配置“setroubleshootd”
日期:2020-09-17 00:12:30 来源:oir作者:oir