]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
auth/AuthServiceHandler: keep track of global_id and whether it is new
authorIlya Dryomov <idryomov@gmail.com>
Tue, 9 Mar 2021 15:33:55 +0000 (16:33 +0100)
committerIlya Dryomov <idryomov@gmail.com>
Mon, 12 Apr 2021 18:50:53 +0000 (20:50 +0200)
AuthServiceHandler already has global_id field, but it is unused.
Revive it and let the handler know whether global_id is newly assigned
by the monitor or provided by the client.

Lift the setting of entity_name into AuthServiceHandler.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
(cherry picked from commit b50b6abd60e730176a7ef602bdd25d789a3c467d)

src/auth/AuthServiceHandler.cc
src/auth/AuthServiceHandler.h
src/auth/cephx/CephxServiceHandler.cc
src/auth/cephx/CephxServiceHandler.h
src/auth/krb/KrbServiceHandler.cpp
src/auth/krb/KrbServiceHandler.hpp
src/auth/none/AuthNoneServiceHandler.h
src/mon/AuthMonitor.cc
src/mon/Monitor.cc

index 51c5c75da7bf775466d2ffe9ab98b12aabedc023..6e70de41dbd322eed289fe114bf4cb31e3784ea8 100644 (file)
 #include "krb/KrbServiceHandler.hpp"
 #endif
 #include "none/AuthNoneServiceHandler.h"
+#include "common/dout.h"
 
 #define dout_subsys ceph_subsys_auth
 
 
