]> xenbits.xensource.com Git - libvirt.git/commitdiff
security: apparmor: Use translated disk definitions for disk type=volume
authorPeter Krempa <pkrempa@redhat.com>
Thu, 12 Oct 2023 14:03:41 +0000 (16:03 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 17 Oct 2023 12:16:15 +0000 (14:16 +0200)
The 'virt-aa-helper' process gets a XML of the VM it needs to create a
profile for. For a disk type='volume' this XML contained only the
pool and volume name.

The 'virt-aa-helper' needs a local path though for anything it needs to
label. This means that we'd either need to invoke connection to the
storage driver and re-resolve the volume. Alternative which makes more
sense is to pass the proper data in the XML already passed to it via the
new XML formatter and parser flags.

This was indirectly reported upstream in
https://gitlab.com/libvirt/libvirt/-/issues/546

The configuration in the issue above was created by Cockpit on Debian.
Since Cockpit is getting more popular it's more likely that users will
be impacted by this problem.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/security/security_apparmor.c
src/security/virt-aa-helper.c

index bce797de7c8016fc68a2a549eabdcf0b65de8cb7..6fd0aedacf2b41ef5fd2c74e96965df4d78539af 100644 (file)
@@ -159,13 +159,17 @@ load_profile(virSecurityManager *mgr G_GNUC_UNUSED,
              bool append)
 {
     bool create = true;
+    g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
     g_autofree char *xml = NULL;
     g_autoptr(virCommand) cmd = NULL;
 
-    xml = virDomainDefFormat(def, NULL, VIR_DOMAIN_DEF_FORMAT_SECURE);
-    if (!xml)
+    if (virDomainDefFormatInternal(def, NULL, &buf,
+                                   VIR_DOMAIN_DEF_FORMAT_SECURE |
+                                   VIR_DOMAIN_DEF_FORMAT_VOLUME_TRANSLATED) < 0)
         return -1;
 
+    xml = virBufferContentAndReset(&buf);
+
     if (profile_status_file(profile) >= 0)
         create = false;
 
index 0855eb68cafcf316a57c4e4925d0e9ee87150a39..be13979cefc4f41ed71e999fcccd656920de7661 100644 (file)
@@ -654,7 +654,8 @@ get_definition(vahControl * ctl, const char *xmlStr)
     ctl->def = virDomainDefParseString(xmlStr,
                                        ctl->xmlopt, NULL,
                                        VIR_DOMAIN_DEF_PARSE_SKIP_SECLABEL |
-                                       VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE);
+                                       VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE |
+                                       VIR_DOMAIN_DEF_PARSE_VOLUME_TRANSLATED);
 
     if (ctl->def == NULL) {
         vah_error(ctl, 0, _("could not parse XML"));