7c2869
From 8f44b5a73f2c838ed0c498370d525ab702be6da2 Mon Sep 17 00:00:00 2001
7c2869
From: Mohammed Rafi KC <rkavunga@redhat.com>
7c2869
Date: Mon, 23 Apr 2018 09:02:09 +0530
7c2869
Subject: [PATCH 656/656] server/auth: fix regression in honouring auth.allow
7c2869
7c2869
The patch 16d6904d54e7409f95e9e893e131b6bf11f0e4c7 to fix
7c2869
problem with shared storage introduced a regression. auth.allow
7c2869
is now not honouring. This changes will fix the issue with
7c2869
auth.allow
7c2869
7c2869
The option is invalid when SSL/TLS is in use, at which point
7c2869
the SSL/TLS certificate user name is used to validate and
7c2869
hence authorize the right user. This expects TLS allow rules
7c2869
to be setup correctly rather than the default *.
7c2869
7c2869
credit : Shyam
7c2869
7c2869
Change-Id: Ifcb202b16a451e5ef2ea04a6486276ba163c07e4
7c2869
BUG: 1570906
7c2869
Signed-off-by: Mohammed Rafi KC <rkavunga@redhat.com>
7c2869
Reviewed-on: https://code.engineering.redhat.com/gerrit/136453
7c2869
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
7c2869
---
7c2869
 xlators/mgmt/glusterd/src/glusterd-volgen.c    |   3 +-
7c2869
 xlators/protocol/auth/login/src/login.c        | 142 ++++++++++++-------------
7c2869
 xlators/protocol/server/src/authenticate.c     |  32 ++----
7c2869
 xlators/protocol/server/src/authenticate.h     |   4 +-
7c2869
 xlators/protocol/server/src/server-handshake.c |   2 +-
7c2869
 xlators/protocol/server/src/server.c           |   4 +-
7c2869
 xlators/protocol/server/src/server.h           |   2 -
7c2869
 7 files changed, 85 insertions(+), 104 deletions(-)
