使用Postfix或Sendmail milter时配置SELinux
本节说明如何配置SELinux以在使用Bitdefender milter与Postfix和Sendmail时允许邮件流量。
Bitdefender邮件服务器安全方案 通过获奖的主动式反病毒、反间谍软件、反垃圾邮件、反钓鱼、内容及附件过滤技术,为Windows或UNIX邮件服务器提供已知和未知安全威胁防护。该解决方案通过拦截垃圾邮件并提供统一的集中管理工具,保障企业邮件服务安全并提升工作效率。
概述
在启用SELinux强制模式(默认设置)的邮件服务器上,SELinux策略会阻止Bitdefender milter代理与Postfix和Sendmail邮件传输代理(MTA)集成,导致邮件服务器丢弃所有邮件流量。
要解决此问题,需创建一系列安全策略例外。下文列出为各MTA创建SELinux例外的步骤。
前提条件
必须安装 policycoreutils-python 软件包。该包包含创建SELinux策略模块所需的 audit2allow 脚本。
默认情况下 policycoreutils-python 软件包未预装。
要验证系统是否已安装该包,请执行:
-
基于Red Hat的发行版
$rpm-qapolicycoreutils-python -
基于Debian的发行版
$dpkg–spolicycoreutils-python
要安装该软件包,请运行:
-
基于Red Hat的发行版
#yuminstallpolicycoreutils-python -
基于Debian的发行版
#apt-getupdate#apt-getinstallpolicycoreutils-python
故障排除
SELinux将所有操作记录在/var/log/audit/audit.log中。 Audit2allow 利用"deny"操作生成的日志条目来构建例外规则。
按照以下步骤使用 audit2allow :
对于Postfix milter
-
针对以下日志条目,构建SELinux模块,允许 smtp 对Bitdefender创建的socket进行写入操作:
type=AVC msg=audit(1420639482.638:359): avc: denied { write } for pid=2628 comm="smtpd" name="bdmilterd.sock" dev="dm-1" ino=17433124 scontext=system_u:system_r:postfix_smtpd_t:s0 tcontext=system_u:object_r:postfix_spool_t:s0 tclass=sock_file
#grep"denied{write}"/var/log/audit/audit.log|grep"smtpd"|audit2allow-Msmtpd-write生成的模块包含两个文件:
-
smtpd-write.te ,类型强制文件
-
smtpd-write.pp ,策略包文件
-
-
将策略包加载到策略中。
#semodule-ismtpd-write.pp -
创建另一条策略,允许 smtp 连接到以下日志条目中的套接字文件:
type=AVC msg=audit(1420712445.141:616): avc: denied { connectto } for pid=4292 comm="smtpd" path="/var/spool/postfix/BitDefender/bdmilterd.sock" scontext=system_u:system_r:postfix_smtpd_t:s0 tcontext=system_u:system_r:init_t:s0 tclass=unix_stream_socket
#grep"denied{connectto}"/var/log/audit/audit.log|grep"smtpd"|audit2allow-Msmtpd-connectto生成的文件: smtpd-connectto.te , smtpd-connectto.pp
-
将策略包加载到策略中。
#semodule-ismtpd-connectto.pp -
要查看已安装的策略模块,请运行:
#semodule-l
对于Sendmail milter
-
针对以下日志条目,构建允许 sendmail 读取Bitdefender创建的套接字属性的SELinux模块:
type=AVC msg=audit(1420728867.579:709): avc: denied { getattr } for pid=5805 comm="sendmail" path="/run/BitDefender/bdmilterd.sock" dev="tmpfs" ino=334905 scontext=system_u:system_r:sendmail_t:s0 tcontext=unconfined_u:object_r:init_var_run_t:s0 tclass=sock_file
#grep"denied{getattr}"/var/log/audit/audit.log|grep"sendmail"|audit2allow-Msendmail-gettattr生成的模块包含两个文件:
-
sendmail-gettattr.te ,类型强制文件
-
sendmail-gettattr.pp ,一个策略包文件
-
-
将该包加载到策略中。
#semodule-isendmail-gettattr.pp -
针对以下日志条目,构建SELinux模块,允许 sendmail 对Bitdefender创建的套接字进行写入操作:
type=AVC msg=audit(1420729472.802:720): avc: denied { write } for pid=5881 comm="sendmail" name="bdmilterd.sock" dev="tmpfs" ino=334905 scontext=system_u:system_r:sendmail_t:s0 tcontext=unconfined_u:object_r:init_var_run_t:s0 tclass=sock_file
#grep"denied{write}"/var/log/audit/audit.log|grep"sendmail"|audit2allow-Msendmail-write生成的文件包括: sendmail-write.te , sendmail-write.pp
-
将该包加载到策略中。
#semodule-isendmail-write.pp -
针对以下日志条目,创建策略以允许sendmail连接到套接字文件:
type=AVC msg=audit(1420730220.602:729): avc: denied { connectto } for pid=5999 comm="sendmail" path="/run/BitDefender/bdmilterd.sock" scontext=system_u:system_r:sendmail_t:s0 tcontext=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 tclass=unix_stream_socket
#grep"denied{connectto}"/var/log/audit/audit.log|grep"sendmail"|audit2allow-Msendmail-connectto生成的文件包括: sendmail-connectto.te , sendmail-connectto.pp
-
将该包加载到策略中。
#semodule-isendmail-connectto.pp -
要查看已安装的策略模块,请运行:
#semodule-l