|
|
d76c62 |
From 2c711c10712280bd4dae442bc68c8e38df3ab171 Mon Sep 17 00:00:00 2001
|
|
|
d76c62 |
Message-Id: <2c711c10712280bd4dae442bc68c8e38df3ab171@dist-git>
|
|
|
d76c62 |
From: Peter Krempa <pkrempa@redhat.com>
|
|
|
d76c62 |
Date: Mon, 16 Mar 2020 22:12:13 +0100
|
|
|
d76c62 |
Subject: [PATCH] qemu: Pass through arguments of 'ssh' block driver used by
|
|
|
d76c62 |
libguestfs
|
|
|
d76c62 |
MIME-Version: 1.0
|
|
|
d76c62 |
Content-Type: text/plain; charset=UTF-8
|
|
|
d76c62 |
Content-Transfer-Encoding: 8bit
|
|
|
d76c62 |
|
|
|
d76c62 |
We currently don't model the 'ssh' protocol properties properly and
|
|
|
d76c62 |
since it seems impossible for now (agent path passed via environment
|
|
|
d76c62 |
variable). To allow libguestfs to work as it used in pre-blockdev era we
|
|
|
d76c62 |
must carry the properties over to the command line. For this instance we
|
|
|
d76c62 |
just store it internally and format it back.
|
|
|
d76c62 |
|
|
|
d76c62 |
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
|
|
|
d76c62 |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
d76c62 |
(cherry picked from commit d6db013c6e507fe45ebc07fa109e608cf7451b22)
|
|
|
d76c62 |
https://bugzilla.redhat.com/show_bug.cgi?id=1804750
|
|
|
d76c62 |
Message-Id: <521e8b33432bfa847007866c631d6d6454f08ea3.1584391727.git.pkrempa@redhat.com>
|
|
|
d76c62 |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
d76c62 |
---
|
|
|
d76c62 |
src/qemu/qemu_block.c | 10 ++++++++++
|
|
|
d76c62 |
src/util/virstoragefile.c | 13 +++++++++++++
|
|
|
d76c62 |
src/util/virstoragefile.h | 5 +++++
|
|
|
d76c62 |
tests/qemublocktest.c | 1 +
|
|
|
d76c62 |
.../jsontojson/ssh-passthrough-libguestfs-in.json | 1 +
|
|
|
d76c62 |
.../jsontojson/ssh-passthrough-libguestfs-out.json | 14 ++++++++++++++
|
|
|
d76c62 |
6 files changed, 44 insertions(+)
|
|
|
d76c62 |
create mode 100644 tests/qemublocktestdata/jsontojson/ssh-passthrough-libguestfs-in.json
|
|
|
d76c62 |
create mode 100644 tests/qemublocktestdata/jsontojson/ssh-passthrough-libguestfs-out.json
|
|
|
d76c62 |
|
|
|
d76c62 |
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
|
|
|
d76c62 |
index b077e2e02f..141059ae81 100644
|
|
|
d76c62 |
--- a/src/qemu/qemu_block.c
|
|
|
d76c62 |
+++ b/src/qemu/qemu_block.c
|
|
|
d76c62 |
@@ -911,6 +911,7 @@ qemuBlockStorageSourceGetSshProps(virStorageSourcePtr src)
|
|
|
d76c62 |
g_autoptr(virJSONValue) serverprops = NULL;
|
|
|
d76c62 |
virJSONValuePtr ret = NULL;
|
|
|
d76c62 |
const char *username = NULL;
|
|
|
d76c62 |
+ g_autoptr(virJSONValue) host_key_check = NULL;
|
|
|
d76c62 |
|
|
|
d76c62 |
if (src->nhosts != 1) {
|
|
|
d76c62 |
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
d76c62 |
@@ -924,11 +925,20 @@ qemuBlockStorageSourceGetSshProps(virStorageSourcePtr src)
|
|
|
d76c62 |
|
|
|
d76c62 |
if (src->auth)
|
|
|
d76c62 |
username = src->auth->username;
|
|
|
d76c62 |
+ else if (src->ssh_user)
|
|
|
d76c62 |
+ username = src->ssh_user;
|
|
|
d76c62 |
+
|
|
|
d76c62 |
+ if (src->ssh_host_key_check_disabled &&
|
|
|
d76c62 |
+ virJSONValueObjectCreate(&host_key_check,
|
|
|
d76c62 |
+ "s:mode", "none",
|
|
|
d76c62 |
+ NULL) < 0)
|
|
|
d76c62 |
+ return NULL;
|
|
|
d76c62 |
|
|
|
d76c62 |
if (virJSONValueObjectCreate(&ret,
|
|
|
d76c62 |
"s:path", src->path,
|
|
|
d76c62 |
"a:server", &serverprops,
|
|
|
d76c62 |
"S:user", username,
|
|
|
d76c62 |
+ "A:host-key-check", &host_key_check,
|
|
|
d76c62 |
NULL) < 0)
|
|
|
d76c62 |
return NULL;
|
|
|
d76c62 |
|
|
|
d76c62 |
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
|
|
|
d76c62 |
index 9eca186e99..ce126f5cba 100644
|
|
|
d76c62 |
--- a/src/util/virstoragefile.c
|
|
|
d76c62 |
+++ b/src/util/virstoragefile.c
|
|
|
d76c62 |
@@ -2464,6 +2464,10 @@ virStorageSourceCopy(const virStorageSource *src,
|
|
|
d76c62 |
return NULL;
|
|
|
d76c62 |
}
|
|
|
d76c62 |
|
|
|
d76c62 |
+ /* ssh config passthrough for libguestfs */
|
|
|
d76c62 |
+ def->ssh_host_key_check_disabled = src->ssh_host_key_check_disabled;
|
|
|
d76c62 |
+ def->ssh_user = g_strdup(src->ssh_user);
|
|
|
d76c62 |
+
|
|
|
d76c62 |
return g_steal_pointer(&def;;
|
|
|
d76c62 |
}
|
|
|
d76c62 |
|
|
|
d76c62 |
@@ -2705,6 +2709,8 @@ virStorageSourceClear(virStorageSourcePtr def)
|
|
|
d76c62 |
VIR_FREE(def->tlsAlias);
|
|
|
d76c62 |
VIR_FREE(def->tlsCertdir);
|
|
|
d76c62 |
|
|
|
d76c62 |
+ VIR_FREE(def->ssh_user);
|
|
|
d76c62 |
+
|
|
|
d76c62 |
virStorageSourceInitiatorClear(&def->initiator);
|
|
|
d76c62 |
|
|
|
d76c62 |
/* clear everything except the class header as the object APIs
|
|
|
d76c62 |
@@ -3635,6 +3641,8 @@ virStorageSourceParseBackingJSONSSH(virStorageSourcePtr src,
|
|
|
d76c62 |
const char *path = virJSONValueObjectGetString(json, "path");
|
|
|
d76c62 |
const char *host = virJSONValueObjectGetString(json, "host");
|
|
|
d76c62 |
const char *port = virJSONValueObjectGetString(json, "port");
|
|
|
d76c62 |
+ const char *user = virJSONValueObjectGetString(json, "user");
|
|
|
d76c62 |
+ const char *host_key_check = virJSONValueObjectGetString(json, "host_key_check");
|
|
|
d76c62 |
virJSONValuePtr server = virJSONValueObjectGetObject(json, "server");
|
|
|
d76c62 |
|
|
|
d76c62 |
if (!(host || server) || !path) {
|
|
|
d76c62 |
@@ -3665,6 +3673,11 @@ virStorageSourceParseBackingJSONSSH(virStorageSourcePtr src,
|
|
|
d76c62 |
return -1;
|
|
|
d76c62 |
}
|
|
|
d76c62 |
|
|
|
d76c62 |
+ /* these two are parsed just to be passed back as we don't model them yet */
|
|
|
d76c62 |
+ src->ssh_user = g_strdup(user);
|
|
|
d76c62 |
+ if (STREQ_NULLABLE(host_key_check, "no"))
|
|
|
d76c62 |
+ src->ssh_host_key_check_disabled = true;
|
|
|
d76c62 |
+
|
|
|
d76c62 |
return 0;
|
|
|
d76c62 |
}
|
|
|
d76c62 |
|
|
|
d76c62 |
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
|
|
|
d76c62 |
index 1abdaf89ce..c1430cadd1 100644
|
|
|
d76c62 |
--- a/src/util/virstoragefile.h
|
|
|
d76c62 |
+++ b/src/util/virstoragefile.h
|
|
|
d76c62 |
@@ -385,6 +385,11 @@ struct _virStorageSource {
|
|
|
d76c62 |
as a source for floppy drive */
|
|
|
d76c62 |
|
|
|
d76c62 |
bool hostcdrom; /* backing device is a cdrom */
|
|
|
d76c62 |
+
|
|
|
d76c62 |
+ /* passthrough variables for the ssh driver which we don't handle properly */
|
|
|
d76c62 |
+ /* these must not be used apart from formatting the output JSON in the qemu driver */
|
|
|
d76c62 |
+ char *ssh_user;
|
|
|
d76c62 |
+ bool ssh_host_key_check_disabled;
|
|
|
d76c62 |
};
|
|
|
d76c62 |
|
|
|
d76c62 |
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStorageSource, virObjectUnref);
|
|
|
d76c62 |
diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c
|
|
|
d76c62 |
index d8bd811b4d..f48875e16d 100644
|
|
|
d76c62 |
--- a/tests/qemublocktest.c
|
|
|
d76c62 |
+++ b/tests/qemublocktest.c
|
|
|
d76c62 |
@@ -1132,6 +1132,7 @@ mymain(void)
|
|
|
d76c62 |
jsontojsondata.schemaroot = qmp_schemaroot_x86_64_blockdev_add;
|
|
|
d76c62 |
|
|
|
d76c62 |
TEST_JSON_TO_JSON("curl-libguestfs");
|
|
|
d76c62 |
+ TEST_JSON_TO_JSON("ssh-passthrough-libguestfs");
|
|
|
d76c62 |
|
|
|
d76c62 |
#define TEST_IMAGE_CREATE(testname, testbacking) \
|
|
|
d76c62 |
do { \
|
|
|
d76c62 |
diff --git a/tests/qemublocktestdata/jsontojson/ssh-passthrough-libguestfs-in.json b/tests/qemublocktestdata/jsontojson/ssh-passthrough-libguestfs-in.json
|
|
|
d76c62 |
new file mode 100644
|
|
|
d76c62 |
index 0000000000..da8fedef07
|
|
|
d76c62 |
--- /dev/null
|
|
|
d76c62 |
+++ b/tests/qemublocktestdata/jsontojson/ssh-passthrough-libguestfs-in.json
|
|
|
d76c62 |
@@ -0,0 +1 @@
|
|
|
d76c62 |
+json:{"file.driver":"ssh","file.user":"testuser","file.host":"random.host","file.port":1234,"file.path":"somewhere/something","file.host_key_check":"no"}
|
|
|
d76c62 |
diff --git a/tests/qemublocktestdata/jsontojson/ssh-passthrough-libguestfs-out.json b/tests/qemublocktestdata/jsontojson/ssh-passthrough-libguestfs-out.json
|
|
|
d76c62 |
new file mode 100644
|
|
|
d76c62 |
index 0000000000..1f6032deb4
|
|
|
d76c62 |
--- /dev/null
|
|
|
d76c62 |
+++ b/tests/qemublocktestdata/jsontojson/ssh-passthrough-libguestfs-out.json
|
|
|
d76c62 |
@@ -0,0 +1,14 @@
|
|
|
d76c62 |
+{
|
|
|
d76c62 |
+ "driver": "ssh",
|
|
|
d76c62 |
+ "path": "somewhere/something",
|
|
|
d76c62 |
+ "server": {
|
|
|
d76c62 |
+ "host": "random.host",
|
|
|
d76c62 |
+ "port": "22"
|
|
|
d76c62 |
+ },
|
|
|
d76c62 |
+ "user": "testuser",
|
|
|
d76c62 |
+ "host-key-check": {
|
|
|
d76c62 |
+ "mode": "none"
|
|
|
d76c62 |
+ },
|
|
|
d76c62 |
+ "auto-read-only": true,
|
|
|
d76c62 |
+ "discard": "unmap"
|
|
|
d76c62 |
+}
|
|
|
d76c62 |
--
|
|
|
d76c62 |
2.25.1
|
|
|
d76c62 |
|