]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/net: dummy auth for protocol v2
authorYingxin Cheng <yingxincheng@gmail.com>
Mon, 11 Mar 2019 08:19:24 +0000 (16:19 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 5 Apr 2019 03:21:19 +0000 (11:21 +0800)
Signed-off-by: Yingxin Cheng <yingxincheng@gmail.com>
src/crimson/auth/AuthClient.h [new file with mode: 0644]
src/crimson/auth/AuthServer.h [new file with mode: 0644]
src/crimson/auth/DummyAuth.h [new file with mode: 0644]
src/crimson/net/Messenger.h
src/crimson/net/ProtocolV2.cc
src/test/crimson/test_alien_echo.cc

diff --git a/src/crimson/auth/AuthClient.h b/src/crimson/auth/AuthClient.h
new file mode 100644 (file)
index 0000000..9d737e0
--- /dev/null
@@ -0,0 +1,53 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#pragma once
+
+#include <vector>
+#include "crimson/net/Fwd.h"
+
+class CryptoKey;
+
+namespace ceph::auth {
+
+// TODO: revisit interfaces for non-dummy implementations
+class AuthClient {
+public:
+  virtual ~AuthClient() {}
+
+  // Build an authentication request to begin the handshake
+  virtual int get_auth_request(
+    ceph::net::ConnectionRef conn,
+    AuthConnectionMetaRef auth_meta,
+    uint32_t *method,
+    std::vector<uint32_t> *preferred_modes,
+    bufferlist *out) = 0;
+
+  // Handle server's request to continue the handshake
+  virtual int handle_auth_reply_more(
+    ceph::net::ConnectionRef conn,
+    AuthConnectionMetaRef auth_meta,
+    const bufferlist& bl,
+    bufferlist *reply) = 0;
+
+  // Handle server's indication that authentication succeeded
+  virtual int handle_auth_done(
+    ceph::net::ConnectionRef conn,
+    AuthConnectionMetaRef auth_meta,
+    uint64_t global_id,
+    uint32_t con_mode,
+    const bufferlist& bl,
+    CryptoKey *session_key,
+    std::string *connection_secret) = 0;
+
+  // Handle server's indication that the previous auth attempt failed
+  virtual int handle_auth_bad_method(
+    ceph::net::ConnectionRef conn,
+    AuthConnectionMetaRef auth_meta,
+    uint32_t old_auth_method,
+    int result,
+    const std::vector<uint32_t>& allowed_methods,
+    const std::vector<uint32_t>& allowed_modes) = 0;
+};
+
+} // namespace ceph::auth
diff --git a/src/crimson/auth/AuthServer.h b/src/crimson/auth/AuthServer.h
new file mode 100644 (file)
index 0000000..e15d47b
--- /dev/null
@@ -0,0 +1,72 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#pragma once
+
+#include <vector>
+#include "auth/AuthAuthorizeHandler.h"
+#include "crimson/net/Fwd.h"
+
+namespace ceph::auth {
+
+// TODO: revisit interfaces for non-dummy implementations
+class AuthServer {
+public:
+  // TODO:
+  // AuthRegistry auth_registry;
+
+  AuthServer() {}
+  virtual ~AuthServer() {}
+
+  // Get authentication methods and connection modes for the given peer type
+  virtual void get_supported_auth_methods(
+    int peer_type,
+    std::vector<uint32_t> *methods,
+    std::vector<uint32_t> *modes = nullptr) {
+    // auth_registry.get_supported_methods(peer_type, methods, modes);
+    *methods = { CEPH_AUTH_NONE };
+    if (modes != nullptr) {
+      *modes = { CEPH_CON_MODE_CRC };
+    }
+  }
+
+  // Get support connection modes for the given peer type and auth method
+  virtual void get_supported_con_modes(
+    int peer_type,
+    uint32_t auth_method,
+    std::vector<uint32_t> *modes) {
+    // auth_registry.get_supported_modes(peer_type, auth_method, modes);
+    *modes = { CEPH_CON_MODE_CRC };
+  }
+
+  // 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<uint32_t>& preferred_modes) {
+    // return auth_registry.pick_mode(peer_type, auth_method, preferred_modes);
+    ceph_assert(auth_method == CEPH_AUTH_NONE);
+    ceph_assert(preferred_modes.size() &&
+                preferred_modes[0] == CEPH_CON_MODE_CRC);
+    return CEPH_CON_MODE_CRC;
+  }
+
+  // return an AuthAuthorizeHandler for the given peer type and auth method
+  AuthAuthorizeHandler *get_auth_authorize_handler(
+    int peer_type,
+    int auth_method) {
+    // return auth_registry.get_handler(peer_type, auth_method);
+    return nullptr;
+  }
+
+  // Handle an authentication request on an incoming connection
+  virtual int handle_auth_request(
+    ceph::net::ConnectionRef conn,
+    AuthConnectionMetaRef auth_meta,
+    bool more,           //< true if this is not the first part of the handshake
+    uint32_t auth_method,
+    const bufferlist& bl,
+    bufferlist *reply) = 0;
+};
+
+} // namespace ceph::auth
diff --git a/src/crimson/auth/DummyAuth.h b/src/crimson/auth/DummyAuth.h
new file mode 100644 (file)
index 0000000..e6fc720
--- /dev/null
@@ -0,0 +1,67 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#include "AuthClient.h"
+#include "AuthServer.h"
+
+namespace ceph::auth {
+
+class DummyAuthClientServer : public AuthClient,
+                              public AuthServer {
+public:
+  DummyAuthClientServer() {}
+
+  // client
+  int get_auth_request(
+    ceph::net::ConnectionRef conn,
+    AuthConnectionMetaRef auth_meta,
+    uint32_t *method,
+    std::vector<uint32_t> *preferred_modes,
+    bufferlist *out) override {
+    *method = CEPH_AUTH_NONE;
+    *preferred_modes = { CEPH_CON_MODE_CRC };
+    return 0;
+  }
+
+  int handle_auth_reply_more(
+    ceph::net::ConnectionRef conn,
+    AuthConnectionMetaRef auth_meta,
+    const bufferlist& bl,
+    bufferlist *reply) override {
+    ceph_abort();
+  }
+
+  int handle_auth_done(
+    ceph::net::ConnectionRef conn,
+    AuthConnectionMetaRef auth_meta,
+    uint64_t global_id,
+    uint32_t con_mode,
+    const bufferlist& bl,
+    CryptoKey *session_key,
+    std::string *connection_secret) {
+    return 0;
+  }
+
+  int handle_auth_bad_method(
+    ceph::net::ConnectionRef conn,
+    AuthConnectionMetaRef auth_meta,
+    uint32_t old_auth_method,
+    int result,
+    const std::vector<uint32_t>& allowed_methods,
+    const std::vector<uint32_t>& allowed_modes) override {
+    ceph_abort();
+  }
+
+  // server
+  int handle_auth_request(
+    ceph::net::ConnectionRef conn,
+    AuthConnectionMetaRef auth_meta,
+    bool more,
+    uint32_t auth_method,
+    const bufferlist& bl,
+    bufferlist *reply) override {
+    return 1;
+  }
+};
+
+} // namespace ceph::auth
index e3a684e32f02a907cf80f9e9f0144c2309dacc5e..ed6037ca27356de8aaa687c78a92fc91cb5d1a35 100644 (file)
 
 class AuthAuthorizer;
 
