Blame SOURCES/libvirt-qemu-Pass-through-arguments-of-ssh-block-driver-used-by-libguestfs.patch

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