如何修改SELinux以允许OpenDKIM写入/ var / tmp?

我试过这个答案( https://serverfault.com/a/744756/123651 ),但它仍然给出了一个错误。

Jan 7 23:56:33 ip-172-31-15-65 opendkim [24223]:AF15521407:dkim_eoh():资源不可用:无法在/var/tmp/dkim.AF15521407.ennuJK创build临时文件:Permission denied

以下是一些audit.log

 type=AVC msg=audit(1483827348.024:363280): avc: denied { write } for pid=22334 comm="opendkim" name="tmp" dev=xvde ino=40961 scontext=unconfined_u:system_r:dkim_milter_t:s0 tcontext=system_u:object_r:tmp_t:s0 tclass=dir type=SYSCALL msg=audit(1483827348.024:363280): arch=c000003e syscall=2 success=no exit=-13 a0=7f7eecd1f910 a1=c2 a2=180 a3=0 items=0 ppid=22035 pid=22334 auid=0 uid=495 gid=495 euid=495 suid=495 fsuid=495 egid=495 sgid=495 fsgid=495 tty=(none) ses=4038 comm="opendkim" exe="/usr/sbin/opendkim" subj=unconfined_u:system_r:dkim_milter_t:s0 key=(null) 

 # cat opendkim.te module opendkim 1.0; require { type tmp_t; type dkim_milter_t; class dir write; } #============= dkim_milter_t ============== #!!!! The source type 'dkim_milter_t' can write to a 'dir' of the following types: # dkim_milter_data_t, cluster_var_lib_t, cluster_var_run_t, root_t, cluster_conf_t allow dkim_milter_t tmp_t:dir write; # semodule -i opendkim.pp # ls -ldZ /var/tmp drwxrwxrwt. root root system_u:object_r:tmp_t:s0 /var/tmp # service opendkim restart Stopping OpenDKIM Milter: [ OK ] Starting OpenDKIM Milter: [ OK ] 

我不知道还有什么要尝试的。

参考:我使用这个指南: https : //www.rosehosting.com/blog/how-to-install-and-integrate-opendkim-with-postfix-on-a-centos-6-vps/

CentOS版本6.8(最终)

没有必要允许OpenDKIM写入任何其他目录。 只需写入默认临时目录/var/run/opendkim ,该目录应该已经存在,并且有正确的SELinux上下文以允许写入。

首先, setroubleshoot软件包提供了sealert命令,可以让你排除你的SELinux相关日志,并提出解决scheme,尽pipe可能不是最安全的解决scheme。

EL6文档: 链接

EL7文档: 链接


迈克尔汉普顿的答案是好的,因为默认目录是/var/run/opendkim与正确的dkim_milter_data_t SELinuxtypes。 为了回答你的问题,你可以使用下面的命令创build一个名为/var/tmp/opendkim (或其他你想要调用它的目录)的新目录,并使用正确的权限和SELinux上下文:

 mkdir -p /var/tmp/opendkim chown opendkim:opendkim /var/tmp/opendkim chmod 0775 /var/tmp/opendkim semanage fcontext -a -t dkim_milter_data_t "/var/tmp/opendkim(/.*)?" restorecon -rv /var/tmp/opendkim 

这些更改在重新启动后保持不变,您必须更新您的opendkimconfiguration才能使用此新创build的目录,该目录超出了本答案的范围。

我认为Michael Hampton♦所说的是最好的解决scheme。

但是如果你确实需要将Temporary设置为/var/tmp

那么你可以试试下面。

  1. 我们需要修改dkim_milter_t原来的策略。 所以,创build一个.te文件(例如下面的opendkim.te

  2. dkim_milter_t有权限访问tmp_t dir /var/tmp/types。

    # ll -Zd /var/tmp/ drwxrwxrwt. root root system_u:object_r:tmp_t:s0 /var/tmp/

文件可能如下所示

 module opendkim 1.0; require { type tmp_t; type dkim_milter_t; class dir { write remove_name add_name }; class file { write create unlink open }; } allow dkim_milter_t tmp_t:dir { write remove_name add_name }; allow dkim_milter_t tmp_t:file { write create unlink open }; 

当然,你可以改变它适合。 但我认为这是你最不需要的。 它实际上给了dkim_milter_t的权限去写从/var/tmp/

  1. 手动重新生成opendkim.pp

    checkmodule -M -m -o opendkim.mod opendkim.te

    semodule_package -o opendkim.pp -m opendkim.mod

  2. 启用更改

    semodule -i opendkim.pp

也许你需要更多的帮助。 和男人 。

 # setenforce permissive # service opendkim restart ... send mail to myself ... # setenforce enforcing # grep opendkim /var/log/audit/audit.log | audit2allow -M opendkim # cat opendkim.te module opendkim 1.0; require { type tmp_t; type dkim_milter_t; type sysctl_vm_t; class dir { write remove_name search add_name }; class file { write read create unlink open }; } #============= dkim_milter_t ============== allow dkim_milter_t sysctl_vm_t:dir search; allow dkim_milter_t sysctl_vm_t:file read; #!!!! This avc is allowed in the current policy allow dkim_milter_t tmp_t:dir write; allow dkim_milter_t tmp_t:dir { remove_name add_name }; #!!!! The source type 'dkim_milter_t' can write to a 'file' of the following types: # dkim_milter_data_t, cluster_var_lib_t, cluster_var_run_t, root_t, cluster_conf_t allow dkim_milter_t tmp_t:file { write create unlink open }; 

 # semodule -i opendkim.pp