Logrotate“权限被拒绝”错误

Logrotate“权限被拒绝”错误

我正在尝试让 logrotate 正常工作并不断收到以下错误消息。

/etc/cron.daily/logrotate:
error: error accessing /ftp/logs: Permission denied
error: error opening /ftp/logs/sftp_system.log: Permission denied

以下是文件夹权限:

drwxrwx---. 2 psoft psoft          4096 Jun 19 09:05 logs

以下是文件权限:

-rw-rw-r--. 1 psoft psoft  43449642 Jun 19 09:15 sftp_system.log

这是配置:

/ftp/logs/sftp_system.log
{
        su psoft psoft
        size=25M
        rotate 5
        copytruncate
        create 0664 psoft psoft
        notifempty
}

我假设 logrotate 以 root 身份运行。我尝试更改文件和文件夹的权限和所有权,但总是收到相同的消息。我的操作系统是 Oracle Linux 7,基本上是 Redhat 7。

    root@DB-PRD1 etc]# ausearch -ts today -m avc -i
    ----
    type=PROCTITLE msg=audit(06/19/2019 03:09:01.964:15543) : proctitle=/usr/sbin/logrotate -s /var/lib/logrotate/logrotate.status /etc/logrotate.conf
    type=SYSCALL msg=audit(06/19/2019 03:09:01.964:15543) : arch=x86_64 syscall=openat success=no exit=EACCES(Permission denied) a0=0xffffffffffffff9c a1=0x7fff6328bd90 a2=O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC a3=0x0 items=0 ppid=25062 pid=25065 auid=root uid=root gid=root euid=psoft suid=root fsuid=psoft egid=psoft sgid=root fsgid=psoft tty=(none) ses=1688 comm=logrotate exe=/usr/sbin/logrotate subj=system_u:system_r:logrotate_t:s0-s0:c0.c1023 key=(null)
    type=AVC msg=audit(06/19/2019 03:09:01.964:15543) : avc:  denied  { read } for  pid=25065 comm=logrotate name=logs dev="dm-3" ino=2097153 scontext=system_u:system_r:logrotate_t:s0-s0:c0.c1023 tcontext=system_u:object_r:unlabeled_t:s0 tclass=dir permissive=0
    ----
    type=PROCTITLE msg=audit(06/19/2019 03:09:01.965:15544) : proctitle=/usr/sbin/logrotate -s /var/lib/logrotate/logrotate.status /etc/logrotate.conf
    type=SYSCALL msg=audit(06/19/2019 03:09:01.965:15544) : arch=x86_64 syscall=open success=no exit=EACCES(Permission denied) a0=0x2574570 a1=O_RDWR|O_NOFOLLOW a2=0x2574570 a3=0x3630393130322d67 items=0 ppid=25062 pid=25065 auid=root uid=root gid=root euid=psoft suid=root fsuid=psoft egid=psoft sgid=root fsgid=psoft tty=(none) ses=1688 comm=logrotate exe=/usr/sbin/logrotate subj=system_u:system_r:logrotate_t:s0-s0:c0.c1023 key=(null)
    type=AVC msg=audit(06/19/2019 03:09:01.965:15544) : avc:  denied  { read write } for  pid=25065 comm=logrotate name=sftp_system.log dev="dm-3" ino=2097163 scontext=system_u:system_r:logrotate_t:s0-s0:c0.c1023 tcontext=system_u:object_r:unlabeled_t:s0 tclass=file permissive=0
    [root@DB-PRD1 etc]# sestatus
    SELinux status:                 enabled
    SELinuxfs mount:                /sys/fs/selinux
    SELinux root directory:         /etc/selinux
    Loaded policy name:             targeted
    Current mode:                   enforcing
    Mode from config file:          enforcing
    Policy MLS status:              enabled
    Policy deny_unknown status:     allowed
    Max kernel policy version:      29

我今天早上收到这封电子邮件:

/etc/cron.daily/logrotate:

error: error accessing /ftp/logs: Permission denied
error: error creating output file /ftp/logs/sftp_system.log-20190724: Permission denied
[root@DB-PRD1 ftp]# ausearch -ts today -m avc -i
----
type=PROCTITLE msg=audit(07/24/2019 03:06:01.809:69341) : proctitle=/usr/sbin/logrotate -s /var/lib/logrotate/logrotate.status /etc/logrotate.conf
type=SYSCALL msg=audit(07/24/2019 03:06:01.809:69341) : arch=x86_64 syscall=openat success=no exit=EACCES(Permission denied) a0=0xffffffffffffff9c a1=0x7ffe0b8767d0 a2=O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC a3=0x0 items=0 ppid=21723 pid=21725 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=(none) ses=7731 comm=logrotate exe=/usr/sbin/logrotate subj=system_u:system_r:logrotate_t:s0-s0:c0.c1023 key=(null)
type=AVC msg=audit(07/24/2019 03:06:01.809:69341) : avc:  denied  { read } for  pid=21725 comm=logrotate name=logs dev="dm-3" ino=2097153 scontext=system_u:system_r:logrotate_t:s0-s0:c0.c1023 tcontext=system_u:object_r:unlabeled_t:s0 tclass=dir permissive=0
----
type=PROCTITLE msg=audit(07/24/2019 03:06:01.809:69342) : proctitle=/usr/sbin/logrotate -s /var/lib/logrotate/logrotate.status /etc/logrotate.conf
type=SYSCALL msg=audit(07/24/2019 03:06:01.809:69342) : arch=x86_64 syscall=open success=no exit=EACCES(Permission denied) a0=0x1ccb3a0 a1=O_WRONLY|O_CREAT|O_EXCL|O_NOFOLLOW a2=0600 a3=0xe items=0 ppid=21723 pid=21725 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=(none) ses=7731 comm=logrotate exe=/usr/sbin/logrotate subj=system_u:system_r:logrotate_t:s0-s0:c0.c1023 key=(null)
type=AVC msg=audit(07/24/2019 03:06:01.809:69342) : avc:  denied  { write } for  pid=21725 comm=logrotate name=logs dev="dm-3" ino=2097153 scontext=system_u:system_r:logrotate_t:s0-s0:c0.c1023 tcontext=system_u:object_r:unlabeled_t:s0 tclass=dir permissive=0

包含该文件的目录是否也需要具有 var_log_t 访问权限才能正常工作?我将尝试一下,看看是否会有所不同。

[root@DB-PRD1 ftp]# ls -dZ logs
drwxrwx---. psoft psoft system_u:object_r:unlabeled_t:s0 logs

[root@DB-PRD1 logs]# ls -Z
-rw-rw-r--. psoft psoft system_u:object_r:var_log_t:s0   sftp_system.log

答案1

您拥有随 SELinux 一起提供的 Centos。此安全组件阻止logrotate在上下文中运行的进程logrotate_t访问该sftp_system.log文件。

解决方案是通过更改文件的上下文来授予 logrotate 进程对文件的访问权限,如下所示:

semanage fcontext -a -t var_log_t /ftp/logs/sftp_system.log
restorecon -v /ftp/logs/sftp_system.log

如果您没有该semanage命令,请安装它并重试:

yum install -y policycoreutils-python

或者(如果该包不存在):

yum install -y policycoreutils-python-utils

或者,您可以将 SFTP 日志文件从/ftp/根目录移出,/var/log以自动获取正确的上下文。

相关内容