Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1658319

Summary: Collectd default selinux context for log file makes it impossible for the file to be created and written into
Product: Red Hat Enterprise Linux 7 Reporter: ggrimaux
Component: selinux-policyAssignee: Lukas Vrabec <lvrabec>
Status: CLOSED ERRATA QA Contact: Milos Malik <mmalik>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.5CC: astupnik, dparkes, fgarciad, ggrimaux, jpichon, lvrabec, mmalik, mrunge, plautrba, ssekidde, tjaros, vmojzis, zpytela
Target Milestone: rcKeywords: AutoVerified, Reopened
Target Release: 7.8   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: selinux-policy-3.13.1-259.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-03-31 19:10:44 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1711916    

Description ggrimaux 2018-12-11 18:15:51 UTC
Description of problem:
On a default installation of collectd there isn't a default place to write to a log file using logfile plugin.

On collectd's website: https://collectd.org/wiki/index.php/Plugin:LogFile
They suggest:
  File "/var/log/collectd.log"

If you enable that and start collectd, the file won't be created because the daemon can't write to that location since the file will get the default context of var_log_t.

It should also be able for logrotate to be able to rotate that file with the new context (if you decide on changing it)

Log files could also be in their own subdirectory of /var/log (like /var/log/collectd like other daemons writing there. This would be the best in my opinion)

Version-Release number of selected component (if applicable):
selinux-policy-3.13.1-229.el7_6.6.noarch

How reproducible:
100%

Steps to Reproduce:
1. Install collectd
2. configure logfile in /etc/collectd.conf
   <Plugin logfile>
        LogLevel info
        File "/var/log/collectd.log"
        Timestamp true
        PrintSeverity false
   </Plugin>

3.systemctl start collectd
4 In /var/log/audit/audit.log:

type=PROCTITLE msg=audit(1544551925.528:4919): proctitle="/usr/sbin/collectd"
type=AVC msg=audit(1544551925.528:4920): avc:  denied  { write } for  pid=31778 comm="writer#1" name="log" dev="vda1" ino=4239454 scontext=system_u:system_r:collectd_t:s0 tcontext=system_u:object_r:var_log_t:s0 tclass=dir permissive=0
type=SYSCALL msg=audit(1544551925.528:4920): arch=c000003e syscall=2 success=no exit=-13 a0=561cd53f51d0 a1=441 a2=1b6 a3=24 items=0 ppid=1 pid=31778 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="writer#1" exe="/usr/sbin/collectd" subj=system_u:system_r:collectd_t:s0 key=(null)


Actual results:
The "default" log file can't be created or written into (after a logrotate) since the default context for /var/log is var_log_t and the daemon can't write to it.

Expected results:
Create some kind of standard so files gets created and logrotated properly with SELinux Enforcing.

Additional info:

Comment 2 Milos Malik 2018-12-11 18:27:22 UTC
Unfortunately, there is no special SELinux type defined for collectd log files:

# seinfo -t | grep 'collectd'
   collectd_content_t
   collectd_script_exec_t
   collectd_var_lib_t
   collectd_var_run_t
   collectd_initrc_exec_t
   collectd_unit_file_t
   collectd_client_packet_t
   collectd_port_t
   collectd_htaccess_t
   collectd_script_tmp_t
   collectd_ra_content_t
   collectd_rw_content_t
   collectd_exec_t
   collectd_server_packet_t
   collectd_t
   collectd_script_t
# seinfo -t | grep 'collect.*log'
#

Comment 3 ggrimaux 2018-12-11 18:34:22 UTC
Hi Milos,

What's the solution here ?

Can we create a new type for it ?
Do we reuse one already created ?

Comment 4 Milos Malik 2018-12-11 18:47:34 UTC
Either we can use collectd policy from Fedora / RHEL-8 as inspiration, because it defines the type and rules:

# seinfo -t | grep 'collectd.*log'
   collectd_log_t
#

Or we can use collectd_var_lib_t as workaround:

# mkdir /var/log/collectd
# semanage fcontext -a -t collectd_var_lib_t '/var/log/collectd(/.*)?'
# restorecon -Rv /var/log/collectd

but the /etc/collectd.conf file must contain "/var/log/collectd/collectd.log" instead of "/var/log/collectd.log".

I believe that Lukas Vrabec will be able to create a new type for it.

Comment 15 Zdenek Pytela 2019-02-28 18:59:56 UTC
This issue was not selected to be included in Red Hat Enterprise Linux 7.7 because it is seen either as low or moderate impact to a small number of use-cases. The next release will be in Maintenance Support 1 Phase, which means that qualified Critical and Important Security errata advisories (RHSAs) and Urgent Priority Bug Fix errata advisories (RHBAs) may be released as they become available.

We will now close this issue, but if you believe that it qualifies for the Maintenance Support 1 Phase, please re-open; otherwise, we recommend moving the request to Red Hat Enterprise Linux 8 if applicable.

Comment 34 Lukas Vrabec 2019-09-25 10:50:29 UTC
commit 15144165cf93ca9aa35ca2e65b87473927aaf176 (HEAD -> rawhide)
Author: Lukas Vrabec <lvrabec>
Date:   Wed Sep 25 12:48:53 2019 +0200

    Label /var/log/collectd.log as collectd_log_t

Comment 42 errata-xmlrpc 2020-03-31 19:10:44 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2020:1007