Skip to content

Commit b891235

Browse files
committed
Bug#35746330 MGMD accept connections before checking its own required certificates
Description: A MGMD process can be configured to require valid certificates when starting with configuration parameter [MGM]RequireCertificate=1. Currently verification happens after listening ports are setup for both mgm-connections and transporters. Test `testMgmd -n MgmdWithoutCertificate` fails since client manage to connect to MGMD before MGMD is shutting down due to no certificates were detected. How To Repeat: Run for example `./mtr ndb.test_mgmd` or `testMgmd -n MgmdWithoutCertificate` Fix: Certificate validation, if required, is done before accepting any connections (both mgm-protocol and transporters). First read the relevant configuration before starting either transporters or mgm-service ports. Then also make sure that start_transporters propagate the require certificate flag such that certificate checks are done first if needed. Change-Id: I5995fc8fb34539ff00fd628be5404d26bf2c00b5
1 parent 784fe79 commit b891235

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

storage/ndb/src/mgmsrv/MgmtSrvr.cpp

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,19 @@ MgmtSrvr::start_transporter(const Config* config)
435435
*/
436436
m_config_manager->set_facade(theFacade);
437437

438-
if (theFacade->start_instance(_ownNodeId,
439-
config->m_configuration) < 0)
438+
int r = theFacade->start_instance(_ownNodeId,
439+
config->m_configuration,
440+
require_cert());
441+
if (r < 0)
440442
{
441-
g_eventLogger->error("Failed to start transporter");
443+
if (r == -2)
444+
{
445+
g_eventLogger->error("This node does not have a valid TLS certificate.");
446+
}
447+
else
448+
{
449+
g_eventLogger->error("Failed to start transporter");
450+
}
442451
delete theFacade;
443452
theFacade = 0;
444453
DBUG_RETURN(false);
@@ -461,9 +470,9 @@ MgmtSrvr::start_transporter(const Config* config)
461470

462471

463472
bool
464-
MgmtSrvr::start_mgm_service(const Config* config)
473+
MgmtSrvr::get_connection_config(const Config* config)
465474
{
466-
DBUG_ENTER("MgmtSrvr::start_mgm_service");
475+
DBUG_ENTER("MgmtSrvr::get_connection_config");
467476

468477
assert(m_port == 0);
469478
{
@@ -500,6 +509,13 @@ MgmtSrvr::start_mgm_service(const Config* config)
500509
m_require_tls = requireTls;
501510
m_require_cert = requireCert;
502511
}
512+
DBUG_RETURN(true);
513+
}
514+
515+
bool
516+
MgmtSrvr::start_mgm_service(const Config* config)
517+
{
518+
DBUG_ENTER("MgmtSrvr::start_mgm_service");
503519

504520
unsigned short port= m_port;
505521
DBUG_PRINT("info", ("Using port %d", port));
@@ -593,6 +609,12 @@ MgmtSrvr::start()
593609
require(m_tls_search_path);
594610
theFacade->mgm_configure_tls(m_tls_search_path, m_client_tls_req);
595611

612+
if (!get_connection_config(m_local_config))
613+
{
614+
g_eventLogger->error( "Shutting down. Failed read config.");
615+
DBUG_RETURN(false);
616+
}
617+
596618
/* Start transporter */
597619
if(!start_transporter(m_local_config))
598620
{
@@ -607,15 +629,6 @@ MgmtSrvr::start()
607629
DBUG_RETURN(false);
608630
}
609631

610-
/* Check for required TLS certificate */
611-
ssl_ctx_st * ctx = theFacade->get_registry()->getTlsKeyManager()->ctx();
612-
if(require_cert() && ! ctx)
613-
{
614-
g_eventLogger->error(
615-
"Shutting down. This node does not have a valid TLS certificate.");
616-
DBUG_RETURN(false);
617-
}
618-
619632
g_eventLogger->info(require_tls() ?
620633
"This server will require all MGM clients to use TLS" :
621634
"Not requiring TLS");

storage/ndb/src/mgmsrv/MgmtSrvr.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class MgmtSrvr : private ConfigSubscriber, public trp_client {
150150
private:
151151
/* Functions used from 'start' */
152152
bool start_transporter(const Config*);
153+
bool get_connection_config(const Config*);
153154
bool start_mgm_service(const Config*);
154155
bool connect_to_self(void);
155156

0 commit comments

Comments
 (0)