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
CentosはSELinuxに付属しています。このセキュリティコンポーネントは、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
正しいコンテキストを自動的に取得することもできます。