提交 3b06103e 编写于 作者: P Peter Krempa

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: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NMichal Privoznik <mprivozn@redhat.com>
上级 bafd2e94
......@@ -685,6 +685,7 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src,
virJSONValuePtr ret = NULL;
g_autoptr(virURI) uri = NULL;
g_autofree char *uristr = NULL;
g_autofree char *cookiestr = NULL;
/**
* Common options:
......@@ -714,6 +715,9 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src,
if (srcPriv &&
srcPriv->httpcookie)
cookiealias = srcPriv->httpcookie->s.aes.alias;
} else {
/* format target string along with cookies */
cookiestr = qemuBlockStorageSourceGetCookieString(src);
}
ignore_value(virJSONValueObjectCreate(&ret,
......@@ -721,6 +725,7 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src,
"S:username", username,
"S:password-secret", passwordalias,
"T:sslverify", src->sslverify,
"S:cookie", cookiestr,
"S:cookie-secret", cookiealias,
"P:timeout", src->timeout,
"P:readahead", src->readahead,
......@@ -2056,7 +2061,12 @@ qemuBlockGetBackingStoreString(virStorageSourcePtr src,
/* generate simplified URIs for the easy cases */
if (actualType == VIR_STORAGE_TYPE_NETWORK &&
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) {
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("dir-fat-cache");
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-reservations");
......
(
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"
}
}
)
{
"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"
}
<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>
(
source only properties:
{
"driver": "https",
"url": "https://host1.example.com:443/something"
}
backing store string:
https://host1.example.com:443/something
)
{
"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"
}
<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>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册