From: Sage Weil Date: Mon, 18 Feb 2019 19:34:15 +0000 (-0600) Subject: auth: push con_mode selection into AuthRegistry helper X-Git-Tag: v14.1.0~7^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2d530938753313a776258ff9fa8208db637c9d96;p=ceph.git auth: push con_mode selection into AuthRegistry helper Signed-off-by: Sage Weil --- diff --git a/src/auth/AuthRegistry.cc b/src/auth/AuthRegistry.cc index a7385a833a88..f7483d56211d 100644 --- a/src/auth/AuthRegistry.cc +++ b/src/auth/AuthRegistry.cc @@ -249,6 +249,24 @@ void AuthRegistry::get_supported_modes( } } +uint32_t AuthRegistry::pick_mode( + int peer_type, + uint32_t auth_method, + const std::vector& preferred_modes) +{ + std::vector allowed_modes; + get_supported_modes(peer_type, auth_method, &allowed_modes); + for (auto mode : preferred_modes) { + if (std::find(allowed_modes.begin(), allowed_modes.end(), mode) + != allowed_modes.end()) { + return mode; + } + } + ldout(cct,1) << "failed to pick con mode from client's " << preferred_modes + << " and our " << allowed_modes << dendl; + return CEPH_CON_MODE_UNKNOWN; +} + AuthAuthorizeHandler *AuthRegistry::get_handler(int peer_type, int method) { std::scoped_lock l{lock}; diff --git a/src/auth/AuthRegistry.h b/src/auth/AuthRegistry.h index 5474355110de..ae2cad4fcc3a 100644 --- a/src/auth/AuthRegistry.h +++ b/src/auth/AuthRegistry.h @@ -56,6 +56,10 @@ public: uint32_t auth_method, std::vector *modes); + uint32_t pick_mode(int peer_type, + uint32_t auth_method, + const std::vector& preferred_modes); + AuthAuthorizeHandler *get_handler(int peer_type, int method); const char** get_tracked_conf_keys() const override; diff --git a/src/auth/AuthServer.h b/src/auth/AuthServer.h index 61a2650f192e..e3bc8787710e 100644 --- a/src/auth/AuthServer.h +++ b/src/auth/AuthServer.h @@ -33,6 +33,14 @@ public: auth_registry.get_supported_modes(peer_type, auth_method, modes); } + /// Get support connection modes for the given peer type and auth method + virtual uint32_t pick_con_mode( + int peer_type, + uint32_t auth_method, + const std::vector& preferred_modes) { + return auth_registry.pick_mode(peer_type, auth_method, preferred_modes); + } + /// return an AuthAuthorizeHandler for the given peer type and auth method AuthAuthorizeHandler *get_auth_authorize_handler( int peer_type, diff --git a/src/msg/async/ProtocolV2.cc b/src/msg/async/ProtocolV2.cc index ce2ef6490b55..712686b598b1 100644 --- a/src/msg/async/ProtocolV2.cc +++ b/src/msg/async/ProtocolV2.cc @@ -2443,22 +2443,10 @@ CtPtr ProtocolV2::handle_auth_request(char *payload, uint32_t length) { << ", payload_len=" << request.auth_payload().length() << ")" << dendl; auth_meta->auth_method = request.method(); - - // select a connection mode - auto& preferred_modes = request.preferred_modes(); - std::vector allowed_modes; - messenger->auth_server->get_supported_con_modes( - connection->get_peer_type(), auth_meta->auth_method, &allowed_modes); - for (auto mode : preferred_modes) { - if (std::find(allowed_modes.begin(), allowed_modes.end(), mode) - != allowed_modes.end()) { - auth_meta->con_mode = mode; - break; - } - } + auth_meta->con_mode = messenger->auth_server->pick_con_mode( + connection->get_peer_type(), auth_meta->auth_method, + request.preferred_modes()); if (auth_meta->con_mode == CEPH_CON_MODE_UNKNOWN) { - ldout(cct,1) << "failed to pick con mode from client's " << preferred_modes - << " and our " << allowed_modes << dendl; return _auth_bad_method(-EOPNOTSUPP); } return _handle_auth_request(request.auth_payload(), false);