render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
fbe740
From 282f6724e64787451e69dd0f261c7239fa0e79ac Mon Sep 17 00:00:00 2001
fbe740
Message-Id: <282f6724e64787451e69dd0f261c7239fa0e79ac@dist-git>
fbe740
From: Peter Krempa <pkrempa@redhat.com>
fbe740
Date: Tue, 24 Mar 2020 16:26:07 +0100
fbe740
Subject: [PATCH] qemuBlockGetBackingStoreString: Properly handle 'http/s' with
fbe740
 cookies and others
fbe740
MIME-Version: 1.0
fbe740
Content-Type: text/plain; charset=UTF-8
fbe740
Content-Transfer-Encoding: 8bit
fbe740
fbe740
Format cookies into the backing store string without encryption as they
fbe740
will not be visible on the command line when formatting a 'target' only
fbe740
string. In cases when cookies or other options are used we must use the
fbe740
JSON format rather than pure URI.
fbe740
fbe740
Add tests to validate the scenario.
fbe740
fbe740
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
fbe740
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
fbe740
(cherry picked from commit 3b06103e695829c4720baaee8286f20568133ebd)
fbe740
https://bugzilla.redhat.com/show_bug.cgi?id=1804617
fbe740
Message-Id: <aea5c926b86d5dad7dc78f30f2f0e8d95807e58e.1585063415.git.pkrempa@redhat.com>
fbe740
Reviewed-by: Ján Tomko <jtomko@redhat.com>
fbe740
---
fbe740
 src/qemu/qemu_block.c                         | 12 ++++++++++-
fbe740
 tests/qemublocktest.c                         |  2 ++
fbe740
 .../network-http-curlopts-srconly.json        | 17 ++++++++++++++++
fbe740
 .../xml2json/network-http-curlopts.json       | 15 ++++++++++++++
fbe740
 .../xml2json/network-http-curlopts.xml        | 20 +++++++++++++++++++
fbe740
 .../xml2json/network-http-noopts-srconly.json |  9 +++++++++
fbe740
 .../xml2json/network-http-noopts.json         | 14 +++++++++++++
fbe740
 .../xml2json/network-http-noopts.xml          | 15 ++++++++++++++
fbe740
 8 files changed, 103 insertions(+), 1 deletion(-)
fbe740
 create mode 100644 tests/qemublocktestdata/xml2json/network-http-curlopts-srconly.json
fbe740
 create mode 100644 tests/qemublocktestdata/xml2json/network-http-curlopts.json
fbe740
 create mode 100644 tests/qemublocktestdata/xml2json/network-http-curlopts.xml
fbe740
 create mode 100644 tests/qemublocktestdata/xml2json/network-http-noopts-srconly.json
fbe740
 create mode 100644 tests/qemublocktestdata/xml2json/network-http-noopts.json
fbe740
 create mode 100644 tests/qemublocktestdata/xml2json/network-http-noopts.xml
fbe740
fbe740
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
fbe740
index 1f48f559e3..ba7318b074 100644
fbe740
--- a/src/qemu/qemu_block.c
fbe740
+++ b/src/qemu/qemu_block.c
fbe740
@@ -685,6 +685,7 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src,
fbe740
     virJSONValuePtr ret = NULL;
fbe740
     g_autoptr(virURI) uri = NULL;
fbe740
     g_autofree char *uristr = NULL;
fbe740
+    g_autofree char *cookiestr = NULL;
fbe740
 
fbe740
     /**
fbe740
      * Common options:
fbe740
@@ -714,6 +715,9 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src,
fbe740
         if (srcPriv &&
fbe740
             srcPriv->httpcookie)
fbe740
             cookiealias = srcPriv->httpcookie->s.aes.alias;
fbe740
+    } else {
fbe740
+        /* format target string along with cookies */
fbe740
+        cookiestr = qemuBlockStorageSourceGetCookieString(src);
fbe740
     }
fbe740
 
