SELinux logrotate 问题

SELinux logrotate 问题

似乎这个话题很受欢迎...所以我想我的 logrotate 无法轮换 tomcat 日志,这有问题。Logrotate 配置设置/etc/logrotate.d/tomcat

/opt/tomcat/apache-tomcat-8.5.37/logs/catalina.out
{
  daily
  missingok
  copytruncate
  rotate 15
}

logrotate.conf 是:

> cat /etc/logrotate.conf
# see "man logrotate" for details
# rotate log files weekly
weekly

# keep 4 weeks worth of backlogs
rotate 12

# create new (empty) log files after rotating old ones
create

# use date as a suffix of the rotated file
dateext

# uncomment this if you want your log files compressed
compress

# RPM packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own wtmp and btmp -- we'll rotate them here
/var/log/wtmp {
   ... skipped ...    
}

/var/log/btmp {
... skipped ...
}

报告的问题audit.log

type=AVC msg=audit(1580286181.904:9833967): avc:  denied  { write } for  pid=25982 comm="logrotate" name="catalina.out-20191228.gz" dev="dm-3" ino=16889774 scontext=system_u:system_r:logrotate_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:usr_t:s0 tclass=file permissive=0
type=SYSCALL msg=audit(1580286181.904:9833967): arch=c000003e syscall=2 success=no exit=-13 a0=b392b0 a1=20002 a2=b392b0 a3=b39580 items=2 ppid=25980 pid=25982 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=72358 comm="logrotate" exe="/usr/sbin/logrotate" subj=system_u:system_r:logrotate_t:s0-s0:c0.c1023 key=(null)
type=CWD msg=audit(1580286181.904:9833967):  cwd="/"
type=PATH msg=audit(1580286181.904:9833967): item=0 name="/opt/tomcat/apache-tomcat-8.5.37/logs/catalina.out-20191228.gz" inode=16889774 dev=fd:03 mode=0100640 ouid=1008 ogid=1009 rdev=00:00 obj=unconfined_u:object_r:usr_t:s0 objtype=NORMAL cap_fp=0000000000000000 cap_fi=0000000000000000 cap_fe=0 cap_fver=0
type=PATH msg=audit(1580286181.904:9833967): item=1 name="/opt/tomcat/apache-tomcat-8.5.37/logs/catalina.out-20191228.gz" inode=16889774 dev=fd:03 mode=0100640 ouid=1008 ogid=1009 rdev=00:00 obj=unconfined_u:object_r:usr_t:s0 objtype=NORMAL cap_fp=0000000000000000 cap_fi=0000000000000000 cap_fe=0 cap_fver=0
type=PROCTITLE msg=audit(1580286181.904:9833967): proctitle=2F7573722F7362696E2F6C6F67726F74617465002D73002F7661722F6C69622F6C6F67726F746174652F6C6F67726F746174652E737461747573002F6574632F6C6F67726F746174652E636F6E66

usr_t因此,让我感到神秘的是,如果目录和其中的文件var_log_t根据策略被标记为正确,为什么 logrotate 会尝试创建具有上下文的文件:

> semanage fcontext -l | grep logs
... skipped ...
/opt/tomcat/apache-tomcat-8.5.37/logs/             all files          system_u:object_r:var_log_t:s0
/opt/tomcat/apache-tomcat-8.5.37/logs              all files          system_u:object_r:var_log_t:s0
/opt/tomcat/apache-tomcat-8.5.37/logs/catalina.out all files          system_u:object_r:var_log_t:s0

可以采取哪些步骤来进一步排除故障?

(这是我在 Unix 和 Linux 部分发布的一个问题的副本)

答案1

所以问题就出来了。问题出在上下文定义上。相反,这 3 个定义

> semanage fcontext -l | grep logs
... skipped ...
/opt/tomcat/apache-tomcat-8.5.37/logs/             all files          system_u:object_r:var_log_t:s0
/opt/tomcat/apache-tomcat-8.5.37/logs              all files          system_u:object_r:var_log_t:s0
/opt/tomcat/apache-tomcat-8.5.37/logs/catalina.out all files          system_u:object_r:var_log_t:s0

已经引入了适当的替代方法

/opt/tomcat/apache-tomcat-8.5.37/logs(/.*)?

相关内容