Bug 1472709 - setfiles now requires "-m" to restore contexts in some chroot environments
setfiles now requires "-m" to restore contexts in some chroot environments
Status: NEW
Product: Fedora
Classification: Fedora
Component: policycoreutils (Show other bugs)
Unspecified Unspecified
unspecified Severity unspecified
: ---
: ---
Assigned To: Petr Lautrbach
Fedora Extras Quality Assurance
Depends On:
  Show dependency treegraph
Reported: 2017-07-19 04:40 EDT by Ian Wienand
Modified: 2018-02-07 16:06 EST (History)
5 users (show)

See Also:
Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
Last Closed:
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Ian Wienand 2017-07-19 04:40:20 EDT
diskimage-builder builds a fedora image within a chroot environment on a host.  This is happening on an ubuntu xenial system -- this is part of building images for use by the OpenStack CI environment.  We have long had a final step before we create the final image of running "setfiles" within the chroot of the final image to restore contexts so that the image we are building boots quickly [2]

Unfortunately this stopped working with F26.  The setfiles just does nothing at all

# setfiles -d   /etc/selinux/targeted/contexts/files/file_contexts /
# echo $?

If I take the F25 setfiles binary and run it, it works.  So that got me digging into git history, where I noticed the suspect change where F26 has started using selinux_restorecon [3].

Reading this change I noticed "-m"

  ... do not read /proc/mounts to obtain a list of non-seclabel mounts ...

and realised that we're in a chroot environment on a loopback disk on an ubuntu system, so this is probably not matching.  So long story short, the "-m" fixed things for me

I get that what is happening with diskimage-builder is pretty uncommon usage, but it is pretty painful having setfiles having no error code or any output indication of what's going on at all without this flag, when it's been working for literally years.  I had to first figure out how to break into our vms (because lack of selinux meant nothing could log in), figure out it was selinux at fault, then spend considerable time figuring out that the 'setfiles' was doing nothing now during the build, and then correlating this with git history ...

Maybe the cat is out of the bag; but it would be my suggestion that "-m" should be applied by default on setfiles to maintain the behavior with the prior versions.  if anything, a flag should be inverted to turn it off.

[1] https://docs.openstack.org/diskimage-builder/latest/
[2] http://git.openstack.org/cgit/openstack/diskimage-builder/tree/diskimage_builder/elements/rpm-distro/finalise.d/90-selinux-fixfiles-restore
[3] https://github.com/SELinuxProject/selinux/commit/602347c7422e971a5674fe2767267a96e3b4f61c

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