render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
a41c76
From ffe8028ca07eb049b12d5c152b3d66489378d731 Mon Sep 17 00:00:00 2001
a41c76
Message-Id: <ffe8028ca07eb049b12d5c152b3d66489378d731@dist-git>
a41c76
From: Peter Krempa <pkrempa@redhat.com>
a41c76
Date: Mon, 16 Mar 2020 22:11:56 +0100
a41c76
Subject: [PATCH] conf: Add support for modifying ssl validation for https/ftps
a41c76
 disks
a41c76
MIME-Version: 1.0
a41c76
Content-Type: text/plain; charset=UTF-8
a41c76
Content-Transfer-Encoding: 8bit
a41c76
a41c76
To allow turning off verification of SSL cerificates add a new element
a41c76
<ssl> to the disk source XML which will allow configuring the validation
a41c76
process using the 'verify' attribute.
a41c76
a41c76
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
(cherry picked from commit 25481e25b14108373bf2e5e95c04fe30bff96bb4)
a41c76
a41c76
https://bugzilla.redhat.com/show_bug.cgi?id=1804750
a41c76
Message-Id: <ede13179128fc9ef05036a5408f4115132a2c12d.1584391727.git.pkrempa@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
---
a41c76
 docs/formatdomain.html.in                     |  9 ++++
a41c76
 docs/schemas/domaincommon.rng                 | 51 ++++++++++++++++++-
a41c76
 src/conf/domain_conf.c                        | 19 +++++++
a41c76
 src/util/virstoragefile.c                     |  1 +
a41c76
 src/util/virstoragefile.h                     |  1 +
a41c76
 .../disk-network-http.xml                     |  9 ++++
a41c76
 6 files changed, 88 insertions(+), 2 deletions(-)
a41c76
a41c76
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
a41c76
index e9830ab231..2cce247958 100644
a41c76
--- a/docs/formatdomain.html.in
a41c76
+++ b/docs/formatdomain.html.in
a41c76
@@ -2847,6 +2847,7 @@
a41c76
     <driver name='qemu' type='raw'/>
a41c76
     <source protocol="https" name="url_path">
a41c76
       <host name="hostname" port="443"/>
a41c76
+      <ssl verify="no"/>
a41c76
     </source>
a41c76
     <target dev='hdf' bus='ide' tray='open'/>
a41c76
     <readonly/>
a41c76
@@ -3373,6 +3374,14 @@
a41c76
             The offset and size values are in bytes.
a41c76
             Since 6.1.0
a41c76
           
a41c76
+          
ssl
a41c76
+          
a41c76
+            For https and ftps accessed storage it's
a41c76
+            possible to tweak the SSL transport parameters with this element.
a41c76
+            The verify attribute allows to turn on or off SSL
a41c76
+            certificate validation. Supported values are yes and
a41c76
+            no. Since 6.2.0
a41c76
+          
a41c76
         
a41c76
 
a41c76
         

a41c76
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
a41c76
index aa70e340b9..548601b61c 100644
a41c76
--- a/docs/schemas/domaincommon.rng
a41c76
+++ b/docs/schemas/domaincommon.rng
a41c76
@@ -1808,12 +1808,39 @@
a41c76
     </element>
a41c76
   </define>
a41c76
 
a41c76
+  <define name="diskSourceNetworkProtocolSSLVerify">
a41c76
+    <element name="ssl">
a41c76
+      <attribute name="verify">
a41c76
+        <ref name="virYesNo"/>
a41c76
+      </attribute>
a41c76
+      <empty/>
a41c76
+    </element>
a41c76
+  </define>
a41c76
+
a41c76
+  <define name="diskSourceNetworkProtocolHTTPS">
a41c76
+    <element name="source">
a41c76
+      <attribute name="protocol">
a41c76
+        <choice>
a41c76
+          <value>https</value>
a41c76
+        </choice>
a41c76
+      </attribute>
a41c76
+      <attribute name="name"/>
a41c76
+      <ref name="diskSourceCommon"/>
a41c76
+      <ref name="diskSourceNetworkHost"/>
a41c76
+      <optional>
a41c76
+        <ref name="encryption"/>
a41c76
+      </optional>
a41c76
+      <optional>
a41c76
+        <ref name="diskSourceNetworkProtocolSSLVerify"/>
a41c76
+      </optional>
a41c76
+    </element>
a41c76
+  </define>
a41c76
+
a41c76
   <define name="diskSourceNetworkProtocolHTTP">
