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 1650232 - postconf command alters selinux context of main.cf when run
Summary: postconf command alters selinux context of main.cf when run
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: selinux-policy
Version: 7.5
Hardware: All
OS: Linux
low
low
Target Milestone: rc
: ---
Assignee: Lukas Vrabec
QA Contact: Milos Malik
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2018-11-15 16:07 UTC by afox@redhat.com
Modified: 2019-05-03 15:14 UTC (History)
9 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-02-28 19:07:19 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description afox@redhat.com 2018-11-15 16:07:11 UTC
Description of problem:
Running the postconf command to set a value in /etc/postfix/main.cf always alters the selinux context of that file away from what it should be. For example:

---
[root@eld115:~]# ll -Z /etc/postfix/main.cf 
-rw-r--r--. root root system_u:object_r:postfix_etc_t:s0 /etc/postfix/main.cf
[root@eld115:~]# postconf -e 'mydomain = testdomain.gov.uk'
[root@eld115:~]# ll -Z /etc/postfix/main.cf 
-rw-r--r--. root root unconfined_u:object_r:postfix_etc_t:s0 /etc/postfix/main.cf
---

Using restorecon, then resets the context to what it should be:

---
[root@eld115:~]# restorecon -Fvv /etc/postfix/main.cf
restorecon reset /etc/postfix/main.cf context unconfined_u:object_r:postfix_etc_t:s0->system_u:object_r:postfix_etc_t:s0
[root@eld115:~]# ll -Z /etc/postfix/main.cf 
-rw-r--r--. root root system_u:object_r:postfix_etc_t:s0 /etc/postfix/main.cf
---

Checking/getting a value is fine:

---
[root@eld115:~]# ll -Z /etc/postfix/main.cf 
-rw-r--r--. root root system_u:object_r:postfix_etc_t:s0 /etc/postfix/main.cf
[root@eld115:~]# postconf mydomain
mydomain = metoffice.gov.uk
[root@eld115:~]# ll -Z /etc/postfix/main.cf 
-rw-r--r--. root root system_u:object_r:postfix_etc_t:s0 /etc/postfix/main.cf
---

This means that systems continually flip-flop between having the context for /etc/postfix.main.cf set to one of the two values:

unconfined_u:object_r:postfix_etc_t:s0 main.cf
system_u:object_r:postfix_etc_t:s0 main.cf

Version-Release number of selected component (if applicable):


How reproducible:


Steps to Reproduce:
1. Run postconf command to set a value in main.cf

Actual results:
Running postconf results in selinux context being changed on main.cf

Expected results:
selinux context on main.cf should not change when executing postconf

Comment 3 Jaroslav Škarvada 2019-01-28 15:29:37 UTC
Sorry for delay, I think the best way is to fix it in the SELinux policy instead of adding downstream "hacks" into postconf, the strace output of the postconf:
...
rename("/etc/postfix/main.cf.tmp", "/etc/postfix/main.cf") = 0
...

Reassigning to selinux-policy.

Comment 5 Zdenek Pytela 2019-02-28 19:07:19 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 6 Milos Malik 2019-05-03 14:43:06 UTC
It seems that every time the "postconf ..." is executed, the inode changes. I believe that the postconf utility creates a new file every time.

