Skip to content

Commit 9b06a30

Browse files
committed
WL#15524 Patch #11 Use MGM TLS in TransporterRegistry and MgmtSrvr
TransporterRegistry and MgmtSrvr both open some MGM connections to management servers. Use MGM TLS for these, and extend the init_tls() method to add the MGM TLS requirement level. Change-Id: Iea6d776eeb676bd979267b03461bf62d59ca25b1
1 parent 85152cc commit 9b06a30

File tree

8 files changed

+40
-16
lines changed

8 files changed

+40
-16
lines changed

storage/ndb/include/transporter/TransporterRegistry.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ class TransporterRegistry
238238
* Initialize TLS context. Cannot be called prior to init(NodeId).
239239
* Returns true on success.
240240
*/
241-
bool init_tls(const char * search_path, int node_type, bool is_primary);
241+
bool init_tls(const char * search_path, int node_type,
242+
bool is_primary, int mgm_tls_requirement_level);
242243

243244
/**
244245
Perform handshaking of a client connection to accept it
@@ -572,6 +573,7 @@ class TransporterRegistry
572573
Uint32 nTCPTransporters;
573574
Uint32 nSHMTransporters;
574575
TlsKeyManager m_tls_keys;
576+
int m_mgm_tls_req;
575577

576578
#ifdef ERROR_INSERT
577579
NodeBitmask m_blocked;

storage/ndb/src/common/transporter/TransporterRegistry.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,10 +514,11 @@ TransporterRegistry::init(TransporterReceiveHandle& recvhandle)
514514

515515
bool
516516
TransporterRegistry::init_tls(const char * searchPath, int nodeType,
517-
bool isPrimary)
517+
bool isPrimary, int mgmReqLevel)
518518
{
519519
require(localNodeId);
520520
m_tls_keys.init(searchPath, localNodeId, nodeType, isPrimary);
521+
m_mgm_tls_req = mgmReqLevel;
521522
return m_tls_keys.ctx();
522523
}
523524

@@ -3433,8 +3434,11 @@ TransporterRegistry::start_clients_thread()
34333434
"dynamic port",
34343435
nodeId));
34353436

3436-
if(!ndb_mgm_is_connected(m_mgm_handle))
3437-
ndb_mgm_connect(m_mgm_handle, 0, 0, 0);
3437+
if(! ndb_mgm_is_connected(m_mgm_handle))
3438+
{
3439+
ndb_mgm_set_ssl_ctx(m_mgm_handle, m_tls_keys.ctx());
3440+
ndb_mgm_connect_tls(m_mgm_handle, 0, 0, 0, m_mgm_tls_req);
3441+
}
34383442

34393443
if(ndb_mgm_is_connected(m_mgm_handle))
34403444
{

storage/ndb/src/kernel/ndbd.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,8 @@ ndbd_run(bool foreground, int report_fd,
11721172

11731173
theConfig->setupConfiguration();
11741174

1175-
globalTransporterRegistry.init_tls(tls_search_path, NODE_TYPE_DB, true);
1175+
globalTransporterRegistry.init_tls(tls_search_path, NODE_TYPE_DB, true,
1176+
opt_mgm_tls);
11761177

11771178
const ndb_mgm_configuration_iterator *p =
11781179
globalEmulatorData.theConfiguration->getOwnConfigIterator();

storage/ndb/src/mgmsrv/MgmtSrvr.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ MgmtSrvr::start()
592592

593593
/* Configure TlsKeyManager */
594594
require(m_tls_search_path);
595-
theFacade->mgm_configure_tls(m_tls_search_path);
595+
theFacade->mgm_configure_tls(m_tls_search_path, m_client_tls_req);
596596

