根据audit.log来放通SELinux的拦截

参考:https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/security-enhanced_linux/sect-security-enhanced_linux-fixing_problems-allowing_access_audit2allow

Redhat系的linux发行版,默认都打开了SELinux,总所周知,SELinux可以很好的提高系统安全性,但同时也会对系统的配置造成影响,所以,很多教程开始都会包含关闭SELinux的内容,避免出现异常。

Redhat对于配置SELinux也提供了一些很有用的帮助,比如说/var/log/audit/audit.log里面就包含了SELinux的审计日志,只要一搜denied就能看到SELinux拦截了的内容,配合audit2allow工具,就可以很方便的新增SELinux的放通策略。

下面是摘抄于参考文档中的内容:

第一步,先检查/var/log/audit/audit.log,里面包含了被SELinux拦截的内容,比如说这样内容

type=AVC msg=audit(1226270358.848:238): avc:  denied  { write } for  pid=13349 comm="certwatch" name="cache" dev=dm-0 ino=218171 scontext=system_u:system_r:certwatch_t:s0 tcontext=system_u:object_r:var_t:s0 tclass=dir

type=SYSCALL msg=audit(1226270358.848:238): arch=40000003 syscall=39 success=no exit=-13 a0=39a2bf a1=3ff a2=3a0354 a3=94703c8 items=0 ppid=13344 pid=13349 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="certwatch" exe="/usr/bin/certwatch" subj=system_u:system_r:certwatch_t:s0 key=(null)

例子中一个叫做certwatch(comm="certwatch")的进程被拦截了,被禁止写操作({ write }),写的目标文件夹的带有的var_t标签(tcontext=system_u:object_r:var_t:s0)。如果仔细阅读另外一节之后发现,这个拦截不能用简单的sebool来解决,就需要使用audit2allow来根据audit的日志来生成允许策略。

第二步,用audit2allow -w -a生成一个方便人看懂的报告。audit2allow可以读取/var/audit/audit.log,需要root权限运行,-w参数代表方便阅读,-a参数表示读取所有的audit日志。结果会是类似这样的

~]# audit2allow -w -a
type=AVC msg=audit(1226270358.848:238): avc:  denied  { write } for  pid=13349 comm="certwatch" name="cache" dev=dm-0 ino=218171 scontext=system_u:system_r:certwatch_t:s0 tcontext=system_u:object_r:var_t:s0 tclass=dir
 Was caused by:
 Missing type enforcement (TE) allow rule.

 You can use audit2allow to generate a loadable module to allow this access.

第三步,执行audit2allow -a检查需要放通的权限

~]# audit2allow -a


#============= certwatch_t ==============
allow certwatch_t var_t:dir write;

原文中提到一个重要的提醒,提到,出现这种情况都算软件没配好,是应该向Redhat提交故障报告的。

第四步,用 audit2allow -a -M 生成一个可以加载的模块

~]# audit2allow -a -M mycertwatch

******************** IMPORTANT ***********************
To make this policy package active, execute:

semodule -i mycertwatch.pp

~]# ls
mycertwatch.pp  mycertwatch.te

生成模块后,用semodule加载上。原文中提到,生成的模块往往会超出实际所需的权限,建议先提交结果去  fedora-selinux-list 之类的让大家先看看有没有问题。

最后,如果出现多个denied的原因,建议用grep过滤出几个结果,分开几个模块来允许。

发表评论