[root@ci-vm-10-0-136-48 ~]# ls -Z /etc/postfix/main.cf
-rw-r--r--. root root system_u:object_r:postfix_etc_t:s0 /etc/postfix/main.cf
[root@ci-vm-10-0-136-48 ~]# ls -il /etc/postfix/main.cf
145296 -rw-r--r--. 1 root root 27176 May  9  2018 /etc/postfix/main.cf
[root@ci-vm-10-0-136-48 ~]# postconf -e 'mydomain = testdomain.gov.uk'
[root@ci-vm-10-0-136-48 ~]# ls -Z /etc/postfix/main.cf
-rw-r--r--. root root unconfined_u:object_r:postfix_etc_t:s0 /etc/postfix/main.cf
[root@ci-vm-10-0-136-48 ~]# ls -il /etc/postfix/main.cf
169024 -rw-r--r--. 1 root root 27205 May  3 10:28 /etc/postfix/main.cf
[root@ci-vm-10-0-136-48 ~]# restorecon -vF /etc/postfix/main.cf
restorecon reset /etc/postfix/main.cf context unconfined_u:object_r:postfix_etc_t:s0->system_u:object_r:postfix_etc_t:s0
[root@ci-vm-10-0-136-48 ~]# ls -Z /etc/postfix/main.cf
-rw-r--r--. root root system_u:object_r:postfix_etc_t:s0 /etc/postfix/main.cf
[root@ci-vm-10-0-136-48 ~]# ls -il /etc/postfix/main.cf
169024 -rw-r--r--. 1 root root 27205 May  3 10:28 /etc/postfix/main.cf
[root@ci-vm-10-0-136-48 ~]# postconf -e 'mydomain = other-domain.gov.uk'
[root@ci-vm-10-0-136-48 ~]# ls -Z /etc/postfix/main.cf
-rw-r--r--. root root unconfined_u:object_r:postfix_etc_t:s0 /etc/postfix/main.cf
[root@ci-vm-10-0-136-48 ~]# ls -il /etc/postfix/main.cf
145296 -rw-r--r--. 1 root root 27207 May  3 10:30 /etc/postfix/main.cf
[root@ci-vm-10-0-136-48 ~]# restorecon -vF /etc/postfix/main.cf
restorecon reset /etc/postfix/main.cf context unconfined_u:object_r:postfix_etc_t:s0->system_u:object_r:postfix_etc_t:s0
[root@ci-vm-10-0-136-48 ~]# ls -Z /etc/postfix/main.cf
-rw-r--r--. root root system_u:object_r:postfix_etc_t:s0 /etc/postfix/main.cf
[root@ci-vm-10-0-136-48 ~]# ls -il /etc/postfix/main.cf
145296 -rw-r--r--. 1 root root 27207 May  3 10:30 /etc/postfix/main.cf
[root@ci-vm-10-0-136-48 ~]# postconf -e 'mydomain = yet-another.gov.uk'
[root@ci-vm-10-0-136-48 ~]# ls -Z /etc/postfix/main.cf
-rw-r--r--. root root unconfined_u:object_r:postfix_etc_t:s0 /etc/postfix/main.cf
[root@ci-vm-10-0-136-48 ~]# ls -il /etc/postfix/main.cf
169024 -rw-r--r--. 1 root root 27206 May  3 10:34 /etc/postfix/main.cf
[root@ci-vm-10-0-136-48 ~]#

Comment 7 Milos Malik 2019-05-03 14:55:57 UTC
strace output also confirms that setting a value via postconf utility leads to a newly created file (inode changed):

[root@ci-vm-10-0-136-48 ~]# ls -il /etc/postfix/main.cf
169024 -rw-r--r--. 1 root root 27206 May  3 10:34 /etc/postfix/main.cf
[root@ci-vm-10-0-136-48 ~]# ls -Z /etc/postfix/main.cf
-rw-r--r--. root root unconfined_u:object_r:postfix_etc_t:s0 /etc/postfix/main.cf
[root@ci-vm-10-0-136-48 ~]# strace -f -o output.txt postconf -e 'mydomain = traced.gov.uk'
[root@ci-vm-10-0-136-48 ~]# ls -il /etc/postfix/main.cf
145296 -rw-r--r--. 1 root root 27201 May  3 10:47 /etc/postfix/main.cf
[root@ci-vm-10-0-136-48 ~]# ls -Z /etc/postfix/main.cf
-rw-r--r--. root root unconfined_u:object_r:postfix_etc_t:s0 /etc/postfix/main.cf
[root@ci-vm-10-0-136-48 ~]# grep main.cf output.txt 
10314 open("/etc/postfix/main.cf.tmp", O_WRONLY|O_CREAT, 0600) = 3
10314 stat("/etc/postfix/main.cf.tmp", {st_mode=S_IFREG|0600, st_size=0, ...}) = 0
10314 open("/etc/postfix/main.cf", O_RDONLY) = 4
10314 rename("/etc/postfix/main.cf.tmp", "/etc/postfix/main.cf") = 0
[root@ci-vm-10-0-136-48 ~]# 

