render / rpms / libvirt

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