fbe740
     ignore_value(virJSONValueObjectCreate(&ret,
fbe740
@@ -721,6 +725,7 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src,
fbe740
                                           "S:username", username,
fbe740
                                           "S:password-secret", passwordalias,
fbe740
                                           "T:sslverify", src->sslverify,
fbe740
+                                          "S:cookie", cookiestr,
fbe740
                                           "S:cookie-secret", cookiealias,
fbe740
                                           "P:timeout", src->timeout,
fbe740
                                           "P:readahead", src->readahead,
fbe740
@@ -2043,7 +2048,12 @@ qemuBlockGetBackingStoreString(virStorageSourcePtr src,
fbe740
         /* generate simplified URIs for the easy cases */
fbe740
         if (actualType == VIR_STORAGE_TYPE_NETWORK &&
fbe740
             src->nhosts == 1 &&
fbe740
-            src->hosts->transport == VIR_STORAGE_NET_HOST_TRANS_TCP) {
fbe740
+            src->hosts->transport == VIR_STORAGE_NET_HOST_TRANS_TCP &&
fbe740
+            src->timeout == 0 &&
fbe740
+            src->ncookies == 0 &&
fbe740
+            src->sslverify == VIR_TRISTATE_BOOL_ABSENT &&
fbe740
+            src->timeout == 0 &&
fbe740
+            src->readahead == 0) {
fbe740
 
fbe740
             switch ((virStorageNetProtocol) src->protocol) {
fbe740
             case VIR_STORAGE_NET_PROTOCOL_NBD:
fbe740
diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c
fbe740
index cf56c8a983..8b7a50712d 100644
fbe740
--- a/tests/qemublocktest.c
fbe740
+++ b/tests/qemublocktest.c
fbe740
@@ -1212,6 +1212,8 @@ mymain(void)
fbe740
     TEST_DISK_TO_JSON("network-qcow2-backing-chain-cache-unsafe");
fbe740
     TEST_DISK_TO_JSON("dir-fat-cache");
fbe740
     TEST_DISK_TO_JSON("network-nbd-tls");
fbe740
+    TEST_DISK_TO_JSON("network-http-noopts");
fbe740
+    TEST_DISK_TO_JSON("network-http-curlopts");
fbe740
 
fbe740
     TEST_DISK_TO_JSON("block-raw-noopts");
fbe740
     TEST_DISK_TO_JSON("block-raw-reservations");
fbe740
diff --git a/tests/qemublocktestdata/xml2json/network-http-curlopts-srconly.json b/tests/qemublocktestdata/xml2json/network-http-curlopts-srconly.json
fbe740
new file mode 100644
fbe740
index 0000000000..f5645ac2a6
fbe740
--- /dev/null
fbe740
+++ b/tests/qemublocktestdata/xml2json/network-http-curlopts-srconly.json
fbe740
@@ -0,0 +1,17 @@
fbe740
+(
fbe740
+  source only properties:
fbe740
+  {
fbe740
+    "driver": "https",
fbe740
+    "url": "https://host1.example.com:443/something",
fbe740
+    "sslverify": false,
fbe740
+    "cookie": "test=123456; blurb=here"
fbe740
+  }
fbe740
+  backing store string:
fbe740
+  json:{"file":{
fbe740
+    "driver": "https",
fbe740
+    "url": "https://host1.example.com:443/something",
fbe740
+    "sslverify": false,
fbe740
+    "cookie": "test=123456; blurb=here"
fbe740
+  }
fbe740
+  }
fbe740
+)
fbe740
diff --git a/tests/qemublocktestdata/xml2json/network-http-curlopts.json b/tests/qemublocktestdata/xml2json/network-http-curlopts.json
fbe740
new file mode 100644
fbe740
index 0000000000..08dfd1b300
fbe740
--- /dev/null
fbe740
+++ b/tests/qemublocktestdata/xml2json/network-http-curlopts.json
fbe740
@@ -0,0 +1,15 @@
fbe740
+{
fbe740
+  "node-name": "node-b-f",
fbe740
+  "read-only": false,
fbe740
+  "driver": "qcow2",
fbe740
+  "file": "node-a-s",
fbe740
+  "backing": null
fbe740
+}
fbe740
+{
fbe740
+  "driver": "https",
fbe740
+  "url": "https://host1.example.com:443/something",
fbe740
+  "sslverify": false,
fbe740
+  "node-name": "node-a-s",
fbe740
+  "auto-read-only": true,
fbe740
+  "discard": "unmap"
fbe740
+}
fbe740
diff --git a/tests/qemublocktestdata/xml2json/network-http-curlopts.xml b/tests/qemublocktestdata/xml2json/network-http-curlopts.xml
fbe740
new file mode 100644
fbe740
index 0000000000..a656247e2e
fbe740
--- /dev/null
fbe740
+++ b/tests/qemublocktestdata/xml2json/network-http-curlopts.xml
fbe740
@@ -0,0 +1,20 @@
fbe740
+<disk type='network' device='disk'>
fbe740
+  <driver name='qemu' type='qcow2'/>
fbe740
+  <source protocol='https' name='/something'>
fbe740
+    <host name='host1.example.com'/>
fbe740
+    <ssl verify='no'/>
fbe740
+    <cookies>
fbe740
+      <cookie name='test'>123456</cookie>
fbe740
+      <cookie name='blurb'>here</cookie>
fbe740
+    </cookies>
fbe740
+    <privateData>
fbe740
+      <nodenames>
fbe740
+        <nodename type='storage' name='node-a-s'/>
fbe740
+        <nodename type='format' name='node-b-f'/>
fbe740
+      </nodenames>
fbe740
+    </privateData>
fbe740
+  </source>
fbe740
+  <backingStore/>
fbe740
+  <target dev='vda' bus='virtio'/>
fbe740
+  <alias name='virtio-disk0'/>
fbe740
+</disk>
fbe740
diff --git a/tests/qemublocktestdata/xml2json/network-http-noopts-srconly.json b/tests/qemublocktestdata/xml2json/network-http-noopts-srconly.json
fbe740
new file mode 100644
fbe740
index 0000000000..1303623036
fbe740
--- /dev/null
fbe740
+++ b/tests/qemublocktestdata/xml2json/network-http-noopts-srconly.json
fbe740
@@ -0,0 +1,9 @@
fbe740
+(
fbe740
+  source only properties:
fbe740
+  {
fbe740
+    "driver": "https",
fbe740
+    "url": "https://host1.example.com:443/something"
fbe740
+  }
fbe740
+  backing store string:
fbe740
+  https://host1.example.com:443/something
fbe740
+)
fbe740
diff --git a/tests/qemublocktestdata/xml2json/network-http-noopts.json b/tests/qemublocktestdata/xml2json/network-http-noopts.json
fbe740
new file mode 100644
fbe740
index 0000000000..d577858236
fbe740
--- /dev/null
fbe740
+++ b/tests/qemublocktestdata/xml2json/network-http-noopts.json
fbe740
@@ -0,0 +1,14 @@
fbe740
+{
fbe740
+  "node-name": "node-b-f",
fbe740
+  "read-only": false,
fbe740
+  "driver": "qcow2",
fbe740
+  "file": "node-a-s",
fbe740
+  "backing": null
fbe740
+}
fbe740
+{
fbe740
+  "driver": "https",
fbe740
+  "url": "https://host1.example.com:443/something",
fbe740
+  "node-name": "node-a-s",
fbe740
+  "auto-read-only": true,
fbe740
+  "discard": "unmap"
fbe740
+}
fbe740
diff --git a/tests/qemublocktestdata/xml2json/network-http-noopts.xml b/tests/qemublocktestdata/xml2json/network-http-noopts.xml
fbe740
new file mode 100644
fbe740
index 0000000000..f09ff7ba67
fbe740
--- /dev/null
fbe740
+++ b/tests/qemublocktestdata/xml2json/network-http-noopts.xml
fbe740
@@ -0,0 +1,15 @@
fbe740
+<disk type='network' device='disk'>
fbe740
+  <driver name='qemu' type='qcow2'/>
fbe740
+  <source protocol='https' name='/something'>
fbe740
+    <host name='host1.example.com'/>
fbe740
+    <privateData>
fbe740
+      <nodenames>
fbe740
+        <nodename type='storage' name='node-a-s'/>
fbe740
+        <nodename type='format' name='node-b-f'/>
fbe740
+      </nodenames>
fbe740
+    </privateData>
fbe740
+  </source>
fbe740
+  <backingStore/>
fbe740
+  <target dev='vda' bus='virtio'/>
fbe740
+  <alias name='virtio-disk0'/>
fbe740
+</disk>
fbe740
-- 
fbe740
2.26.0
fbe740