]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/MonClient: make MonClientPinger an AuthCleint
authorSage Weil <sage@redhat.com>
Wed, 30 Jan 2019 23:59:51 +0000 (17:59 -0600)
committerSage Weil <sage@redhat.com>
Thu, 7 Feb 2019 18:10:34 +0000 (12:10 -0600)
Reuse MonConnection to do the authentication.

Note this is a change in behavior: ceph ping mon* now requires
authentication.

Signed-off-by: Sage Weil <sage@redhat.com>
src/mon/MonClient.cc
src/mon/MonClient.h

index a51209124deb1ab4c87063acb1d253658c7b5bca..ac7922c3153948688278f2442dd24d6805759a13 100644 (file)
@@ -224,15 +224,29 @@ int MonClient::ping_monitor(const string &mon_id, string *result_reply)
     return -ENOENT;
   }
 
-  MonClientPinger *pinger = new MonClientPinger(cct, result_reply);
+  // N.B. monc isn't initialized
+
+  auth_registry.refresh_config();
+
+  KeyRing keyring;
+  keyring.from_ceph_context(cct);
+  RotatingKeyRing rkeyring(cct, cct->get_module_type(), &keyring);
+
+  MonClientPinger *pinger = new MonClientPinger(cct,
+                                               &rkeyring,
+                                               result_reply);
 
   Messenger *smsgr = Messenger::create_client_messenger(cct, "temp_ping_client");
   smsgr->add_dispatcher_head(pinger);
+  smsgr->set_auth_client(pinger);
   smsgr->start();
 
   ConnectionRef con = smsgr->connect_to_mon(monmap.get_addrs(new_mon_id));
   ldout(cct, 10) << __func__ << " ping mon." << new_mon_id
                  << " " << con->get_peer_addr() << dendl;
+
+  pinger->mc.reset(new MonConnection(cct, con, 0, &auth_registry));
+  pinger->mc->start(monmap.get_epoch(), entity_name);
   con->send_message(new MPing);
 
   pinger->lock.Lock();
@@ -245,6 +259,7 @@ int MonClient::ping_monitor(const string &mon_id, string *result_reply)
   pinger->lock.Unlock();
 
   con->mark_down();
+  pinger->mc.reset();
   smsgr->shutdown();
   smsgr->wait();
   delete smsgr;
index 19b921defc686b330f911adaeddc4c40a467e65e..5503d46943d06f7c6f9ffa26ccc3072808fafac2 100644 (file)
@@ -43,61 +43,6 @@ class AuthClientHandler;
 class KeyRing;
 class RotatingKeyRing;
 
-struct MonClientPinger : public Dispatcher {
-
-  Mutex lock;
-  Cond ping_recvd_cond;
-  string *result;
-  bool done;
-
-  MonClientPinger(CephContext *cct_, string *res_) :
-    Dispatcher(cct_),
-    lock("MonClientPinger::lock"),
-    result(res_),
-    done(false)
-  { }
-
-  int wait_for_reply(double timeout = 0.0) {
-    utime_t until = ceph_clock_now();
-    until += (timeout > 0 ? timeout : cct->_conf->client_mount_timeout);
-    done = false;
-
-    int ret = 0;
-    while (!done) {
-      ret = ping_recvd_cond.WaitUntil(lock, until);
-      if (ret == ETIMEDOUT)
-        break;
-    }
-    return ret;
-  }
-
-  bool ms_dispatch(Message *m) override {
-    std::lock_guard l(lock);
-    if (m->get_type() != CEPH_MSG_PING)
-      return false;
-
-    bufferlist &payload = m->get_payload();
-    if (result && payload.length() > 0) {
-      auto p = std::cbegin(payload);
-      decode(*result, p);
-    }
-    done = true;
-    ping_recvd_cond.SignalAll();
-    m->put();
-    return true;
-  }
-  bool ms_handle_reset(Connection *con) override {
-    std::lock_guard l(lock);
-    done = true;
-    ping_recvd_cond.SignalAll();
-    return true;
-  }
-  void ms_handle_remote_reset(Connection *con) override {}
-  bool ms_handle_refused(Connection *con) override {
-    return false;
-  }
-};
-
 class MonConnection {
 public:
   MonConnection(CephContext *cct,
@@ -183,6 +128,108 @@ private:
   AuthRegistry *auth_registry;
 };
 
+
+struct MonClientPinger : public Dispatcher,
+                        public AuthClient {
+
+  Mutex lock;
+  Cond ping_recvd_cond;
+  string *result;
+  bool done;
+  RotatingKeyRing *keyring;
+  std::unique_ptr<MonConnection> mc;
+
+  MonClientPinger(CephContext *cct_,
+                 RotatingKeyRing *keyring,
+                 string *res_) :
+    Dispatcher(cct_),
+    lock("MonClientPinger::lock"),
+    result(res_),
+    done(false),
+    keyring(keyring)
+  { }
+
+  int wait_for_reply(double timeout = 0.0) {
+    utime_t until = ceph_clock_now();
+    until += (timeout > 0 ? timeout : cct->_conf->client_mount_timeout);
+    done = false;
+
+    int ret = 0;
+    while (!done) {
+      ret = ping_recvd_cond.WaitUntil(lock, until);
+      if (ret == ETIMEDOUT)
+        break;
+    }
+    return ret;
+  }
+
+  bool ms_dispatch(Message *m) override {
+    std::lock_guard l(lock);
+    if (m->get_type() != CEPH_MSG_PING)
+      return false;
+
+    bufferlist &payload = m->get_payload();
+    if (result && payload.length() > 0) {
+      auto p = std::cbegin(payload);
+      decode(*result, p);
+    }
+    done = true;
+    ping_recvd_cond.SignalAll();
+    m->put();
+    return true;
+  }
+  bool ms_handle_reset(Connection *con) override {
+    std::lock_guard l(lock);
+    done = true;
+    ping_recvd_cond.SignalAll();
+    return true;
+  }
+  void ms_handle_remote_reset(Connection *con) override {}
+  bool ms_handle_refused(Connection *con) override {
+    return false;
+  }
+
+  // AuthClient
+  int get_auth_request(
+    Connection *con,
+    AuthConnectionMeta *auth_meta,
+    uint32_t *auth_method,
+    std::vector<uint32_t> *preferred_modes,
+    bufferlist *bl) override {
+    return mc->get_auth_request(auth_method, preferred_modes, bl,
+                               cct->_conf->name, 0, keyring);
+  }
+  int handle_auth_reply_more(
+    Connection *con,
+    AuthConnectionMeta *auth_meta,
+    const bufferlist& bl,
+    bufferlist *reply) override {
+    return mc->handle_auth_reply_more(auth_meta, bl, reply);
+  }
+  int handle_auth_done(
+    Connection *con,
+    AuthConnectionMeta *auth_meta,
+    uint64_t global_id,
+    uint32_t con_mode,
+    const bufferlist& bl,
+    CryptoKey *session_key,
+    std::string *connection_secret) override {
+    return mc->handle_auth_done(auth_meta, global_id, bl,
+                               session_key, connection_secret);
+  }
+  int handle_auth_bad_method(
+    Connection *con,
+    AuthConnectionMeta *auth_meta,
+    uint32_t old_auth_method,
+    int result,
+    const std::vector<uint32_t>& allowed_methods,
+    const std::vector<uint32_t>& allowed_modes) override {
+    return mc->handle_auth_bad_method(old_auth_method, result,
+                                     allowed_methods, allowed_modes);
+  }
+};
+
+
 class MonClient : public Dispatcher,
                  public AuthClient,
                  public AuthServer /* for mgr, osd, mds */ {