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