libvirt/SOURCES/libvirt-qemu-block-Add-support-for-HTTP-cookies.patch
2021-09-10 11:57:33 +00:00

123 lines
5.3 KiB
Diff

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