Red Hat Bugzilla – Bug 1406520
calling libselinux python restorecon fails on /var/lib/nfs/rpc_pipefs
Last modified: 2017-08-01 13:43:16 EDT
Created attachment 1234027 [details] replicato-log I am working on RHEL Atomic enablement on MS Azure, which requires a slightly newer version of cloud-init. Cloud-init eventually calls a restore con on /var/lib before it does any writing of its own. When doing so, it reveals a traceback in libselinux code for the file '/var/lib/nfs/rpc_pipefs'. The unhandled exception causes the provisioning to fail. In looking at the restorecon method, the first failure occurs when matchpathcon is called. The 'OSError' except catches it but then fails again when it is called again in the exception condition. def restorecon(path, recursive=False): """ Restore SELinux context on a given path """ try: mode = os.lstat(path)[stat.ST_MODE] status, context = matchpathcon(path, mode) except OSError: path = os.path.realpath(os.path.expanduser(path)) mode = os.lstat(path)[stat.ST_MODE] status, context = matchpathcon(path, mode) ... Because matchpathcon is likely? in the .so, I am not able to debug further as to why an OSError (file not found) is being thrown. The file is definitely there but probably suffers from some selinux context issue. You can replicate this easily with: >>> import selinux >>> selinux.restorecon('/var/lib/nfs/rpc_pipefs') ... Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib64/python2.7/site-packages/selinux/__init__.py", line 88, in restorecon status, context = matchpathcon(path, mode) OSError: [Errno 2] No such file or directory I'll attach a full log for the above as well as the cloud-init log.
Created attachment 1234028 [details] cloud-init log
This is blocking enablement of RHEL Atomic on Azure which is why I jacked up the priority.
Just to elaborate, it seems like the issue is that /var/lib/nfs/rpc_pipefs is explicitly undefined: # semanage fcontext -l | grep rpc_pipefs /var/lib/nfs/rpc_pipefs(/.*)? all files <<None>> which is probably why the matchpathcon() fails. The rpc_pipefs mount itself is indeed properly labeled as per the refpolicy. Maybe selinux.restorecon() should have a skip_undefined optional bool? To compare the CLI equivalent does not error out on this and instead just prints a warning message.
I tested the suggestion by Dan Walsh at https://github.com/fedora-selinux/selinux/pull/35 and it worked perfectly for my use. Let's monitor the upstream response and then patch the RH package as soon as possible.
Petr can we get this backported to RHEL7?
old version ======== # rpm -qa libselinux\* libselinux-2.5-6.el7.x86_64 libselinux-utils-2.5-6.el7.x86_64 libselinux-python-2.5-6.el7.x86_64 # matchpathcon /run/*.pid /run/auditd.pid system_u:object_r:auditd_var_run_t:s0 /run/crond.pid system_u:object_r:crond_var_run_t:s0 /run/dhclient-eth0.pid system_u:object_r:dhcpc_var_run_t:s0 /run/gssproxy.pid system_u:object_r:gssproxy_var_run_t:s0 /run/lvmetad.pid <<none>> /run/rhnsd.pid system_u:object_r:rhnsd_var_run_t:s0 /run/rpc.statd.pid system_u:object_r:rpcd_var_run_t:s0 /run/sm-notify.pid system_u:object_r:rpcd_var_run_t:s0 /run/sshd.pid system_u:object_r:sshd_var_run_t:s0 /run/syslogd.pid system_u:object_r:syslogd_var_run_t:s0 # python Python 2.7.5 (default, Aug 2 2016, 04:20:16) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import selinux >>> selinux.restorecon('/run/lvmetad.pid') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib64/python2.7/site-packages/selinux/__init__.py", line 85, in restorecon status, context = matchpathcon(path, mode) OSError: [Errno 2] No such file or directory >>> new version ======== # rpm -qa libselinux\* libselinux-2.5-7.el7.x86_64 libselinux-utils-2.5-7.el7.x86_64 libselinux-python-2.5-7.el7.x86_64 # matchpathcon /run/*.pid /run/auditd.pid system_u:object_r:auditd_var_run_t:s0 /run/crond.pid system_u:object_r:crond_var_run_t:s0 /run/dhclient-eth0.pid system_u:object_r:dhcpc_var_run_t:s0 /run/gssproxy.pid system_u:object_r:gssproxy_var_run_t:s0 /run/lvmetad.pid <<none>> /run/rhnsd.pid system_u:object_r:rhnsd_var_run_t:s0 /run/rpc.statd.pid system_u:object_r:rpcd_var_run_t:s0 /run/sm-notify.pid system_u:object_r:rpcd_var_run_t:s0 /run/sshd.pid system_u:object_r:sshd_var_run_t:s0 /run/syslogd.pid system_u:object_r:syslogd_var_run_t:s0 [0 root@qeos-100 ~]# python Python 2.7.5 (default, Aug 2 2016, 04:20:16) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import selinux >>> selinux.restorecon('/run/lvmetad.pid') >>> The fix is OK. Of course, it works well with /var/lib/nfs/rpc_pipefs.
Brent do we need this prior to 7.4?
In comment 6, Milos says he will do a zstream which will help with testing. Other that, we dont need earlier (like RHEL6)
*** Bug 1396293 has been marked as a duplicate of this bug. ***
(In reply to Brent Baude from comment #14) > In comment 6, Milos says he will do a zstream which will help with testing. > Other that, we dont need earlier (like RHEL6) Actually, I am seeing the symptoms of bug 1396293 in CentOS 6.8: # python Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import selinux >>> selinux.restorecon('/var/lib/nfs/rpc_pipefs') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib64/python2.6/site-packages/selinux/__init__.py", line 80, in restorecon status, context = matchpathcon(path, mode) OSError: [Errno 2] No such file or directory I'm aware that since this comes from CentOS, it doesn't necessarily affect RHEL, but I thought I would mention it since there probably are chef users affected by bug 1396293 under RHEL 6.8.
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-2017:1853