597597
/* Start transporter */
598598
if(!start_transporter(m_local_config))
@@ -1330,7 +1330,8 @@ int MgmtSrvr::sendStopMgmd(NodeId nodeId,
13301330
if ( h && connect_string.length() > 0 )
13311331
{
13321332
ndb_mgm_set_connectstring(h,connect_string.c_str());
1333-
if(ndb_mgm_connect(h,1,0,0))
1333+
ndb_mgm_set_ssl_ctx(h, ssl_ctx());
1334+
if(ndb_mgm_connect_tls(h,1,0,0, m_client_tls_req))
13341335
{
13351336
DBUG_PRINT("info",("failed ndb_mgm_connect"));
13361337
ndb_mgm_destroy_handle(&h);
@@ -5186,7 +5187,8 @@ bool MgmtSrvr::connect_to_self()
51865187
m_port);
51875188
ndb_mgm_set_connectstring(mgm_handle, buf.c_str());
51885189

5189-
if(ndb_mgm_connect(mgm_handle, 0, 0, 0) < 0)
5190+
ndb_mgm_set_ssl_ctx(mgm_handle, ssl_ctx());
5191+
if(ndb_mgm_connect_tls(mgm_handle, 0, 0, 0, m_client_tls_req) < 0)
51905192
{
51915193
g_eventLogger->warning("%d %s",
51925194
ndb_mgm_get_latest_error(mgm_handle),

storage/ndb/src/mgmsrv/MgmtSrvr.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,10 @@ class MgmtSrvr : private ConfigSubscriber, public trp_client {
463463
bool m_require_tls { false }; // ... and as MGM server.
464464
bool m_require_cert { false };
465465

466+
struct ssl_ctx_st * ssl_ctx() {
467+
return theFacade->get_registry()->getTlsKeyManager()->ctx();
468+
}
469+
466470
bool m_need_restart;
467471

468472
ndb_sockaddr m_connect_address[MAX_NODES];

storage/ndb/src/ndbapi/TransporterFacade.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,8 @@ TransporterFacade::start_instance(NodeId nodeId,
524524

525525
theTransporterRegistry->init_tls(m_tls_search_path,
526526
m_tls_node_type,
527-
m_tls_primary_api);
527+
m_tls_primary_api,
528+
m_mgm_tls_level);
528529

529530
if (theClusterMgr == nullptr)
530531
{
@@ -1777,12 +1778,14 @@ TransporterFacade::set_up_node_active_in_send_buffers(Uint32 nodeId,
17771778

17781779
void
17791780
TransporterFacade::configure_tls(const char * searchPath,
1780-
int nodeType, bool isPrimary)
1781+
int nodeType, bool isPrimary,
1782+
int mgmTlsRequirement)
17811783
{
17821784
assert(searchPath);
17831785
m_tls_search_path = searchPath;
17841786
m_tls_node_type = nodeType;
17851787
m_tls_primary_api = isPrimary;
1788+
m_mgm_tls_level = mgmTlsRequirement;
17861789
}
17871790

17881791
bool

storage/ndb/src/ndbapi/TransporterFacade.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ class TransporterFacade :
7373
int start_instance(NodeId, const ndb_mgm_configuration*);
7474
void stop_instance();
7575

76-
void configure_tls(const char *, int type, bool primary);
77-
void api_configure_tls(const char * searchPath, bool primary)
76+
void configure_tls(const char *, int type, bool primary, int mgmLevel);
77+
void api_configure_tls(const char * searchPath, bool primary, int mgmLevel)
7878
{
79-
configure_tls(searchPath, NODE_TYPE_API, primary);
79+
configure_tls(searchPath, NODE_TYPE_API, primary, mgmLevel);
8080
}
81-
void mgm_configure_tls(const char * searchPath)
81+
void mgm_configure_tls(const char * searchPath, int mgmLevel)
8282
{
83-
configure_tls(searchPath, NODE_TYPE_MGM, true);
83+
configure_tls(searchPath, NODE_TYPE_MGM, true, mgmLevel);
8484
}
8585

8686
/*
@@ -611,6 +611,7 @@ class TransporterFacade :
611611
const char * m_tls_search_path;
612612
int m_tls_node_type;
613613
bool m_tls_primary_api;
614+
int m_mgm_tls_level;
614615
};
615616

616617
inline

storage/ndb/src/ndbapi/ndb_cluster_connection.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,14 @@ Ndb_cluster_connection_impl::configure_tls(const char * searchPath)
946946
{
947947
bool isPrimary = ! (bool) m_main_connection;
948948
m_tls_search_path = strdup(searchPath);
949-
m_transporter_facade->api_configure_tls(m_tls_search_path, isPrimary);
949+
950+
/* A later patch will make mgm_level configurable */
951+
static constexpr int mgm_level = CLIENT_TLS_RELAXED;
952+
953+
m_config_retriever->init_mgm_tls(m_tls_search_path, ::Node::Type::Client,
954+
mgm_level);
955+
m_transporter_facade->api_configure_tls(m_tls_search_path, isPrimary,
956+
mgm_level);
950957
}
951958

952959
void

0 commit comments

Comments
 (0)