libvirt/tests/qemuxml2xmloutdata
Eric Blake 0f082e699e selinux: distinguish failure to label from request to avoid label
https://bugzilla.redhat.com/show_bug.cgi?id=924153

Commit 904e05a2 (v0.9.9) added a per-<disk> seclabel element with
an attribute relabel='no' in order to try and minimize the
impact of shutdown delays when an NFS server disappears.  The idea
was that if a disk is on NFS and can't be labeled in the first
place, there is no need to attempt the (no-op) relabel on domain
shutdown.  Unfortunately, the way this was implemented was by
modifying the domain XML so that the optimization would survive
libvirtd restart, but in a way that is indistinguishable from an
explicit user setting.  Furthermore, once the setting is turned
on, libvirt avoids attempts at labeling, even for operations like
snapshot or blockcopy where the chain is being extended or pivoted
onto non-NFS, where SELinux labeling is once again possible.  As
a result, it was impossible to do a blockcopy to pivot from an
NFS image file onto a local file.

The solution is to separate the semantics of a chain that must
not be labeled (which the user can set even on persistent domains)
vs. the optimization of not attempting a relabel on cleanup (a
live-only annotation), and using only the user's explicit notation
rather than the optimization as the decision on whether to skip
a label attempt in the first place.  When upgrading an older
libvirtd to a newer, an NFS volume will still attempt the relabel;
but as the avoidance of a relabel was only an optimization, this
shouldn't cause any problems.

In the ideal future, libvirt will eventually have XML describing
EVERY file in the backing chain, with each file having a separate
<seclabel> element.  At that point, libvirt will be able to track
more closely which files need a relabel attempt at shutdown.  But
until we reach that point, the single <seclabel> for the entire
<disk> chain is treated as a hint - when a chain has only one
file, then we know it is accurate; but if the chain has more than
one file, we have to attempt relabel in spite of the attribute,
in case part of the chain is local and SELinux mattered for that
portion of the chain.

* src/conf/domain_conf.h (_virSecurityDeviceLabelDef): Add new
member.
* src/conf/domain_conf.c (virSecurityDeviceLabelDefParseXML):
Parse it, for live images only.
(virSecurityDeviceLabelDefFormat): Output it.
(virDomainDiskDefParseXML, virDomainChrSourceDefParseXML)
(virDomainDiskSourceDefFormat, virDomainChrDefFormat)
(virDomainDiskDefFormat): Pass flags on through.
* src/security/security_selinux.c
(virSecuritySELinuxRestoreSecurityImageLabelInt): Honor labelskip
when possible.
(virSecuritySELinuxSetSecurityFileLabel): Set labelskip, not
norelabel, if labeling fails.
(virSecuritySELinuxSetFileconHelper): Fix indentation.
* docs/formatdomain.html.in (seclabel): Document new xml.
* docs/schemas/domaincommon.rng (devSeclabel): Allow it in RNG.
* tests/qemuxml2argvdata/qemuxml2argv-seclabel-*-labelskip.xml:
* tests/qemuxml2argvdata/qemuxml2argv-seclabel-*-labelskip.args:
* tests/qemuxml2xmloutdata/qemuxml2xmlout-seclabel-*-labelskip.xml:
New test files.
* tests/qemuxml2argvtest.c (mymain): Run the new tests.
* tests/qemuxml2xmltest.c (mymain): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2013-08-20 10:39:03 -06:00
..
qemuxml2xmlout-balloon-device-auto.xml conf: Swap order of AddImplicitControllers and DomainDefPostParse 2013-06-28 09:52:00 +02:00
qemuxml2xmlout-channel-virtio-auto.xml conf: Swap order of AddImplicitControllers and DomainDefPostParse 2013-06-28 09:52:00 +02:00
qemuxml2xmlout-console-compat-auto.xml qemu: auto-add pci-root controller for pc machine types 2013-04-25 13:05:10 +02:00
qemuxml2xmlout-console-virtio.xml conf: Swap order of AddImplicitControllers and DomainDefPostParse 2013-06-28 09:52:00 +02:00
qemuxml2xmlout-disk-cdrom-empty.xml numad: Always output 'placement' of <vcpu> 2012-05-08 16:57:37 -06:00
qemuxml2xmlout-disk-mirror.xml qemu: auto-add pci-root controller for pc machine types 2013-04-25 13:05:10 +02:00
qemuxml2xmlout-disk-scsi-device-auto.xml conf: Swap order of AddImplicitControllers and DomainDefPostParse 2013-06-28 09:52:00 +02:00
qemuxml2xmlout-graphics-listen-network2.xml qemu: auto-add pci-root controller for pc machine types 2013-04-25 13:05:10 +02:00
qemuxml2xmlout-graphics-spice-timeout.xml qemu: auto-add pci-root controller for pc machine types 2013-04-25 13:05:10 +02:00
qemuxml2xmlout-hostdev-scsi-autogen-address.xml conf: Generate address for scsi host device automatically 2013-06-01 10:00:23 +08:00
qemuxml2xmlout-memtune.xml qemu: auto-add pci-root controller for pc machine types 2013-04-25 13:05:10 +02:00
qemuxml2xmlout-metadata.xml qemu: auto-add pci-root controller for pc machine types 2013-04-25 13:05:10 +02:00
qemuxml2xmlout-numad-auto-memory-vcpu-cpuset.xml qemu: auto-add pci-root controller for pc machine types 2013-04-25 13:05:10 +02:00
qemuxml2xmlout-numad-auto-memory-vcpu-no-cpuset-and-placement.xml qemu: auto-add pci-root controller for pc machine types 2013-04-25 13:05:10 +02:00
qemuxml2xmlout-numad-auto-vcpu-no-numatune.xml qemu: auto-add pci-root controller for pc machine types 2013-04-25 13:05:10 +02:00
qemuxml2xmlout-numad-static-vcpu-no-numatune.xml numad: Set memory policy from numad advisory nodeset 2012-05-08 16:57:32 -06:00
qemuxml2xmlout-pci-autoadd-addr.xml qemu: auto-add bridges and allow using them 2013-04-25 13:19:40 +02:00
qemuxml2xmlout-pci-autoadd-idx.xml qemu: auto-add bridges and allow using them 2013-04-25 13:19:40 +02:00
qemuxml2xmlout-pci-bridge-many-disks.xml qemu: set/validate slot/connection type when assigning slots for PCI devices 2013-07-24 06:45:07 -04:00
qemuxml2xmlout-pcie-root.xml qemu: fix handling of default/implicit devices for q35 2013-08-05 15:47:49 -04:00
qemuxml2xmlout-q35.xml qemu: enable using implicit sata controller in q35 machines 2013-08-06 13:37:36 -04:00
qemuxml2xmlout-s390-defaultconsole.xml S390: Testcase for console default target type (virtio) 2013-06-28 09:52:00 +02:00
qemuxml2xmlout-seclabel-dynamic-labelskip.xml selinux: distinguish failure to label from request to avoid label 2013-08-20 10:39:03 -06:00
qemuxml2xmlout-serial-target-port-auto.xml qemu: auto-add pci-root controller for pc machine types 2013-04-25 13:05:10 +02:00
qemuxml2xmlout-usb-ich9-ehci-addr.xml qemu: auto-add pci-root controller for pc machine types 2013-04-25 13:05:10 +02:00