Ubuntu由于apparmor配置导致日志文件无法读写

前端之家收集整理的这篇文章主要介绍了Ubuntu由于apparmor配置导致日志文件无法读写前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

在strongswan查看日志的时候,并没有找到在strongswan.conf中配置的日志文件,我的相应配置如下:

  1. # strongswan.conf - strongSwan configuration file
  2. #
  3. # Refer to the strongswan.conf(5) manpage for details
  4. #
  5. # Configuration changes should be made in the included files
  6.  
  7. charon {
  8. plugins {
  9. include strongswan.d/charon/*.conf
  10. }
  11.  
  12. filelog {
  13. /var/log/strongswan.log {
  14. time_format = %b %e %T
  15. default = 4
  16. append = no
  17. flush_line = yes
  18. }
  19. }
  20. }
  21. include strongswan.d/*.conf

创建文件并对所有用户修改权限也没有用,查看/var/log/syslog文件在启动的时候报错:

报错如下(打开文件报错):

  1. Apr 24 16:36:32 ubuntu kernel: [ 690.797791] audit: type=1400 audit(1524558992.560:41): apparmor="DENIED" operation="open" profile="/usr/lib/ipsec/charon" name="/var/log/strongswan.log" pid=3723 comm="charon" requested_mask="wc" denied_mask="wc" fsuid=0 ouid=0

或者(创建文件报错):

  1. Apr 24 17:02:32 ubuntu kernel: [ 2250.553437] audit: type=1400 audit(1524560552.427:182): apparmor="DENIED" operation="mknod" profile="/usr/lib/ipsec/charon" name="/var/log/strongswan.log" pid=4557 comm="charon" requested_mask="c" denied_mask="c" fsuid=0 ouid=0

原因:

这是由于在Ubuntu中使用了apparmor配置,需要在相应配置文件修改相应文件权限控制。

参考:https://www.cnblogs.com/0xJDchen/p/6055531.html

解决方法

1 修改apparmor配置

  1. sudo vim '/etc/apparmor.d/usr.lib.ipsec.charon'
大括号中其他文件权限配置之后,添加(前面的内容为定义的log文件的路径,后面的是分配的权限),由于我在strongswan.conf中filelog的路径配置的为/var/log/strongswan.log,因此我配置的权限如下:
  1. /var/log/strongswan.* rwk,
2 执行apparmor重新加载:
  1. sudo /etc/init.d/apparmor reload
3 重启strongswan,我自测如果不重启还是没有文件
  1. sudo ipsec restart

就可以看到日志了

PS:还有一种省事的解决方法:在配置文件usr.lib.ipsec.charon中查找已经存在的权限为rw的文件或者文件夹,将日志文件放到那里就可以(比如:/run/charon.* rw,可以将日志文件配置到:/run/charon.log,虽然停止进程就会删除这个文件),按照不同需求来配置吧。

猜你在找的Ubuntu相关文章