render / rpms / libvirt

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