SELinux logrotate issue

logrotateselinux

It seems the topic is quite popular… So I figured I have issues with my logrotate not being able to rotate tomcat logs. Logrotate configuration is set in /etc/logrotate.d/tomcat as

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

And logrotate.conf is:

> 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 ...
}

The problem reported in audit.log is

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

So what is mysterious to me is why logrotate would try to create file with context usr_t if the dir and files inside it are tagged as var_log_t according to the policy:

> 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

What can be the steps to troubleshoot further?

(it's a copy of a question I posted into Unix & Linux section)

Best Answer

So the issue figured. Problem was with context definitions. Instead all of those 3 definitions

> 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

a proper replacement has been introduced

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