Getting a value does not create a new file, therefore the inode + SELinux context remain the same:

[root@ci-vm-10-0-136-48 ~]# ls -il /etc/postfix/main.cf
145296 -rw-r--r--. 1 root root 27201 May  3 10:47 /etc/postfix/main.cf
[root@ci-vm-10-0-136-48 ~]# ls -Z /etc/postfix/main.cf
-rw-r--r--. root root system_u:object_r:postfix_etc_t:s0 /etc/postfix/main.cf
[root@ci-vm-10-0-136-48 ~]# postconf mydomain
mydomain = traced.gov.uk
[root@ci-vm-10-0-136-48 ~]# ls -il /etc/postfix/main.cf
145296 -rw-r--r--. 1 root root 27201 May  3 10:47 /etc/postfix/main.cf
[root@ci-vm-10-0-136-48 ~]# ls -Z /etc/postfix/main.cf
-rw-r--r--. root root system_u:object_r:postfix_etc_t:s0 /etc/postfix/main.cf
[root@ci-vm-10-0-136-48 ~]#

Comment 8 Jaroslav Škarvada 2019-05-03 14:57:05 UTC
(In reply to Milos Malik from comment #6)
> It seems that every time the "postconf ..." is executed, the inode changes.
> I believe that the postconf utility creates a new file every time.
> 
> [root@ci-vm-10-0-136-48 ~]# ls -Z /etc/postfix/main.cf
> -rw-r--r--. root root system_u:object_r:postfix_etc_t:s0 /etc/postfix/main.cf
> [root@ci-vm-10-0-136-48 ~]# ls -il /etc/postfix/main.cf
> 145296 -rw-r--r--. 1 root root 27176 May  9  2018 /etc/postfix/main.cf
> [root@ci-vm-10-0-136-48 ~]# postconf -e 'mydomain = testdomain.gov.uk'
> [root@ci-vm-10-0-136-48 ~]# ls -Z /etc/postfix/main.cf
> -rw-r--r--. root root unconfined_u:object_r:postfix_etc_t:s0
> /etc/postfix/main.cf
> [root@ci-vm-10-0-136-48 ~]# ls -il /etc/postfix/main.cf
> 169024 -rw-r--r--. 1 root root 27205 May  3 10:28 /etc/postfix/main.cf
> [root@ci-vm-10-0-136-48 ~]# restorecon -vF /etc/postfix/main.cf
> restorecon reset /etc/postfix/main.cf context
> unconfined_u:object_r:postfix_etc_t:s0->system_u:object_r:postfix_etc_t:s0
> [root@ci-vm-10-0-136-48 ~]# ls -Z /etc/postfix/main.cf
> -rw-r--r--. root root system_u:object_r:postfix_etc_t:s0 /etc/postfix/main.cf
> [root@ci-vm-10-0-136-48 ~]# ls -il /etc/postfix/main.cf
> 169024 -rw-r--r--. 1 root root 27205 May  3 10:28 /etc/postfix/main.cf
> [root@ci-vm-10-0-136-48 ~]# postconf -e 'mydomain = other-domain.gov.uk'
> [root@ci-vm-10-0-136-48 ~]# ls -Z /etc/postfix/main.cf
> -rw-r--r--. root root unconfined_u:object_r:postfix_etc_t:s0
> /etc/postfix/main.cf
> [root@ci-vm-10-0-136-48 ~]# ls -il /etc/postfix/main.cf
> 145296 -rw-r--r--. 1 root root 27207 May  3 10:30 /etc/postfix/main.cf
> [root@ci-vm-10-0-136-48 ~]# restorecon -vF /etc/postfix/main.cf
> restorecon reset /etc/postfix/main.cf context
> unconfined_u:object_r:postfix_etc_t:s0->system_u:object_r:postfix_etc_t:s0
> [root@ci-vm-10-0-136-48 ~]# ls -Z /etc/postfix/main.cf
> -rw-r--r--. root root system_u:object_r:postfix_etc_t:s0 /etc/postfix/main.cf
> [root@ci-vm-10-0-136-48 ~]# ls -il /etc/postfix/main.cf
> 145296 -rw-r--r--. 1 root root 27207 May  3 10:30 /etc/postfix/main.cf
> [root@ci-vm-10-0-136-48 ~]# postconf -e 'mydomain = yet-another.gov.uk'
> [root@ci-vm-10-0-136-48 ~]# ls -Z /etc/postfix/main.cf
> -rw-r--r--. root root unconfined_u:object_r:postfix_etc_t:s0
> /etc/postfix/main.cf
> [root@ci-vm-10-0-136-48 ~]# ls -il /etc/postfix/main.cf
> 169024 -rw-r--r--. 1 root root 27206 May  3 10:34 /etc/postfix/main.cf
> [root@ci-vm-10-0-136-48 ~]#

Are you able to reproduce this on RHEL-8? AFAIK there was no related change in the postfix since RHEL-7, so if it wasn't addressed in the selinux-policy, the problem is probably also there. In such case please clone it to RHEL-8.

Comment 9 Milos Malik 2019-05-03 15:14:25 UTC
The same picture on RHEL-8:

[root@ci-vm-10-0-136-197 ~]# ls -Z /etc/postfix/main.cf
system_u:object_r:postfix_etc_t:s0 /etc/postfix/main.cf
[root@ci-vm-10-0-136-197 ~]# ls -il /etc/postfix/main.cf
10486150 -rw-r--r--. 1 root root 29374 Dec  4 09:13 /etc/postfix/main.cf
[root@ci-vm-10-0-136-197 ~]# postconf -e 'mydomain = testdomain.gov.uk'
[root@ci-vm-10-0-136-197 ~]# ls -Z /etc/postfix/main.cf
unconfined_u:object_r:postfix_etc_t:s0 /etc/postfix/main.cf
[root@ci-vm-10-0-136-197 ~]# ls -il /etc/postfix/main.cf
10486163 -rw-r--r--. 1 root root 29403 May  3 11:10 /etc/postfix/main.cf
[root@ci-vm-10-0-136-197 ~]# restorecon -vF /etc/postfix/main.cf
Relabeled /etc/postfix/main.cf from unconfined_u:object_r:postfix_etc_t:s0 to system_u:object_r:postfix_etc_t:s0
[root@ci-vm-10-0-136-197 ~]# ls -Z /etc/postfix/main.cf
system_u:object_r:postfix_etc_t:s0 /etc/postfix/main.cf
[root@ci-vm-10-0-136-197 ~]# ls -il /etc/postfix/main.cf
10486163 -rw-r--r--. 1 root root 29403 May  3 11:10 /etc/postfix/main.cf
[root@ci-vm-10-0-136-197 ~]# postconf -e 'mydomain = other-domain.gov.uk'
[root@ci-vm-10-0-136-197 ~]# ls -Z /etc/postfix/main.cf
unconfined_u:object_r:postfix_etc_t:s0 /etc/postfix/main.cf
[root@ci-vm-10-0-136-197 ~]# ls -il /etc/postfix/main.cf
10486150 -rw-r--r--. 1 root root 29405 May  3 11:11 /etc/postfix/main.cf
[root@ci-vm-10-0-136-197 ~]#


Note You need to log in before you can comment on or make changes to this bug.