Blame SOURCES/kvm-rbd-New-parameter-auth-client-required.patch

1bdc94
From 92e418ec44b35eedff728cc692a09bd001d0762e Mon Sep 17 00:00:00 2001
1bdc94
From: Markus Armbruster <armbru@redhat.com>
1bdc94
Date: Mon, 18 Jun 2018 08:43:29 +0200
1bdc94
Subject: [PATCH 22/54] rbd: New parameter auth-client-required
1bdc94
1bdc94
RH-Author: Markus Armbruster <armbru@redhat.com>
1bdc94
Message-id: <20180618084330.30009-23-armbru@redhat.com>
1bdc94
Patchwork-id: 80731
1bdc94
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 22/23] rbd: New parameter auth-client-required
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
Parameter auth-client-required lets you configure authentication
1bdc94
methods.  We tried to provide that in v2.9.0, but backed out due to
1bdc94
interface design doubts (commit 464444fcc16).
1bdc94
1bdc94
This commit is similar to what we backed out, but simpler: we use a
1bdc94
list of enumeration values instead of a list of objects with a member
1bdc94
of enumeration type.
1bdc94
1bdc94
Let's review our reasons for backing out the first try, as stated in
1bdc94
the commit message:
1bdc94
1bdc94
    * The implementation uses deprecated rados_conf_set() key
1bdc94
      "auth_supported".  No biggie.
1bdc94
1bdc94
Fixed: we use "auth-client-required".
1bdc94
1bdc94
    * The implementation makes -drive silently ignore invalid parameters
1bdc94
      "auth" and "auth-supported.*.X" where X isn't "auth".  Fixable (in
1bdc94
      fact I'm going to fix similar bugs around parameter server), so
1bdc94
      again no biggie.
1bdc94
1bdc94
That fix is commit 2836284db60.  This commit doesn't bring the bugs
1bdc94
back.
1bdc94
1bdc94
    * BlockdevOptionsRbd member @password-secret applies only to
1bdc94
      authentication method cephx.  Should it be a variant member of
1bdc94
      RbdAuthMethod?
1bdc94
1bdc94
We've had time to ponder, and we decided to stick to the way Ceph
1bdc94
configuration works: the key configured separately, and silently
1bdc94
ignored if the authentication method doesn't use it.
1bdc94
1bdc94
    * BlockdevOptionsRbd member @user could apply to both methods cephx
1bdc94
      and none, but I'm not sure it's actually used with none.  If it
1bdc94
      isn't, should it be a variant member of RbdAuthMethod?
1bdc94
1bdc94
Likewise.
1bdc94
1bdc94
    * The client offers a *set* of authentication methods, not a list.
1bdc94
      Should the methods be optional members of BlockdevOptionsRbd instead
1bdc94
      of members of list @auth-supported?  The latter begs the question
1bdc94
      what multiple entries for the same method mean.  Trivial question
1bdc94
      now that RbdAuthMethod contains nothing but @type, but less so when
1bdc94
      RbdAuthMethod acquires other members, such the ones discussed above.
1bdc94
1bdc94
Again, we decided to stick to the way Ceph configuration works, except
1bdc94
we make auth-client-required a list of enumeration values instead of a
1bdc94
string containing keywords separated by delimiters.
1bdc94
1bdc94
    * How BlockdevOptionsRbd member @auth-supported interacts with
1bdc94
      settings from a configuration file specified with @conf is
1bdc94
      undocumented.  I suspect it's untested, too.
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 a3699de4dde82bc76b33a83798a9da82c2336cce)
1bdc94
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
1bdc94
---
1bdc94
 block/rbd.c          | 42 ++++++++++++++++++++++++++++++++----------
1bdc94
 qapi/block-core.json | 13 +++++++++++++
1bdc94
 2 files changed, 45 insertions(+), 10 deletions(-)
1bdc94
1bdc94
diff --git a/block/rbd.c b/block/rbd.c
1bdc94
index c834d72..9c0903f 100644
1bdc94
--- a/block/rbd.c
1bdc94
+++ b/block/rbd.c
1bdc94
@@ -233,20 +233,42 @@ done:
1bdc94
 
1bdc94
 
