Bug 1089100 - NetworkManager avc unlink denied for resolv.conf after using --selinux-relabel
Summary: NetworkManager avc unlink denied for resolv.conf after using --selinux-relabel
Keywords:
Status: CLOSED UPSTREAM
Alias: None
Product: Virtualization Tools
Classification: Community
Component: libguestfs
Version: unspecified
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Pino Toscano
QA Contact:
URL:
Whiteboard:
: 1084221 1122907 (view as bug list)
Depends On:
Blocks: 554829 983969
TreeView+ depends on / blocked
 
Reported: 2014-04-17 23:39 UTC by Richard Su
Modified: 2016-07-14 14:48 UTC (History)
9 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2016-07-14 14:48:47 UTC
Embargoed:


Attachments (Terms of Use)
audit.log from f20 instance using image created by virt-builder (1.32 MB, text/x-log)
2014-04-17 23:41 UTC, Richard Su
no flags Details
Output of virt-builder run with --update and --install options used (278.77 KB, text/plain)
2015-06-08 16:30 UTC, Martin Bukatovic
no flags Details

Description Richard Su 2014-04-17 23:39:56 UTC
Description of problem:
Adding --selinux-relabel fixes all of the avcs denials I was seeing from a freshly built image. Only one remain

type=AVC msg=audit(1397776942.679:469): avc:  denied  { unlink } for  pid=343 comm="NetworkManager" name="resolv.conf" dev="sda3" ino=137360 scontext=system_u:system_r:NetworkManager_t:s0 tcontext=system_u:object_r:etc_t:s0 tclass=file

I see it logged each time the instance is rebooted.

Running "restorecon -R /" fixes it.

This is appears to be a virt-builder bug in how it is relabeling the file system

Version-Release number of selected component (if applicable):
libguestfs-tools-c-1.26.0-1.fc20.x86_64
libguestfs-tools-1.26.0-1.fc20.noarch
libguestfs-1.26.0-1.fc20.x86_64

How reproducible:
always

Steps to Reproduce:
1. Build image using https://github.com/agroup/instack-undercloud/blob/master/README-virt.md, you may need to use the latest instack-virt-setup script from aster as it includes --selinux-relabel

Actual results:
avc logged

Expected results:
no avc logged

Additional info:

Comment 1 Richard Su 2014-04-17 23:41:52 UTC
Created attachment 887366 [details]
audit.log from f20 instance using image created by virt-builder

Comment 2 Pino Toscano 2014-04-18 13:32:23 UTC
The "autorelabel way" (since libguestfs >= 1.25.47) is to run the following shell snippet on the guest:
      if load_policy && fixfiles restore; then
        rm -f /.autorelabel
      else
        touch /.autorelabel
        echo '%s: SELinux relabelling failed, will relabel at boot instead.'
      fi
you should see it in the log of virt-builder, saved by default as /tmp/builder.log (or /builder.log if /tmp does not exist).

On our side, running commands in the guest requires the daemon to setup a mini-environment every time, including (if the network in the guest is not disabled) moving away the existing /etc/resolv.conf, copying the one from the appliance root (and restoring the old one after the execution of the command).
I didn't do further tests yet, but I suspect that having /etc/resolv.conf restored in its place after the policy fix command should not seen in a good way by selinux.

A couple of workarounds/things to check:
a) running virt-builder --no-network (so without being able to install stuff from internet, though) should not cause the issue
b) forcing the autorelabel, using --run "touch /.autorelabel"

Will take a further look (if Rich doesn't beat me to it) in few days.

Comment 3 Richard W.M. Jones 2014-04-22 10:28:43 UTC
I've actually seen some SELinux relabelling strangeness with
virt-builder from git too.  For example I had several files in
/usr/lib64 which were not labelled even though autorelabel had
been done (bug 1088571).  Again I had to manually run restorecon
(twice!) to fix things.  Something is broken here but I've not
had a chance to look at it yet.

Comment 4 Pino Toscano 2014-05-26 09:24:42 UTC
There have been discussions and work toward this:
  https://www.redhat.com/archives/libguestfs/2014-April/msg00070.html
  https://www.redhat.com/archives/libguestfs/2014-May/msg00067.html
  https://www.redhat.com/archives/libguestfs/2014-May/msg00094.html

with a couple of RFC-like patches posted in the last thread.

Comment 5 Pino Toscano 2014-07-24 11:35:58 UTC
*** Bug 1122907 has been marked as a duplicate of this bug. ***

Comment 6 Richard W.M. Jones 2015-03-11 13:55:02 UTC
*** Bug 1084221 has been marked as a duplicate of this bug. ***

Comment 7 Mairi Dulaney 2015-03-13 14:53:33 UTC
Hitting this with virt-configure installing ssh keys.

Comment 8 Martin Bukatovic 2015-06-08 14:38:54 UTC
Hitting this with virt-builder --update and/or --install

Comment 9 Richard W.M. Jones 2015-06-08 14:41:25 UTC
(In reply to Martin Bukatovic from comment #8)
> Hitting this with virt-builder --update and/or --install

Please attach the full debug output (virt-builder -v -x)

Comment 10 Martin Bukatovic 2015-06-08 16:30:09 UTC
Created attachment 1036442 [details]
Output of virt-builder run with --update and --install options used

Attaching full debug output of the following command:

virt-builder fedora-22 \
  --size 15G \
  --format qcow2 \
  --hostname bigtopdev.telesto.local \
  --update \
  --install "gradle,groovy" \
  --output reproducer.qcow2 \
  -x -v 2>&1 | tee virt-builder.output

libguestfs-tools-c-1.28.10-1.fc21.x86_64 used

Resulting issue is the same as described in dupl. BZ 1084221.

Comment 11 Richard W.M. Jones 2015-06-08 16:50:49 UTC
(In reply to Martin Bukatovic from comment #10)
> Created attachment 1036442 [details]
> Output of virt-builder run with --update and --install options used
> 
> Attaching full debug output of the following command:
> 
> virt-builder fedora-22 \
>   --size 15G \
>   --format qcow2 \
>   --hostname bigtopdev.telesto.local \
>   --update \
>   --install "gradle,groovy" \
>   --output reproducer.qcow2 \
>   -x -v 2>&1 | tee virt-builder.output

So to be clear, it works if you add --selinux-relabel to the
command line?

Comment 12 Martin Bukatovic 2015-06-08 17:33:31 UTC
(In reply to Richard W.M. Jones from comment #11)
> (In reply to Martin Bukatovic from comment #10)
> > Created attachment 1036442 [details]
> > Output of virt-builder run with --update and --install options used
> > 
> > Attaching full debug output of the following command:
> > 
> > virt-builder fedora-22 \
> >   --size 15G \
> >   --format qcow2 \
> >   --hostname bigtopdev.telesto.local \
> >   --update \
> >   --install "gradle,groovy" \
> >   --output reproducer.qcow2 \
> >   -x -v 2>&1 | tee virt-builder.output
> 
> So to be clear, it works if you add --selinux-relabel to the
> command line?

Yes, then it works.


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