a41c76
     <element name="source">
a41c76
       <attribute name="protocol">
a41c76
         <choice>
a41c76
           <value>http</value>
a41c76
-          <value>https</value>
a41c76
         </choice>
a41c76
       </attribute>
a41c76
       <attribute name="name"/>
a41c76
@@ -1825,13 +1852,31 @@
a41c76
     </element>
a41c76
   </define>
a41c76
 
a41c76
+  <define name="diskSourceNetworkProtocolFTPS">
a41c76
+    <element name="source">
a41c76
+      <attribute name="protocol">
a41c76
+        <choice>
a41c76
+          <value>ftps</value>
a41c76
+        </choice>
a41c76
+      </attribute>
a41c76
+      <attribute name="name"/>
a41c76
+      <ref name="diskSourceCommon"/>
a41c76
+      <ref name="diskSourceNetworkHost"/>
a41c76
+      <optional>
a41c76
+        <ref name="encryption"/>
a41c76
+      </optional>
a41c76
+      <optional>
a41c76
+        <ref name="diskSourceNetworkProtocolSSLVerify"/>
a41c76
+      </optional>
a41c76
+    </element>
a41c76
+  </define>
a41c76
+
a41c76
   <define name="diskSourceNetworkProtocolSimple">
a41c76
     <element name="source">
a41c76
       <attribute name="protocol">
a41c76
         <choice>
a41c76
           <value>sheepdog</value>
a41c76
           <value>ftp</value>
a41c76
-          <value>ftps</value>
a41c76
           <value>tftp</value>
a41c76
         </choice>
a41c76
       </attribute>
a41c76
@@ -1909,6 +1954,8 @@
a41c76
       <ref name="diskSourceNetworkProtocolRBD"/>
a41c76
       <ref name="diskSourceNetworkProtocolISCSI"/>
a41c76
       <ref name="diskSourceNetworkProtocolHTTP"/>
a41c76
+      <ref name="diskSourceNetworkProtocolHTTPS"/>
a41c76
+      <ref name="diskSourceNetworkProtocolFTPS"/>
a41c76
       <ref name="diskSourceNetworkProtocolSimple"/>
a41c76
       <ref name="diskSourceNetworkProtocolVxHS"/>
a41c76
     </choice>
a41c76
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
a41c76
index b3c4084c38..70bbc35bb3 100644
a41c76
--- a/src/conf/domain_conf.c
a41c76
+++ b/src/conf/domain_conf.c
a41c76
@@ -9259,6 +9259,7 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node,
a41c76
     g_autofree char *protocol = NULL;
a41c76
     g_autofree char *haveTLS = NULL;
a41c76
     g_autofree char *tlsCfg = NULL;
a41c76
+    g_autofree char *sslverifystr = NULL;
a41c76
 
