qemu: block: Add support for HTTP cookies

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>
This commit is contained in:
Peter Krempa 2017-05-04 12:55:49 +02:00
parent b512935b17
commit 06d3e8d539
3 changed files with 28 additions and 5 deletions

View File

@ -680,6 +680,7 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src,
{ {
qemuDomainStorageSourcePrivatePtr srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src); qemuDomainStorageSourcePrivatePtr srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src);
const char *passwordalias = NULL; const char *passwordalias = NULL;
const char *cookiealias = NULL;
const char *username = NULL; const char *username = NULL;
virJSONValuePtr ret = NULL; virJSONValuePtr ret = NULL;
g_autoptr(virURI) uri = NULL; g_autoptr(virURI) uri = NULL;
@ -704,9 +705,15 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src,
if (!(uristr = virURIFormat(uri))) if (!(uristr = virURIFormat(uri)))
return NULL; return NULL;
if (!onlytarget && src->auth) { if (!onlytarget) {
username = src->auth->username; if (src->auth) {
passwordalias = srcPriv->secinfo->s.aes.alias; username = src->auth->username;
passwordalias = srcPriv->secinfo->s.aes.alias;
}
if (srcPriv &&
srcPriv->httpcookie)
cookiealias = srcPriv->httpcookie->s.aes.alias;
} }
ignore_value(virJSONValueObjectCreate(&ret, ignore_value(virJSONValueObjectCreate(&ret,
@ -714,6 +721,7 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src,
"S:username", username, "S:username", username,
"S:password-secret", passwordalias, "S:password-secret", passwordalias,
"T:sslverify", src->sslverify, "T:sslverify", src->sslverify,
"S:cookie-secret", cookiealias,
NULL)); NULL));
return ret; return ret;

View File

@ -40,15 +40,22 @@ id=virtio-disk0,bootindex=1 \
"file":"libvirt-3-storage"}' \ "file":"libvirt-3-storage"}' \
-device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x3,drive=libvirt-3-format,\ -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x3,drive=libvirt-3-format,\
id=virtio-disk1 \ 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",\ -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"}' \ "node-name":"libvirt-2-storage","auto-read-only":true,"discard":"unmap"}' \
-blockdev '{"node-name":"libvirt-2-format","read-only":false,"driver":"raw",\ -blockdev '{"node-name":"libvirt-2-format","read-only":false,"driver":"raw",\
"file":"libvirt-2-storage"}' \ "file":"libvirt-2-storage"}' \
-device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=libvirt-2-format,\ -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=libvirt-2-format,\
id=virtio-disk2 \ 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",\ -blockdev '{"driver":"https","url":"https://example.org:1234/test4.img",\
"sslverify":false,"node-name":"libvirt-1-storage","auto-read-only":true,\ "sslverify":false,"cookie-secret":"libvirt-1-storage-httpcookie-secret0",\
"discard":"unmap"}' \ "node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \
-blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"raw",\ -blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"raw",\
"file":"libvirt-1-storage"}' \ "file":"libvirt-1-storage"}' \
-device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x5,drive=libvirt-1-format,\ -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x5,drive=libvirt-1-format,\

View File

@ -31,6 +31,10 @@
<driver name='qemu' type='raw'/> <driver name='qemu' type='raw'/>
<source protocol='http' name='test3.img'> <source protocol='http' name='test3.img'>
<host name='example.org' port='1234'/> <host name='example.org' port='1234'/>
<cookies>
<cookie name='test'>testcookievalue</cookie>
<cookie name='test2'>blurb</cookie>
</cookies>
</source> </source>
<target dev='vdc' bus='virtio'/> <target dev='vdc' bus='virtio'/>
</disk> </disk>
@ -39,6 +43,10 @@
<source protocol='https' name='test4.img'> <source protocol='https' name='test4.img'>
<host name='example.org' port='1234'/> <host name='example.org' port='1234'/>
<ssl verify='no'/> <ssl verify='no'/>
<cookies>
<cookie name='test'>testcookievalue</cookie>
<cookie name='test2'>blurb</cookie>
</cookies>
</source> </source>
<target dev='vdd' bus='virtio'/> <target dev='vdd' bus='virtio'/>
</disk> </disk>