mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
qemuBlockGetBackingStoreString: Properly handle 'http/s' with cookies and others
Format cookies into the backing store string without encryption as they will not be visible on the command line when formatting a 'target' only string. In cases when cookies or other options are used we must use the JSON format rather than pure URI. Add tests to validate the scenario. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
bafd2e94fa
commit
3b06103e69
@ -685,6 +685,7 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src,
|
|||||||
virJSONValuePtr ret = NULL;
|
virJSONValuePtr ret = NULL;
|
||||||
g_autoptr(virURI) uri = NULL;
|
g_autoptr(virURI) uri = NULL;
|
||||||
g_autofree char *uristr = NULL;
|
g_autofree char *uristr = NULL;
|
||||||
|
g_autofree char *cookiestr = NULL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common options:
|
* Common options:
|
||||||
@ -714,6 +715,9 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src,
|
|||||||
if (srcPriv &&
|
if (srcPriv &&
|
||||||
srcPriv->httpcookie)
|
srcPriv->httpcookie)
|
||||||
cookiealias = srcPriv->httpcookie->s.aes.alias;
|
cookiealias = srcPriv->httpcookie->s.aes.alias;
|
||||||
|
} else {
|
||||||
|
/* format target string along with cookies */
|
||||||
|
cookiestr = qemuBlockStorageSourceGetCookieString(src);
|
||||||
}
|
}
|
||||||
|
|
||||||
ignore_value(virJSONValueObjectCreate(&ret,
|
ignore_value(virJSONValueObjectCreate(&ret,
|
||||||
@ -721,6 +725,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", cookiestr,
|
||||||
"S:cookie-secret", cookiealias,
|
"S:cookie-secret", cookiealias,
|
||||||
"P:timeout", src->timeout,
|
"P:timeout", src->timeout,
|
||||||
"P:readahead", src->readahead,
|
"P:readahead", src->readahead,
|
||||||
@ -2056,7 +2061,12 @@ qemuBlockGetBackingStoreString(virStorageSourcePtr src,
|
|||||||
/* generate simplified URIs for the easy cases */
|
/* generate simplified URIs for the easy cases */
|
||||||
if (actualType == VIR_STORAGE_TYPE_NETWORK &&
|
if (actualType == VIR_STORAGE_TYPE_NETWORK &&
|
||||||
src->nhosts == 1 &&
|
src->nhosts == 1 &&
|
||||||
src->hosts->transport == VIR_STORAGE_NET_HOST_TRANS_TCP) {
|
src->hosts->transport == VIR_STORAGE_NET_HOST_TRANS_TCP &&
|
||||||
|
src->timeout == 0 &&
|
||||||
|
src->ncookies == 0 &&
|
||||||
|
src->sslverify == VIR_TRISTATE_BOOL_ABSENT &&
|
||||||
|
src->timeout == 0 &&
|
||||||
|
src->readahead == 0) {
|
||||||
|
|
||||||
switch ((virStorageNetProtocol) src->protocol) {
|
switch ((virStorageNetProtocol) src->protocol) {
|
||||||
case VIR_STORAGE_NET_PROTOCOL_NBD:
|
case VIR_STORAGE_NET_PROTOCOL_NBD:
|
||||||
|
@ -1212,6 +1212,8 @@ mymain(void)
|
|||||||
TEST_DISK_TO_JSON("network-qcow2-backing-chain-cache-unsafe");
|
TEST_DISK_TO_JSON("network-qcow2-backing-chain-cache-unsafe");
|
||||||
TEST_DISK_TO_JSON("dir-fat-cache");
|
TEST_DISK_TO_JSON("dir-fat-cache");
|
||||||
TEST_DISK_TO_JSON("network-nbd-tls");
|
TEST_DISK_TO_JSON("network-nbd-tls");
|
||||||
|
TEST_DISK_TO_JSON("network-http-noopts");
|
||||||
|
TEST_DISK_TO_JSON("network-http-curlopts");
|
||||||
|
|
||||||
TEST_DISK_TO_JSON("block-raw-noopts");
|
TEST_DISK_TO_JSON("block-raw-noopts");
|
||||||
TEST_DISK_TO_JSON("block-raw-reservations");
|
TEST_DISK_TO_JSON("block-raw-reservations");
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
(
|
||||||
|
source only properties:
|
||||||
|
{
|
||||||
|
"driver": "https",
|
||||||
|
"url": "https://host1.example.com:443/something",
|
||||||
|
"sslverify": false,
|
||||||
|
"cookie": "test=123456; blurb=here"
|
||||||
|
}
|
||||||
|
backing store string:
|
||||||
|
json:{"file":{
|
||||||
|
"driver": "https",
|
||||||
|
"url": "https://host1.example.com:443/something",
|
||||||
|
"sslverify": false,
|
||||||
|
"cookie": "test=123456; blurb=here"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
15
tests/qemublocktestdata/xml2json/network-http-curlopts.json
Normal file
15
tests/qemublocktestdata/xml2json/network-http-curlopts.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"node-name": "node-b-f",
|
||||||
|
"read-only": false,
|
||||||
|
"driver": "qcow2",
|
||||||
|
"file": "node-a-s",
|
||||||
|
"backing": null
|
||||||
|
}
|
||||||
|
{
|
||||||
|
"driver": "https",
|
||||||
|
"url": "https://host1.example.com:443/something",
|
||||||
|
"sslverify": false,
|
||||||
|
"node-name": "node-a-s",
|
||||||
|
"auto-read-only": true,
|
||||||
|
"discard": "unmap"
|
||||||
|
}
|
20
tests/qemublocktestdata/xml2json/network-http-curlopts.xml
Normal file
20
tests/qemublocktestdata/xml2json/network-http-curlopts.xml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<disk type='network' device='disk'>
|
||||||
|
<driver name='qemu' type='qcow2'/>
|
||||||
|
<source protocol='https' name='/something'>
|
||||||
|
<host name='host1.example.com'/>
|
||||||
|
<ssl verify='no'/>
|
||||||
|
<cookies>
|
||||||
|
<cookie name='test'>123456</cookie>
|
||||||
|
<cookie name='blurb'>here</cookie>
|
||||||
|
</cookies>
|
||||||
|
<privateData>
|
||||||
|
<nodenames>
|
||||||
|
<nodename type='storage' name='node-a-s'/>
|
||||||
|
<nodename type='format' name='node-b-f'/>
|
||||||
|
</nodenames>
|
||||||
|
</privateData>
|
||||||
|
</source>
|
||||||
|
<backingStore/>
|
||||||
|
<target dev='vda' bus='virtio'/>
|
||||||
|
<alias name='virtio-disk0'/>
|
||||||
|
</disk>
|
@ -0,0 +1,9 @@
|
|||||||
|
(
|
||||||
|
source only properties:
|
||||||
|
{
|
||||||
|
"driver": "https",
|
||||||
|
"url": "https://host1.example.com:443/something"
|
||||||
|
}
|
||||||
|
backing store string:
|
||||||
|
https://host1.example.com:443/something
|
||||||
|
)
|
14
tests/qemublocktestdata/xml2json/network-http-noopts.json
Normal file
14
tests/qemublocktestdata/xml2json/network-http-noopts.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"node-name": "node-b-f",
|
||||||
|
"read-only": false,
|
||||||
|
"driver": "qcow2",
|
||||||
|
"file": "node-a-s",
|
||||||
|
"backing": null
|
||||||
|
}
|
||||||
|
{
|
||||||
|
"driver": "https",
|
||||||
|
"url": "https://host1.example.com:443/something",
|
||||||
|
"node-name": "node-a-s",
|
||||||
|
"auto-read-only": true,
|
||||||
|
"discard": "unmap"
|
||||||
|
}
|
15
tests/qemublocktestdata/xml2json/network-http-noopts.xml
Normal file
15
tests/qemublocktestdata/xml2json/network-http-noopts.xml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<disk type='network' device='disk'>
|
||||||
|
<driver name='qemu' type='qcow2'/>
|
||||||
|
<source protocol='https' name='/something'>
|
||||||
|
<host name='host1.example.com'/>
|
||||||
|
<privateData>
|
||||||
|
<nodenames>
|
||||||
|
<nodename type='storage' name='node-a-s'/>
|
||||||
|
<nodename type='format' name='node-b-f'/>
|
||||||
|
</nodenames>
|
||||||
|
</privateData>
|
||||||
|
</source>
|
||||||
|
<backingStore/>
|
||||||
|
<target dev='vda' bus='virtio'/>
|
||||||
|
<alias name='virtio-disk0'/>
|
||||||
|
</disk>
|
Loading…
x
Reference in New Issue
Block a user