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

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