1bdc94
 static int qemu_rbd_set_auth(rados_t cluster, const char *secretid,
1bdc94
+                             BlockdevOptionsRbd *opts,
1bdc94
                              Error **errp)
1bdc94
 {
1bdc94
-    if (secretid == 0) {
1bdc94
-        return 0;
1bdc94
-    }
1bdc94
+    char *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
+        }
1bdc94
 
1bdc94
-    gchar *secret = qcrypto_secret_lookup_as_base64(secretid,
1bdc94
-                                                    errp);
1bdc94
-    if (!secret) {
1bdc94
-        return -1;
1bdc94
+        rados_conf_set(cluster, "key", secret);
1bdc94
+        g_free(secret);
1bdc94
     }
1bdc94
 
1bdc94
-    rados_conf_set(cluster, "key", secret);
1bdc94
-    g_free(secret);
1bdc94
+    if (opts->has_auth_client_required) {
1bdc94
+        accu = g_string_new("");
1bdc94
+        for (auth = opts->auth_client_required; auth; auth = auth->next) {
1bdc94
+            if (accu->str[0]) {
1bdc94
+                g_string_append_c(accu, ';');
1bdc94
+            }
1bdc94
+            g_string_append(accu, RbdAuthMode_str(auth->value));
1bdc94
+        }
1bdc94
+        acr = g_string_free(accu, FALSE);
1bdc94
+        r = rados_conf_set(cluster, "auth_client_required", acr);
1bdc94
+        g_free(acr);
1bdc94
+        if (r < 0) {
1bdc94
+            error_setg_errno(errp, -r,
1bdc94
+                             "Could not set 'auth_client_required'");
1bdc94
+            return r;
1bdc94
+        }
1bdc94
+    }
1bdc94
 
1bdc94
     return 0;
1bdc94
 }
1bdc94
@@ -578,7 +600,7 @@ static int qemu_rbd_connect(rados_t *cluster, rados_ioctx_t *io_ctx,
1bdc94
         }
1bdc94
     }
1bdc94
 
1bdc94
-    if (qemu_rbd_set_auth(*cluster, secretid, errp) < 0) {
1bdc94
+    if (qemu_rbd_set_auth(*cluster, secretid, opts, errp) < 0) {
1bdc94
         r = -EIO;
1bdc94
         goto failed_shutdown;
1bdc94
     }
1bdc94
diff --git a/qapi/block-core.json b/qapi/block-core.json
1bdc94
index b38d5d6..28001fb 100644
1bdc94
--- a/qapi/block-core.json
1bdc94
+++ b/qapi/block-core.json
1bdc94
@@ -3170,6 +3170,14 @@
1bdc94
 
1bdc94
 
1bdc94
 ##
1bdc94
+# @RbdAuthMode:
1bdc94
+#
1bdc94
+# Since: 3.0
1bdc94
+##
1bdc94
+{ 'enum': 'RbdAuthMode',
1bdc94
+  'data': [ 'cephx', 'none' ] }
1bdc94
+
1bdc94
+##
1bdc94
 # @BlockdevOptionsRbd:
1bdc94
 #
1bdc94
 # @pool:               Ceph pool name.
1bdc94
@@ -3184,6 +3192,10 @@
1bdc94
 #
1bdc94
 # @user:               Ceph id name.
1bdc94
 #
1bdc94
+# @auth-client-required: Acceptable authentication modes.
1bdc94
+#                      This maps to Ceph configuration option
1bdc94
+#                      "auth_client_required".  (Since 3.0)
1bdc94
+#
1bdc94
 # @server:             Monitor host address and port.  This maps
1bdc94
 #                      to the "mon_host" Ceph option.
1bdc94
 #
1bdc94
@@ -3195,6 +3207,7 @@
1bdc94
             '*conf': 'str',
1bdc94
             '*snapshot': 'str',
1bdc94
             '*user': 'str',
1bdc94
+            '*auth-client-required': ['RbdAuthMode'],
1bdc94
             '*server': ['InetSocketAddressBase'] } }
1bdc94
 
1bdc94
 ##
1bdc94
-- 
1bdc94
1.8.3.1
1bdc94