+namespace ceph::auth {
+class AuthClient;
+class AuthServer;
+}
+
 namespace ceph::net {
 
 using Throttle = ceph::thread::Throttle;
@@ -33,6 +38,10 @@ class Messenger {
   uint32_t global_seq = 0;
   uint32_t crc_flags = 0;
 
+ public:
+  ceph::auth::AuthClient *auth_client = 0;
+  ceph::auth::AuthServer *auth_server = 0;
+
  public:
   Messenger(const entity_name_t& name)
     : my_name(name)
@@ -88,6 +97,13 @@ class Messenger {
     crc_flags |= MSG_CRC_HEADER;
   }
 
+  void set_auth_client(ceph::auth::AuthClient *ac) {
+    auth_client = ac;
+  }
+  void set_auth_server(ceph::auth::AuthServer *as) {
+    auth_server = as;
+  }
+
   // get the local messenger shard if it is accessed by another core
   virtual Messenger* get_local_shard() {
     return this;
index 94919fc8cabb74c1237231ba30cc2dc96b65fab8..40b90e4083521aafa765fd0846bb96d2d1079699 100644 (file)
@@ -5,6 +5,9 @@
 
 #include "include/msgr.h"
 
+#include "crimson/auth/AuthClient.h"
+#include "crimson/auth/AuthServer.h"
+
 #include "Dispatcher.h"
 #include "Errors.h"
 #include "Socket.h"
index e5f0218b90702bfdf4ccb970f9657cc8ebcf57d6..bcec1a8455cf1722ca754c74969e290933f16202 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "auth/Auth.h"
 #include "messages/MPing.h"
+#include "crimson/auth/DummyAuth.h"
 #include "crimson/net/Connection.h"
 #include "crimson/net/Dispatcher.h"
 #include "crimson/net/Messenger.h"
@@ -37,6 +38,7 @@ struct DummyAuthAuthorizer : public AuthAuthorizer {
 struct Server {
   ceph::thread::Throttle byte_throttler;
   ceph::net::Messenger& msgr;
+  ceph::auth::DummyAuthClientServer dummy_auth;
   struct ServerDispatcher : ceph::net::Dispatcher {
     unsigned count = 0;
     seastar::condition_variable on_reply;
@@ -73,6 +75,7 @@ struct Server {
 struct Client {
   ceph::thread::Throttle byte_throttler;
   ceph::net::Messenger& msgr;
+  ceph::auth::DummyAuthClientServer dummy_auth;
   struct ClientDispatcher : ceph::net::Dispatcher {
     unsigned count = 0;
     seastar::condition_variable on_reply;
@@ -161,6 +164,8 @@ seastar_echo(const entity_addr_t addr, echo_role role, unsigned count)
             // bind the server
             server.msgr.set_policy_throttler(entity_name_t::TYPE_OSD,
                                              &server.byte_throttler);
+            server.msgr.set_auth_client(&server.dummy_auth);
+            server.msgr.set_auth_server(&server.dummy_auth);
             return server.msgr.bind(entity_addrvec_t{addr})
               .then([&server] {
                 return server.msgr.start(&server.dispatcher);
@@ -183,6 +188,8 @@ seastar_echo(const entity_addr_t addr, echo_role role, unsigned count)
             std::cout << "client sending to " << addr << std::endl;
             client.msgr.set_policy_throttler(entity_name_t::TYPE_OSD,
                                              &client.byte_throttler);
+            client.msgr.set_auth_client(&client.dummy_auth);
+            client.msgr.set_auth_server(&client.dummy_auth);
             return client.msgr.start(&client.dispatcher)
               .then([addr, &client] {
                 return client.msgr.connect(addr, entity_name_t::TYPE_OSD);