+int AuthServiceHandler::start_session(const EntityName& entity_name,
+                                     uint64_t global_id,
+                                     bool is_new_global_id,
+                                     ceph::buffer::list *result,
+                                     AuthCapsInfo *caps)
+{
+  ceph_assert(!this->entity_name.get_type() && !this->global_id);
+
+  ldout(cct, 10) << __func__ << " entity_name=" << entity_name
+                << " global_id=" << global_id << " is_new_global_id="
+                << is_new_global_id << dendl;
+  this->entity_name = entity_name;
+  this->global_id = global_id;
+
+  return do_start_session(is_new_global_id, result, caps);
+}
+
 AuthServiceHandler *get_auth_service_handler(int type, CephContext *cct, KeyServer *ks)
 {
   switch (type) {
index a6dfe019817d14b61827993150539eb99351ad4e..89619d17cd825ed35ae88e95074062747e46d8f5 100644 (file)
@@ -28,17 +28,19 @@ struct AuthCapsInfo;
 struct AuthServiceHandler {
 protected:
   CephContext *cct;
-public:
   EntityName entity_name;
-  uint64_t global_id;
+  uint64_t global_id = 0;
 
-  explicit AuthServiceHandler(CephContext *cct_) : cct(cct_), global_id(0) {}
+public:
+  explicit AuthServiceHandler(CephContext *cct_) : cct(cct_) {}
 
   virtual ~AuthServiceHandler() { }
 
-  virtual int start_session(const EntityName& name,
-                           ceph::buffer::list *result,
-                           AuthCapsInfo *caps) = 0;
+  int start_session(const EntityName& entity_name,
+                   uint64_t global_id,
+                   bool is_new_global_id,
+                   ceph::buffer::list *result,
+                   AuthCapsInfo *caps);
   virtual int handle_request(ceph::buffer::list::const_iterator& indata,
                             size_t connection_secret_required_length,
                             ceph::buffer::list *result,
@@ -47,7 +49,13 @@ public:
                             CryptoKey *session_key,
                             std::string *connection_secret) = 0;
 
-  EntityName& get_entity_name() { return entity_name; }
+  const EntityName& get_entity_name() { return entity_name; }
+  uint64_t get_global_id() { return global_id; }
+
+private:
+  virtual int do_start_session(bool is_new_global_id,
+                              ceph::buffer::list *result,
+                              AuthCapsInfo *caps) = 0;
 };
 
 extern AuthServiceHandler *get_auth_service_handler(int type, CephContext *cct, KeyServer *ks);
index 129dd96465ee7bd5701bd2c29e21199d35297bad..8760ce0f83972c73a90a221c01b5fbbcc1be66e3 100644 (file)
@@ -35,13 +35,11 @@ using ceph::bufferlist;
 using ceph::decode;
 using ceph::encode;
 
-int CephxServiceHandler::start_session(
-  const EntityName& name,
+int CephxServiceHandler::do_start_session(
+  bool is_new_global_id,
   bufferlist *result_bl,
   AuthCapsInfo *caps)
 {
-  entity_name = name;
-
   uint64_t min = 1; // always non-zero
   uint64_t max = std::numeric_limits<uint64_t>::max();
   server_challenge = ceph::util::generate_random_number<uint64_t>(min, max);
index e770f140c8043d9796a469db1ebd2c9819a0e614..88d49c79b19afd6ee25fbdc80bd087ed7c7a73c8 100644 (file)
@@ -29,9 +29,6 @@ public:
     : AuthServiceHandler(cct_), key_server(ks), server_challenge(0) {}
   ~CephxServiceHandler() override {}
   
-  int start_session(const EntityName& name,
-                   ceph::buffer::list *result_bl,
-                   AuthCapsInfo *caps) override;
   int handle_request(
     ceph::buffer::list::const_iterator& indata,
     size_t connection_secret_required_length,
@@ -42,6 +39,10 @@ public:
     std::string *connection_secret) override;
 
 private:
+  int do_start_session(bool is_new_global_id,
+                      ceph::buffer::list *result_bl,
+                      AuthCapsInfo *caps) override;
+
   void build_cephx_response_header(int request_type, int status,
                                   ceph::buffer::list& bl);
 };
index be1510cd621af10226c015654e7c83737beb452e..0b51097499c9ec13db5b95b950850b21556581ba 100644 (file)
@@ -152,8 +152,8 @@ int KrbServiceHandler::handle_request(
   return result;
 }
 
-int KrbServiceHandler::start_session(
-  const EntityName& name,
+int KrbServiceHandler::do_start_session(
+  bool is_new_global_id,
   bufferlist *buff_list,
   AuthCapsInfo *caps)
 {
@@ -167,7 +167,6 @@ int KrbServiceHandler::start_session(
 
   gss_buffer_in.length = gss_service_name.length();
   gss_buffer_in.value  = (const_cast<char*>(gss_service_name.c_str()));
-  entity_name = name;
 
   gss_major_status = gss_import_name(&gss_minor_status, 
                                      &gss_buffer_in, 
index c1179cc3f0cd2af59b5ef9200d645a44e044136e..69236098acb7653d1e00b4904e8a31491e1629b9 100644 (file)
@@ -45,11 +45,11 @@ class KrbServiceHandler : public AuthServiceHandler {
                       CryptoKey *session_key,
                       std::string *connection_secret) override;
 
-    int start_session(const EntityName& name,
-                     bufferlist *buff_list,
-                      AuthCapsInfo *caps) override;
-
   private:
+    int do_start_session(bool is_new_global_id,
+                        ceph::buffer::list *buff_list,
+                        AuthCapsInfo *caps) override;
+
     gss_buffer_desc m_gss_buffer_out;
     gss_cred_id_t m_gss_credentials; 
     gss_ctx_id_t m_gss_sec_ctx; 
index a16838eecb27cd45b7a149e6d3447ad0b2a863cd..7ceb2ff4ba7a2f0a2b61a7126ec33535e1faaf98 100644 (file)
@@ -25,13 +25,6 @@ public:
     : AuthServiceHandler(cct_) {}
   ~AuthNoneServiceHandler() override {}
   
-  int start_session(const EntityName& name,
-                   ceph::buffer::list *result_bl,
-                   AuthCapsInfo *caps) override {
-    entity_name = name;
-    caps->allow_all = true;
-    return 1;
-  }
   int handle_request(ceph::buffer::list::const_iterator& indata,
                     size_t connection_secret_required_length,
                     ceph::buffer::list *result_bl,
@@ -41,6 +34,14 @@ public:
                     std::string *connection_secret) override {
     return 0;
   }
+
+private:
+  int do_start_session(bool is_new_global_id,
+                      ceph::buffer::list *result_bl,
+                      AuthCapsInfo *caps) override {
+    caps->allow_all = true;
+    return 1;
+  }
 };
 
 #endif
index d4226a93b647abe2656463f7387bcc9de892dc44..abbe124a4e95f9bf0197b143d54d386f59dd6693 100644 (file)
@@ -615,6 +615,7 @@ bool AuthMonitor::prep_auth(MonOpRequestRef op, bool paxos_writable)
   bool start = false;
   bool finished = false;
   EntityName entity_name;
+  bool is_new_global_id = false;
 
   // set up handler?
   if (m->protocol == 0 && !s->auth_handler) {
@@ -734,12 +735,15 @@ bool AuthMonitor::prep_auth(MonOpRequestRef op, bool paxos_writable)
       ceph_assert(!paxos_writable);
       return false;
     }
+    is_new_global_id = true;
   }
 
   try {
     if (start) {
       // new session
       ret = s->auth_handler->start_session(entity_name,
+                                          s->con->peer_global_id,
+                                          is_new_global_id,
                                           &response_bl,
                                           &s->con->peer_caps_info);
     } else {
index b8772b53d75b3953f68264dc0b5fb825fc2c25e2..3a66c5025eb6384a39dae64b0fee552298280cd0 100644 (file)
@@ -6341,14 +6341,14 @@ int Monitor::handle_auth_request(
     // are supported by the client if we require it.  for msgr2 that
     // is not necessary.
 
+    bool is_new_global_id = false;
     if (!con->peer_global_id) {
       con->peer_global_id = authmon()->_assign_global_id();
       if (!con->peer_global_id) {
        dout(1) << __func__ << " failed to assign global_id" << dendl;
        return -EBUSY;
       }
-      dout(10) << __func__ << "  assigned global_id " << con->peer_global_id
-              << dendl;
+      is_new_global_id = true;
     }
 
     // set up partial session
@@ -6358,6 +6358,8 @@ int Monitor::handle_auth_request(
 
     r = s->auth_handler->start_session(
       entity_name,
+      con->peer_global_id,
+      is_new_global_id,
       reply,
       &con->peer_caps_info);
   } else {