7c2869
7c2869
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
7c2869
index 02e8393..4198be8 100644
7c2869
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
7c2869
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
7c2869
@@ -2226,7 +2226,6 @@ brick_graph_add_server (volgen_graph_t *graph, glusterd_volinfo_t *volinfo,
7c2869
 
7c2869
 
7c2869
         if (volname && !strcmp (volname, GLUSTER_SHARED_STORAGE)) {
7c2869
-
7c2869
                 memset (key, 0, sizeof (key));
7c2869
                 snprintf (key, sizeof (key), "strict-auth-accept");
7c2869
 
7c2869
@@ -5522,7 +5521,7 @@ generate_client_volfiles (glusterd_volinfo_t *volinfo,
7c2869
 
7c2869
 
7c2869
         if (volname && !strcmp (volname, GLUSTER_SHARED_STORAGE) &&
7c2869
-             client_type != GF_CLIENT_TRUSTED) {
7c2869
+            client_type != GF_CLIENT_TRUSTED) {
7c2869
                 /*
7c2869
                  * shared storage volume cannot be mounted from non trusted
7c2869
                  * nodes. So we are not creating volfiles for non-trusted
7c2869
diff --git a/xlators/protocol/auth/login/src/login.c b/xlators/protocol/auth/login/src/login.c
7c2869
index e918d38..4310027 100644
7c2869
--- a/xlators/protocol/auth/login/src/login.c
7c2869
+++ b/xlators/protocol/auth/login/src/login.c
7c2869
@@ -11,18 +11,78 @@
7c2869
 #include <fnmatch.h>
7c2869
 #include "authenticate.h"
7c2869
 
7c2869
-auth_result_t gf_authenticate_user (dict_t *input_params, dict_t *config_params,
7c2869
-                                    char *username, char *password,
7c2869
-                                    gf_boolean_t using_ssl) {
7c2869
+/* Note on strict_auth
7c2869
+ * - Strict auth kicks in when authentication is using the username, password
7c2869
+ *   in the volfile to login
7c2869
+ * - If enabled, auth is rejected if the username and password is not matched
7c2869
+ *   or is not present
7c2869
+ * - When using SSL names, this is automatically strict, and allows only those
7c2869
+ *   names that are present in the allow list, IOW strict auth checking has no
7c2869
+ *   implication when using SSL names
7c2869
+*/
7c2869
+
7c2869
+auth_result_t gf_auth (dict_t *input_params, dict_t *config_params)
7c2869
+{
7c2869
         auth_result_t  result  = AUTH_DONT_CARE;
7c2869
         int             ret             = 0;
7c2869
         data_t          *allow_user     = NULL;
7c2869
+        data_t          *username_data  = NULL;
7c2869
         data_t          *passwd_data    = NULL;
7c2869
+        data_t          *password_data  = NULL;
7c2869
+        char            *username       = NULL;
7c2869
+        char            *password       = NULL;
7c2869
         char            *brick_name     = NULL;
7c2869
         char            *searchstr      = NULL;
7c2869
         char            *username_str   = NULL;
7c2869
         char            *tmp            = NULL;
7c2869
         char            *username_cpy   = NULL;
7c2869
+        gf_boolean_t    using_ssl       = _gf_false;
7c2869
+        gf_boolean_t    strict_auth     = _gf_false;
7c2869
+
7c2869
+        username_data = dict_get (input_params, "ssl-name");
7c2869
+        if (username_data) {
7c2869
+                gf_log ("auth/login", GF_LOG_INFO,
7c2869
+                        "connecting user name: %s", username_data->data);
7c2869
+                using_ssl = _gf_true;
7c2869
+        } else {
7c2869
+                ret = dict_get_str_boolean (config_params, "strict-auth-accept",
7c2869
+                                            _gf_false);
7c2869
+                if (ret == -1)
7c2869
+                        strict_auth = _gf_false;
7c2869
+                else
7c2869
+                        strict_auth = ret;
7c2869
+
7c2869
+                username_data = dict_get (input_params, "username");
7c2869
+                if (!username_data) {
7c2869
+                        if (strict_auth) {
7c2869
+                                gf_log ("auth/login", GF_LOG_DEBUG,
7c2869
+                                        "username not found, strict auth"
7c2869
+                                        " configured returning REJECT");
7c2869
+                                result = AUTH_REJECT;
7c2869
+                        } else {
7c2869
+                                gf_log ("auth/login", GF_LOG_DEBUG,
7c2869
+                                        "username not found, returning"
7c2869
+                                        " DONT-CARE");
7c2869
+                        }
7c2869
+                        goto out;
7c2869
+                }
7c2869
+                password_data = dict_get (input_params, "password");
7c2869
+                if (!password_data) {
7c2869
+                        if (strict_auth) {
7c2869
+                                gf_log ("auth/login", GF_LOG_DEBUG,
7c2869
+                                        "password not found, strict auth"
7c2869
+                                        " configured returning REJECT");
7c2869
+                                result = AUTH_REJECT;
7c2869
+                        } else {
7c2869
+                                gf_log ("auth/login", GF_LOG_WARNING,
7c2869
+                                        "password not found, returning"
7c2869
+                                        " DONT-CARE");
7c2869
+                        }
7c2869
+                        goto out;
7c2869
+                }
7c2869
+                password = data_to_str (password_data);
7c2869
+        }
7c2869
+        username = data_to_str (username_data);
7c2869
 
7c2869
         brick_name = data_to_str (dict_get (input_params, "remote-subvolume"));
7c2869
         if (!brick_name) {
7c2869
@@ -35,10 +95,10 @@ auth_result_t gf_authenticate_user (dict_t *input_params, dict_t *config_params,
7c2869
         ret = gf_asprintf (&searchstr, "auth.login.%s.%s", brick_name,
7c2869
                            using_ssl ? "ssl-allow" : "allow");
7c2869
         if (-1 == ret) {
7c2869
-                gf_log ("auth/login", GF_LOG_WARNING,
7c2869
+                gf_log ("auth/login", GF_LOG_ERROR,
7c2869
                         "asprintf failed while setting search string, "
7c2869
-                        "returning AUTH_STRICT_ACCEPT");
7c2869
-                result = AUTH_STRICT_ACCEPT;
7c2869
+                        "returning REJECT");
7c2869
+                result = AUTH_REJECT;
7c2869
                 goto out;
7c2869
         }
7c2869
 
7c2869
@@ -58,7 +118,7 @@ auth_result_t gf_authenticate_user (dict_t *input_params, dict_t *config_params,
7c2869
                  * who do provide a valid username and password (in fact that's
7c2869
                  * pretty much the only thing we use non-SSL login auth for),
7c2869
                  * but they are allowed to connect.  It's wrong, but it's not
7c2869
-                 * worth changing elsewhere.  Therefore, we do the same thing
7c2869
+                 * worth changing elsewhere.  Therefore, we do the sane thing
7c2869
                  * only for SSL here.
7c2869
                  *
7c2869
                  * For SSL, if there's a list *you must be on it*.  Note that
7c2869
@@ -67,19 +127,14 @@ auth_result_t gf_authenticate_user (dict_t *input_params, dict_t *config_params,
7c2869
                  * disabled, though authentication and encryption are still
7c2869
                  * active.
7c2869
                  *
7c2869
-                 * If option strict-auth-accept is enabled, connection
7c2869
-                 * will be rejected if you don't have any matching
7c2869
-                 * username and password (password is only for non-ssl users).
7c2869
+                 * Read NOTE on strict_auth above.
7c2869
                  */
7c2869
-                if (using_ssl) {
7c2869
+                if (using_ssl || strict_auth) {
7c2869
                         result = AUTH_REJECT;
7c2869
                 }
7c2869
                 username_cpy = gf_strdup (allow_user->data);
7c2869
-                if (!username_cpy) {
7c2869
-                        if (!using_ssl)
7c2869
-                                result = AUTH_STRICT_ACCEPT;
7c2869
+                if (!username_cpy)
7c2869
                         goto out;
7c2869
-                }
7c2869
 
7c2869
                 username_str = strtok_r (username_cpy, " ,", &tmp);
7c2869
 
7c2869
@@ -101,7 +156,6 @@ auth_result_t gf_authenticate_user (dict_t *input_params, dict_t *config_params,
7c2869
                                 if (-1 == ret) {
7c2869
                                         gf_log ("auth/login", GF_LOG_WARNING,
7c2869
                                                 "asprintf failed while setting search string");
7c2869
-                                        result = AUTH_STRICT_ACCEPT;
7c2869
                                         goto out;
7c2869
                                 }
7c2869
                                 passwd_data = dict_get (config_params, searchstr);
7c2869
@@ -127,65 +181,11 @@ auth_result_t gf_authenticate_user (dict_t *input_params, dict_t *config_params,
7c2869
                         }
7c2869
                         username_str = strtok_r (NULL, " ,", &tmp);
7c2869
                 }
7c2869
-        } else {
7c2869
-                result = AUTH_STRICT_ACCEPT;
7c2869
         }
7c2869
+
7c2869
 out:
7c2869
         GF_FREE (username_cpy);
7c2869
-        return result;
7c2869
-}
7c2869
-
7c2869
-auth_result_t gf_auth (dict_t *input_params, dict_t *config_params)
7c2869
-{
7c2869
-        auth_result_t   result           = AUTH_DONT_CARE;
7c2869
-        auth_result_t   ssl_result       = AUTH_DONT_CARE;
7c2869
-        data_t          *username_data  = NULL;
7c2869
-        data_t          *password_data  = NULL;
7c2869
-        char            *username       = NULL;
7c2869
-        char            *password       = NULL;
7c2869
-        gf_boolean_t    using_ssl       = _gf_false;
7c2869
 
7c2869
-        username_data = dict_get (input_params, "username");
7c2869
-        if (!username_data) {
7c2869
-                gf_log ("auth/login", GF_LOG_DEBUG,
7c2869
-                        "username not found, returning AUTH_STRICT_ACCEPT");
7c2869
-                result = AUTH_STRICT_ACCEPT;
7c2869
-                goto out;
7c2869
-        }
7c2869
-        password_data = dict_get (input_params, "password");
7c2869
-        if (!password_data) {
7c2869
-                gf_log ("auth/login", GF_LOG_WARNING,
7c2869
-                        "password not found, returning AUTH_STRICT_ACCEPT");
7c2869
-                result = AUTH_STRICT_ACCEPT;
7c2869
-                goto out;
7c2869
-        }
7c2869
-        password = data_to_str (password_data);
7c2869
-        username = data_to_str (username_data);
7c2869
-
7c2869
-        result = gf_authenticate_user (input_params, config_params,
7c2869
-                                                username, password, using_ssl);
7c2869
-
7c2869
-        username_data = dict_get (input_params, "ssl-name");
7c2869
-        if (username_data) {
7c2869
-                gf_log ("auth/login", GF_LOG_INFO,
7c2869
-                        "connecting user name: %s", username_data->data);
7c2869
-                username = data_to_str (username_data);
7c2869
-                using_ssl = _gf_true;
7c2869
-                ssl_result = gf_authenticate_user (input_params, config_params,
7c2869
-                                                   username, NULL, using_ssl);
7c2869
-                if (ssl_result == AUTH_ACCEPT && result != AUTH_ACCEPT) {
7c2869
-                        /*
7c2869
-                         * Here, ssl authentication returns true, but non-ssl
7c2869
-                         * authentication returns differnt result. We are
7c2869
-                         * calling for a strict auth check in this case.
7c2869
-                         */
7c2869
-                        result = AUTH_STRICT_ACCEPT;
7c2869
-                } else {
7c2869
-                        result = ssl_result;
7c2869
-                }
7c2869
-        }
7c2869
-
7c2869
-out:
7c2869
         return result;
7c2869
 }
7c2869
 
7c2869
diff --git a/xlators/protocol/server/src/authenticate.c b/xlators/protocol/server/src/authenticate.c
7c2869
index 977ed75..c000776 100644
7c2869
--- a/xlators/protocol/server/src/authenticate.c
7c2869
+++ b/xlators/protocol/server/src/authenticate.c
7c2869
@@ -18,9 +18,7 @@
7c2869
 #include <dlfcn.h>
7c2869
 #include <errno.h>
7c2869
 #include "authenticate.h"
7c2869
-#include "authenticate.h"
7c2869
 #include "server-messages.h"
7c2869
-#include "server.h"
7c2869
 
7c2869
 static int
7c2869
 init (dict_t *this, char *key, data_t *value, void *data)
7c2869
@@ -175,7 +173,6 @@ gf_auth_one_method (dict_t *this, char *key, data_t *value, void *data)
7c2869
 {
7c2869
         gf_auth_args_t  *args   = data;
7c2869
         auth_handle_t   *handle = NULL;
7c2869
-        int64_t          result;
7c2869
 
7c2869
         if (!value) {
7c2869
                 return 0;
7c2869
@@ -186,13 +183,10 @@ gf_auth_one_method (dict_t *this, char *key, data_t *value, void *data)
7c2869
                 return 0;
7c2869
         }
7c2869
 
7c2869
-        result = handle->authenticate (args->iparams, args->cparams);
7c2869
-        switch (result) {
7c2869
+        switch (handle->authenticate (args->iparams, args->cparams)) {
7c2869
         case AUTH_ACCEPT:
7c2869
-        case AUTH_STRICT_ACCEPT:
7c2869
-                if (args->result != AUTH_REJECT &&
7c2869
-                    args->result != AUTH_STRICT_ACCEPT) {
7c2869
-                        args->result = result;
7c2869
+                if (args->result != AUTH_REJECT) {
7c2869
+                        args->result = AUTH_ACCEPT;
7c2869
                 }
7c2869
                 /* FALLTHROUGH */
7c2869
         default:
7c2869
@@ -204,8 +198,9 @@ gf_auth_one_method (dict_t *this, char *key, data_t *value, void *data)
7c2869
 }
7c2869
 
7c2869
 auth_result_t
7c2869
-gf_authenticate (server_conf_t *conf, dict_t *input_params,
7c2869
-                 dict_t *config_params, dict_t *auth_modules)
7c2869
+gf_authenticate (dict_t *input_params,
7c2869
+                 dict_t *config_params,
7c2869
+                 dict_t *auth_modules)
7c2869
 {
7c2869
         char *name = NULL;
7c2869
         data_t *peerinfo_data = NULL;
7c2869
@@ -215,19 +210,9 @@ gf_authenticate (server_conf_t *conf, dict_t *input_params,
7c2869
         args.cparams = config_params;
7c2869
         args.result = AUTH_DONT_CARE;
7c2869
 
7c2869
-        GF_VALIDATE_OR_GOTO ("authentication", conf, out);
7c2869
         dict_foreach (auth_modules, gf_auth_one_method, &args);
7c2869
 
7c2869
-        switch (args.result) {
7c2869
-        case AUTH_STRICT_ACCEPT:
7c2869
-                if (!conf->strict_auth_enabled) {
7c2869
-                        args.result = AUTH_ACCEPT;
7c2869
-                        break;
7c2869
-                }
7c2869
-                gf_msg ("auth", GF_LOG_ERROR, 0, PS_MSG_REMOTE_CLIENT_REFUSED,
7c2869
-                        "Authentication is failed due to the strict options.");
7c2869
-                /* Fallthrough */
7c2869
-        case AUTH_DONT_CARE:
7c2869
+        if (AUTH_DONT_CARE == args.result) {
7c2869
                 peerinfo_data = dict_get (input_params, "peer-info-name");
7c2869
 
7c2869
                 if (peerinfo_data) {
7c2869
@@ -238,9 +223,8 @@ gf_authenticate (server_conf_t *conf, dict_t *input_params,
7c2869
                         "no authentication module is interested in "
7c2869
                         "accepting remote-client %s", name);
7c2869
                 args.result = AUTH_REJECT;
7c2869
-                /* Fallthrough */
7c2869
         }
7c2869
-out:
7c2869
+
7c2869
         return args.result;
7c2869
 }
7c2869
 
7c2869
diff --git a/xlators/protocol/server/src/authenticate.h b/xlators/protocol/server/src/authenticate.h
7c2869
index d5971d3..5f92183 100644
7c2869
--- a/xlators/protocol/server/src/authenticate.h
7c2869
+++ b/xlators/protocol/server/src/authenticate.h
7c2869
@@ -25,8 +25,7 @@
7c2869
 typedef enum {
7c2869
         AUTH_ACCEPT,
7c2869
         AUTH_REJECT,
7c2869
-        AUTH_DONT_CARE,
7c2869
-        AUTH_STRICT_ACCEPT
7c2869
+        AUTH_DONT_CARE
7c2869
 } auth_result_t;
7c2869
 
7c2869
 typedef auth_result_t (*auth_fn_t) (dict_t *input_params,
7c2869
@@ -40,5 +39,6 @@ typedef struct {
7c2869
 
7c2869
 int32_t gf_auth_init (xlator_t *xl, dict_t *auth_modules);
7c2869
 void gf_auth_fini (dict_t *auth_modules);
7c2869
+auth_result_t gf_authenticate (dict_t *, dict_t *, dict_t *);
7c2869
 
7c2869
 #endif /* _AUTHENTICATE_H */
7c2869
diff --git a/xlators/protocol/server/src/server-handshake.c b/xlators/protocol/server/src/server-handshake.c
7c2869
index b67ed47..f6d5a0b 100644
7c2869
--- a/xlators/protocol/server/src/server-handshake.c
7c2869
+++ b/xlators/protocol/server/src/server-handshake.c
7c2869
@@ -765,7 +765,7 @@ server_setvolume (rpcsvc_request_t *req)
7c2869
                         PS_MSG_CLIENT_VERSION_NOT_SET,
7c2869
                         "client-version not set, may be of older version");
7c2869
 
7c2869
-        ret = gf_authenticate (conf, params, config_params,
7c2869
+        ret = gf_authenticate (params, config_params,
7c2869
                                conf->auth_modules);
7c2869
 
7c2869
         if (ret == AUTH_ACCEPT) {
7c2869
diff --git a/xlators/protocol/server/src/server.c b/xlators/protocol/server/src/server.c
7c2869
index f89e743..7dd2a5a 100644
7c2869
--- a/xlators/protocol/server/src/server.c
7c2869
+++ b/xlators/protocol/server/src/server.c
7c2869
@@ -910,7 +910,7 @@ do_rpc:
7c2869
                                 if (strcmp (xprt_path, auth_path) != 0) {
7c2869
                                         continue;
7c2869
                                 }
7c2869
-                                ret = gf_authenticate (conf, xprt->clnt_options,
7c2869
+                                ret = gf_authenticate (xprt->clnt_options,
7c2869
                                                        options,
7c2869
                                                        conf->auth_modules);
7c2869
                                 if (ret == AUTH_ACCEPT) {
7c2869
@@ -1104,7 +1104,7 @@ init (xlator_t *this)
7c2869
         }
7c2869
 
7c2869
         ret = dict_get_str_boolean (this->options, "strict-auth-accept",
7c2869
-                        _gf_false);
7c2869
+                                    _gf_false);
7c2869
         if (ret == -1)
7c2869
                 conf->strict_auth_enabled = _gf_false;
7c2869
         else
7c2869
diff --git a/xlators/protocol/server/src/server.h b/xlators/protocol/server/src/server.h
7c2869
index 4c35aaa..6af4657 100644
7c2869
--- a/xlators/protocol/server/src/server.h
7c2869
+++ b/xlators/protocol/server/src/server.h
7c2869
@@ -245,8 +245,6 @@ serialize_rsp_dirent (gf_dirent_t *entries, gfs3_readdir_rsp *rsp);
7c2869
 
7c2869
 int
7c2869
 serialize_rsp_direntp (gf_dirent_t *entries, gfs3_readdirp_rsp *rsp);
7c2869
-auth_result_t gf_authenticate (server_conf_t *conf, dict_t *input_params,
7c2869
-                               dict_t *config_params, dict_t *auth_modules);
7c2869
 
7c2869
 server_ctx_t*
7c2869
 server_ctx_get (client_t *client, xlator_t *xlator);
7c2869
-- 
7c2869
1.8.3.1
7c2869