Blame SOURCES/kvm-rbd-New-parameter-key-secret.patch

383d26
From c4b9fcd4bf4179a565e2f10d4c93ef6801007270 Mon Sep 17 00:00:00 2001
383d26
From: Markus Armbruster <armbru@redhat.com>
383d26
Date: Mon, 18 Jun 2018 08:43:30 +0200
383d26
Subject: [PATCH 23/54] rbd: New parameter key-secret
383d26
383d26
RH-Author: Markus Armbruster <armbru@redhat.com>
383d26
Message-id: <20180618084330.30009-24-armbru@redhat.com>
383d26
Patchwork-id: 80727
383d26
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 23/23] rbd: New parameter key-secret
383d26
Bugzilla: 1557995
383d26
RH-Acked-by: Max Reitz <mreitz@redhat.com>
383d26
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
383d26
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
383d26
383d26
Legacy -drive supports "password-secret" parameter that isn't
383d26
available with -blockdev / blockdev-add.  That's because we backed out
383d26
our first try to provide it there due to interface design doubts, in
383d26
commit 577d8c9a811, v2.9.0.
383d26
383d26
This is the second try.  It brings back the parameter, except it's
383d26
named "key-secret" now.
383d26
383d26
Let's review our reasons for backing out the first try, as stated in
383d26
the commit message:
383d26
383d26
    * BlockdevOptionsRbd member @password-secret isn't actually a
383d26
      password, it's a key generated by Ceph.
383d26
383d26
Addressed by the rename.
383d26
383d26
    * We're not sure where member @password-secret belongs (see the
383d26
      previous commit).
383d26
383d26
See previous commit.
383d26
383d26
    * How @password-secret interacts with settings from a configuration
383d26
      file specified with @conf is undocumented.
383d26
383d26
Not actually true, the documentation for @conf says "Values in the
383d26
configuration file will be overridden by options specified via QAPI",
383d26
and we've tested this.
383d26
383d26
Signed-off-by: Markus Armbruster <armbru@redhat.com>
383d26
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
383d26
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
383d26
(cherry picked from commit d083f954a95d37b460df0c2fbfe46ad7eb207b10)
383d26
[Conflict due to lack of commit e8e16d4baff "rbd: Switch to byte-based
383d26
callbacks" trivially resolved]
383d26
383d26
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
---
383d26
 block/rbd.c          | 41 +++++++++++++++++++++++++----------------
383d26
 qapi/block-core.json |  6 ++++++
383d26
 2 files changed, 31 insertions(+), 16 deletions(-)
383d26
383d26
diff --git a/block/rbd.c b/block/rbd.c
383d26
index 9c0903f..3242bcd 100644
383d26
--- a/block/rbd.c
383d26
+++ b/block/rbd.c
383d26
@@ -232,24 +232,25 @@ done:
383d26
 }
383d26
 
383d26
 
383d26
-static int qemu_rbd_set_auth(rados_t cluster, const char *secretid,
383d26
-                             BlockdevOptionsRbd *opts,
383d26
+static int qemu_rbd_set_auth(rados_t cluster, BlockdevOptionsRbd *opts,
383d26
                              Error **errp)
383d26
 {
383d26
-    char *acr;
383d26
+    char *key, *acr;
383d26
     int r;
383d26
     GString *accu;
383d26
     RbdAuthModeList *auth;
383d26
 
383d26
-    if (secretid) {
383d26
-        gchar *secret = qcrypto_secret_lookup_as_base64(secretid,
383d26
-                                                        errp);
383d26
-        if (!secret) {
383d26
-            return -1;
383d26
+    if (opts->key_secret) {
383d26
+        key = qcrypto_secret_lookup_as_base64(opts->key_secret, errp);
383d26
+        if (!key) {
383d26
+            return -EIO;
383d26
+        }
383d26
+        r = rados_conf_set(cluster, "key", key);
383d26
+        g_free(key);
383d26
+        if (r < 0) {
383d26
+            error_setg_errno(errp, -r, "Could not set 'key'");
383d26
+            return r;
383d26
         }
383d26
-
383d26
-        rados_conf_set(cluster, "key", secret);
383d26
-        g_free(secret);
383d26
     }
383d26
 
383d26
     if (opts->has_auth_client_required) {
383d26
@@ -360,9 +361,7 @@ static QemuOptsList runtime_opts = {
383d26
     },
383d26
 };
383d26
 
383d26
-/* FIXME Deprecate and remove keypairs or make it available in QMP.
383d26
- * password_secret should eventually be configurable in opts->location. Support
383d26
- * for it in .bdrv_open will make it work here as well. */
383d26
+/* FIXME Deprecate and remove keypairs or make it available in QMP. */
383d26
 static int qemu_rbd_do_create(BlockdevCreateOptions *options,
383d26
                               const char *keypairs, const char *password_secret,
383d26
                               Error **errp)
383d26
@@ -568,6 +567,16 @@ static int qemu_rbd_connect(rados_t *cluster, rados_ioctx_t *io_ctx,
383d26
     Error *local_err = NULL;
383d26
     int r;
383d26
 
383d26
+    if (secretid) {
383d26
+        if (opts->key_secret) {
383d26
+            error_setg(errp,
383d26
+                       "Legacy 'password-secret' clashes with 'key-secret'");
383d26
+            return -EINVAL;
383d26
+        }
383d26
+        opts->key_secret = g_strdup(secretid);
383d26
+        opts->has_key_secret = true;
383d26
+    }
383d26
+
383d26
     mon_host = qemu_rbd_mon_host(opts, &local_err);
383d26
     if (local_err) {
383d26
         error_propagate(errp, local_err);
383d26
@@ -600,8 +609,8 @@ static int qemu_rbd_connect(rados_t *cluster, rados_ioctx_t *io_ctx,
383d26
         }
383d26
     }
383d26
 
383d26
-    if (qemu_rbd_set_auth(*cluster, secretid, opts, errp) < 0) {
383d26
-        r = -EIO;
383d26
+    r = qemu_rbd_set_auth(*cluster, opts, errp);
383d26
+    if (r < 0) {
383d26
         goto failed_shutdown;
383d26
     }
383d26
 
383d26
diff --git a/qapi/block-core.json b/qapi/block-core.json
383d26
index 28001fb..46469be 100644
383d26
--- a/qapi/block-core.json
383d26
+++ b/qapi/block-core.json
383d26
@@ -3196,6 +3196,11 @@
383d26
 #                      This maps to Ceph configuration option
383d26
 #                      "auth_client_required".  (Since 3.0)
383d26
 #
383d26
+# @key-secret:         ID of a QCryptoSecret object providing a key
383d26
+#                      for cephx authentication.
383d26
+#                      This maps to Ceph configuration option
383d26
+#                      "key".  (Since 3.0)
383d26
+#
383d26
 # @server:             Monitor host address and port.  This maps
383d26
 #                      to the "mon_host" Ceph option.
383d26
 #
383d26
@@ -3208,6 +3213,7 @@
383d26
             '*snapshot': 'str',
383d26
             '*user': 'str',
383d26
             '*auth-client-required': ['RbdAuthMode'],
383d26
+            '*key-secret': 'str',
383d26
             '*server': ['InetSocketAddressBase'] } }
383d26
 
383d26
 ##
383d26
-- 
383d26
1.8.3.1
383d26