render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
d76c62
From 79e5b82ba66bbf8cbf55701013749ed155d92633 Mon Sep 17 00:00:00 2001
d76c62
Message-Id: <79e5b82ba66bbf8cbf55701013749ed155d92633@dist-git>
d76c62
From: Peter Krempa <pkrempa@redhat.com>
d76c62
Date: Mon, 16 Mar 2020 22:12:05 +0100
d76c62
Subject: [PATCH] qemu: block: Add support for HTTP cookies
d76c62
MIME-Version: 1.0
d76c62
Content-Type: text/plain; charset=UTF-8
d76c62
Content-Transfer-Encoding: 8bit
d76c62
d76c62
Pass the alias of the secret object holding the cookie data as
d76c62
'cookie-secret' to qemu.
d76c62
d76c62
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
d76c62
Reviewed-by: Ján Tomko <jtomko@redhat.com>
d76c62
(cherry picked from commit 06d3e8d5398f9ed292b84a18c3bb6ea4034a772e)
d76c62
d76c62
https://bugzilla.redhat.com/show_bug.cgi?id=1804750
d76c62
Message-Id: <1bed750b384b4f553f36cff4782fc29e32af7ca4.1584391727.git.pkrempa@redhat.com>
d76c62
Reviewed-by: Ján Tomko <jtomko@redhat.com>
d76c62
---
d76c62
 src/qemu/qemu_block.c                              | 14 +++++++++++---
d76c62
 .../disk-network-http.x86_64-latest.args           | 11 +++++++++--
d76c62
 tests/qemuxml2argvdata/disk-network-http.xml       |  8 ++++++++
d76c62
 3 files changed, 28 insertions(+), 5 deletions(-)
d76c62
d76c62
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
d76c62
index f07420b6e2..80a8c7296d 100644
d76c62
--- a/src/qemu/qemu_block.c
d76c62
+++ b/src/qemu/qemu_block.c
d76c62
@@ -680,6 +680,7 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src,
d76c62
 {
d76c62
     qemuDomainStorageSourcePrivatePtr srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src);
d76c62
     const char *passwordalias = NULL;
d76c62
+    const char *cookiealias = NULL;
d76c62
     const char *username = NULL;
d76c62
     virJSONValuePtr ret = NULL;
d76c62
     g_autoptr(virURI) uri = NULL;
d76c62
@@ -704,9 +705,15 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src,
d76c62
     if (!(uristr = virURIFormat(uri)))
d76c62
         return NULL;
d76c62
 
d76c62
-    if (!onlytarget && src->auth) {
d76c62
-        username = src->auth->username;
d76c62
-        passwordalias = srcPriv->secinfo->s.aes.alias;
d76c62
+    if (!onlytarget) {
d76c62
+        if (src->auth) {
d76c62
+            username = src->auth->username;
d76c62
+            passwordalias = srcPriv->secinfo->s.aes.alias;
d76c62
+        }
d76c62
+
d76c62
+        if (srcPriv &&
d76c62
+            srcPriv->httpcookie)
d76c62
+            cookiealias = srcPriv->httpcookie->s.aes.alias;
d76c62
     }
d76c62
 
d76c62
     ignore_value(virJSONValueObjectCreate(&ret,
d76c62
@@ -714,6 +721,7 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src,
d76c62
                                           "S:username", username,
d76c62
                                           "S:password-secret", passwordalias,
d76c62
                                           "T:sslverify", src->sslverify,
d76c62
+                                          "S:cookie-secret", cookiealias,
d76c62
                                           NULL));
d76c62
 
d76c62
     return ret;
d76c62
diff --git a/tests/qemuxml2argvdata/disk-network-http.x86_64-latest.args b/tests/qemuxml2argvdata/disk-network-http.x86_64-latest.args
d76c62
index 86e4597a81..cbb69e16a9 100644
d76c62
--- a/tests/qemuxml2argvdata/disk-network-http.x86_64-latest.args
d76c62
+++ b/tests/qemuxml2argvdata/disk-network-http.x86_64-latest.args
d76c62
@@ -39,15 +39,22 @@ id=virtio-disk0,bootindex=1 \
d76c62
 "file":"libvirt-3-storage"}' \
d76c62
 -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x3,drive=libvirt-3-format,\
d76c62
 id=virtio-disk1 \
d76c62
+-object secret,id=libvirt-2-storage-httpcookie-secret0,\
d76c62
+data=DrPR9NA6GKJb7qi1KbjHad3f3UIGTTDmAmOZHHv1F5w5T8rhnk3f+uSKStHe0J2O,\
d76c62
+keyid=masterKey0,iv=AAECAwQFBgcICQoLDA0ODw==,format=base64 \
d76c62
 -blockdev '{"driver":"http","url":"http://example.org:1234/test3.img",\
d76c62
+"cookie-secret":"libvirt-2-storage-httpcookie-secret0",\
d76c62
 "node-name":"libvirt-2-storage","auto-read-only":true,"discard":"unmap"}' \
d76c62
 -blockdev '{"node-name":"libvirt-2-format","read-only":false,"driver":"raw",\
d76c62
 "file":"libvirt-2-storage"}' \
d76c62
 -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=libvirt-2-format,\
d76c62
 id=virtio-disk2 \
d76c62
+-object secret,id=libvirt-1-storage-httpcookie-secret0,\
d76c62
+data=DrPR9NA6GKJb7qi1KbjHad3f3UIGTTDmAmOZHHv1F5w5T8rhnk3f+uSKStHe0J2O,\
d76c62
+keyid=masterKey0,iv=AAECAwQFBgcICQoLDA0ODw==,format=base64 \
d76c62
 -blockdev '{"driver":"https","url":"https://example.org:1234/test4.img",\
d76c62
-"sslverify":false,"node-name":"libvirt-1-storage","auto-read-only":true,\
d76c62
-"discard":"unmap"}' \
d76c62
+"sslverify":false,"cookie-secret":"libvirt-1-storage-httpcookie-secret0",\
d76c62
+"node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \
d76c62
 -blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"raw",\
d76c62
 "file":"libvirt-1-storage"}' \
d76c62
 -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x5,drive=libvirt-1-format,\
d76c62
diff --git a/tests/qemuxml2argvdata/disk-network-http.xml b/tests/qemuxml2argvdata/disk-network-http.xml
d76c62
index 8c475aec1d..6acf75cf65 100644
d76c62
--- a/tests/qemuxml2argvdata/disk-network-http.xml
d76c62
+++ b/tests/qemuxml2argvdata/disk-network-http.xml
d76c62
@@ -31,6 +31,10 @@
d76c62
       <driver name='qemu' type='raw'/>
d76c62
       <source protocol='http' name='test3.img'>
d76c62
         <host name='example.org' port='1234'/>
d76c62
+        <cookies>
d76c62
+          <cookie name='test'>testcookievalue</cookie>
d76c62
+          <cookie name='test2'>blurb</cookie>
d76c62
+        </cookies>
d76c62
       </source>
d76c62
       <target dev='vdc' bus='virtio'/>
d76c62
     </disk>
d76c62
@@ -39,6 +43,10 @@
d76c62
       <source protocol='https' name='test4.img'>
d76c62
         <host name='example.org' port='1234'/>
d76c62
         <ssl verify='no'/>
d76c62
+        <cookies>
d76c62
+          <cookie name='test'>testcookievalue</cookie>
d76c62
+          <cookie name='test2'>blurb</cookie>
d76c62
+        </cookies>
d76c62
       </source>
d76c62
       <target dev='vdd' bus='virtio'/>
d76c62
     </disk>
d76c62
-- 
d76c62
2.25.1
d76c62