render / rpms / libvirt

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