a41c76
     if (!(protocol = virXMLPropString(node, "protocol"))) {
a41c76
         virReportError(VIR_ERR_XML_ERROR, "%s",
a41c76
@@ -9331,6 +9332,19 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node,
a41c76
 
a41c76
     virStorageSourceInitiatorParseXML(ctxt, &src->initiator);
a41c76
 
a41c76
+    if ((src->protocol == VIR_STORAGE_NET_PROTOCOL_HTTPS ||
a41c76
+         src->protocol == VIR_STORAGE_NET_PROTOCOL_FTPS) &&
a41c76
+        (sslverifystr = virXPathString("string(./ssl/@verify)", ctxt))) {
a41c76
+        int verify;
a41c76
+        if ((verify = virTristateBoolTypeFromString(sslverifystr)) < 0) {
a41c76
+            virReportError(VIR_ERR_XML_ERROR,
a41c76
+                           _("invalid ssl verify mode '%s'"), sslverifystr);
a41c76
+            return -1;
a41c76
+        }
a41c76
+
a41c76
+        src->sslverify = verify;
a41c76
+    }
a41c76
+
a41c76
     return 0;
a41c76
 }
a41c76
 
a41c76
@@ -24312,6 +24326,11 @@ virDomainDiskSourceFormatNetwork(virBufferPtr attrBuf,
a41c76
 
a41c76
     virStorageSourceInitiatorFormatXML(&src->initiator, childBuf);
a41c76
 
a41c76
+    if (src->sslverify != VIR_TRISTATE_BOOL_ABSENT) {
a41c76
+        virBufferAsprintf(childBuf, "<ssl verify='%s'/>\n",
a41c76
+                          virTristateBoolTypeToString(src->sslverify));
a41c76
+    }
a41c76
+
a41c76
     return 0;
a41c76
 }
a41c76
 
a41c76
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
a41c76
index b88763b267..cfa77fccf8 100644
a41c76
--- a/src/util/virstoragefile.c
a41c76
+++ b/src/util/virstoragefile.c
a41c76
@@ -2270,6 +2270,7 @@ virStorageSourceCopy(const virStorageSource *src,
a41c76
     def->cachemode = src->cachemode;
a41c76
     def->discard = src->discard;
a41c76
     def->detect_zeroes = src->detect_zeroes;
a41c76
+    def->sslverify = src->sslverify;
a41c76
 
a41c76
     /* storage driver metadata are not copied */
a41c76
     def->drv = NULL;
a41c76
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
a41c76
index 5b995d54ab..fab4248c3d 100644
a41c76
--- a/src/util/virstoragefile.h
a41c76
+++ b/src/util/virstoragefile.h
a41c76
@@ -282,6 +282,7 @@ struct _virStorageSource {
a41c76
     virStorageEncryptionPtr encryption;
a41c76
     bool encryptionInherited;
a41c76
     virStoragePRDefPtr pr;
a41c76
+    virTristateBool sslverify;
a41c76
 
a41c76
     virStorageSourceNVMeDefPtr nvme; /* type == VIR_STORAGE_TYPE_NVME */
a41c76
 
a41c76
diff --git a/tests/genericxml2xmlindata/disk-network-http.xml b/tests/genericxml2xmlindata/disk-network-http.xml
a41c76
index fde1222fd0..bdcc1977f2 100644
a41c76
--- a/tests/genericxml2xmlindata/disk-network-http.xml
a41c76
+++ b/tests/genericxml2xmlindata/disk-network-http.xml
a41c76
@@ -25,6 +25,7 @@
a41c76
       <driver name='qemu' type='raw'/>
a41c76
       <source protocol='https' name='test2.img'>
a41c76
         <host name='example.org' port='443'/>
a41c76
+        <ssl verify='no'/>
a41c76
       </source>
a41c76
       <target dev='vdb' bus='virtio'/>
a41c76
     </disk>
a41c76
@@ -35,6 +36,14 @@
a41c76
       </source>
a41c76
       <target dev='vdc' bus='virtio'/>
a41c76
     </disk>
a41c76
+    <disk type='network' device='disk'>
a41c76
+      <driver name='qemu' type='raw'/>
a41c76
+      <source protocol='https' name='test4.img'>
a41c76
+        <host name='example.org' port='1234'/>
a41c76
+        <ssl verify='yes'/>
a41c76
+      </source>
a41c76
+      <target dev='vdd' bus='virtio'/>
a41c76
+    </disk>
a41c76
     <controller type='usb' index='0'/>
a41c76
     <controller type='pci' index='0' model='pci-root'/>
a41c76
     <input type='mouse' bus='ps2'/>
a41c76
-- 
a41c76
2.25.1
a41c76