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 1626215

Summary: 2 spec file issues
Product: Red Hat Enterprise Linux 7 Reporter: Qian Cai <qcai>
Component: container-selinuxAssignee: Jindrich Novy <jnovy>
Status: CLOSED CURRENTRELEASE QA Contact: atomic-bugs <atomic-bugs>
Severity: high Docs Contact:
Priority: high    
Version: 7.5CC: atomic-bugs, dwalsh, lvrabec, toneata, ypu
Target Milestone: rcKeywords: Extras
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: container-selinux-2.69-3.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1729272 (view as bug list) Environment:
Last Closed: 2020-04-13 09:10:02 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: 1729272    

Description Qian Cai 2018-09-06 18:20:19 UTC
Description of problem:
In order to catch issues like bug 1625772 early so that people won't need to spend tons of time debugging later on with podman/docker issues, it needs %post to return error code once "semodule -i" failed. This line,

   87 %{_sbindir}/semodule -n -X 200 -s %{selinuxtype} -i $MODULES > /dev/null

Right now, rpm will return successful even if the above line failed.

# rpm -Uvh container-selinux-2.69-2.el7.noarch.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
   1:container-selinux-2:2.69-2.el7   ################################# [ 50%]
Failed to resolve allow statement at /etc/selinux/targeted/tmp/modules/200/container/cil:1108
/usr/sbin/semodule:  Failed!
Cleaning up / removing...
   2:container-selinux-2:2.68-1.el7   ################################# [100%]

# echo $?
0

The other issue is that those lines,

     19 # Relabel files
     20 %global relabel_files() %{_sbindir}/restorecon -R %{_bindir}/*podman* %{_bindir}/*runc* %{_bindir}/*crio %{_bindir}/docker* %{_localstatedir}/run/containerd.sock %{_localstatedir}/run/docker.sock %{_loca        lstatedir}/run/docker.pid %{_sysconfdir}/docker %{_sysconfdir}/crio %{_localstatedir}/log/docker %{_localstatedir}/log/lxc %{_localstatedir}/lock/lxc %{_unitdir}/docker.service %{_unitdir}/docker-contain        erd.service %{_unitdir}/docker-latest.service %{_unitdir}/docker-latest-containerd.service %{_sysconfdir}/docker %{_libexecdir}/docker* &> /dev/null || :
     21

     90     %relabel_files
     91     if [ $1 -eq 1 ]; then
     92         restorecon -R %{_sharedstatedir}/docker &> /dev/null || :
     93     fi

This function seems out of date now. The most important things are that,

restorecon -R %{_sharedstatedir}/docker %{_sharedstatedir}/containers

Right now, none of above directories get relabeled after installed/upgraded the packages. Hence, it could cause issues for docker/podman later as directories may still have old (faulty) labels at the first places and never get relabeled properly.

Comment 5 Daniel Walsh 2018-09-14 19:46:30 UTC
Fixed in container-selinux-2.69-3.el7

Comment 6 Qian Cai 2018-09-14 20:20:05 UTC
Unfortunately, I don't think container-selinux-2.69-3.el7 fixes the spec file issues mentioned above.

%changelog
* Thu Sep 6 2018 Dan Walsh <dwalsh> - 2.69-3
- Make sure we pull in the latest selinux-policy

Comment 7 Daniel Walsh 2018-09-17 17:57:57 UTC
This line a couple of lines later should fix label on /var/lib/containers

matchpathcon -qV %{_sharedstatedir}/containers || restorecon -R %{_sharedstatedir}/containers &> /dev/null || :

Comment 8 Joy Pu 2018-09-26 14:12:33 UTC
Can reproduce this with given container-selinux and selinux-policy-3.13.1-192.el7_5.3.noarch in 7.5.4. And container-selinux-2.73-2.el7.noarch request selinux-policy version >= 3.13.1-216. So test with container-selinux-2.73-2.el7.noarch and selinux-policy-3.13.1-225.el7.noarch:
# semodule -X200 -i /usr/share/selinux/packages/container.pp.bz2
semodule -X200 -i /usr/share/selinux/packages/container.pp.bz2 

The command finished as expect. So set this to verified.

Comment 9 Joy Pu 2018-09-26 14:13:19 UTC
Sorry to reply on wrong bug. Set it back.

Comment 10 Daniel Walsh 2018-10-01 17:15:17 UTC
Qian, do agree with my assessment?https://bugzilla.redhat.com/show_bug.cgi?id=1626215#c8

Comment 11 Qian Cai 2018-10-01 17:55:45 UTC
(In reply to Daniel Walsh from comment #7)
> This line a couple of lines later should fix label on /var/lib/containers
> 
> matchpathcon -qV %{_sharedstatedir}/containers || restorecon -R
> %{_sharedstatedir}/containers &> /dev/null || :

That helps one issue but also hope to see some checking for return code from,

87 %{_sbindir}/semodule -n -X 200 -s %{selinuxtype} -i $MODULES > /dev/null

and bail out from rpm with a proper error code with a proper error message something like,

%{_sbindir}/semodule -n -X 200 -s %{selinuxtype} -i $MODULES > /dev/null
if [ $? -ne 0 ]; then
    echo "Error loading SELinux module." >&2
    return 1
fi

Comment 12 Daniel Walsh 2018-10-04 16:00:33 UTC
We can fix this in a future PR.  This is definately not a blocker.

Comment 13 Daniel Walsh 2019-01-10 18:45:11 UTC
Franticek have you made this change?

Comment 15 Qian Cai 2019-07-11 19:51:21 UTC
(In reply to Qian Cai from comment #11)
> (In reply to Daniel Walsh from comment #7)
> > This line a couple of lines later should fix label on /var/lib/containers
> > 
> > matchpathcon -qV %{_sharedstatedir}/containers || restorecon -R
> > %{_sharedstatedir}/containers &> /dev/null || :
> 
> That helps one issue but also hope to see some checking for return code from,
> 
> 87 %{_sbindir}/semodule -n -X 200 -s %{selinuxtype} -i $MODULES > /dev/null
> 
> and bail out from rpm with a proper error code with a proper error message
> something like,
> 
> %{_sbindir}/semodule -n -X 200 -s %{selinuxtype} -i $MODULES > /dev/null
> if [ $? -ne 0 ]; then
>     echo "Error loading SELinux module." >&2
>     return 1
> fi

Well, that is not going to work as rpm still return 0 after post install script section failed.