Skip to content

Commit 37144d5

Browse files
committed
WL#15135 patch #4: Configure TLS in API and MySQL nodes
Part of WL#15135 Certificate Architecture In Ndb_cluster_connection, this patch provides a new top-level method configure_tls(). It also implements TLS initialization in connect(), calling down through the TransporterFacade layer to TransporterRegistry. In the MySQL server this adds the new read-only configuration option ndb-tls-search-path, with a compile-time default that is configurable in CMake, WITH_NDB_TLS_SEARCH_PATH. Unmodified API nodes that do not call into configure_tls() will still be able to make TLS connections if keys are found somewhere in the default search path. Change-Id: Id1d046ff3c5a48a30131c3d15274f5ed625933a9
1 parent a96f9f4 commit 37144d5

13 files changed

+102
-1
lines changed

mysql-test/suite/ndb/r/ndb_basic.result

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ ndb_show_foreign_key_mock_tables #
203203
ndb_slave_conflict_role #
204204
ndb_table_no_logging #
205205
ndb_table_temporary #
206+
ndb_tls_search_path #
206207
ndb_use_copying_alter_table #
207208
ndb_use_exact_count #
208209
ndb_use_transactions #

mysql-test/suite/ndb/r/ndb_basic_3rpl.result

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ ndb_show_foreign_key_mock_tables #
203203
ndb_slave_conflict_role #
204204
ndb_table_no_logging #
205205
ndb_table_temporary #
206+
ndb_tls_search_path #
206207
ndb_use_copying_alter_table #
207208
ndb_use_exact_count #
208209
ndb_use_transactions #

mysql-test/suite/ndb/r/ndb_basic_4rpl.result

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ ndb_show_foreign_key_mock_tables #
203203
ndb_slave_conflict_role #
204204
ndb_table_no_logging #
205205
ndb_table_temporary #
206+
ndb_tls_search_path #
206207
ndb_use_copying_alter_table #
207208
ndb_use_exact_count #
208209
ndb_use_transactions #

mysql-test/suite/ndb/r/ndb_basic_ndbd.result

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ ndb_show_foreign_key_mock_tables #
203203
ndb_slave_conflict_role #
204204
ndb_table_no_logging #
205205
ndb_table_temporary #
206+
ndb_tls_search_path #
206207
ndb_use_copying_alter_table #
207208
ndb_use_exact_count #
208209
ndb_use_transactions #

storage/ndb/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ IF(NOT WITHOUT_SERVER)
3838
SET(WITH_NDBCLUSTER_STORAGE_ENGINE 0)
3939
ENDIF()
4040
ENDIF()
41+
42+
IF(WIN32)
43+
SET(DEFAULT_TLS_SEARCH_PATH "$HOMEPATH/ndb-tls")
44+
ELSE()
45+
SET(DEFAULT_TLS_SEARCH_PATH "$HOME/ndb-tls")
46+
ENDIF()
47+
SET(WITH_NDB_TLS_SEARCH_PATH ${DEFAULT_TLS_SEARCH_PATH}
48+
CACHE STRING "Search path for TLS keys and certificates")
49+
4150
#
4251
# Add the ndbcluster plugin
4352
#
@@ -123,6 +132,10 @@ IF(NOT WITHOUT_SERVER)
123132
DEFAULT STATIC_ONLY
124133
LINK_LIBRARIES ndbclient_static extra::rapidjson)
125134

135+
SET_PROPERTY(SOURCE plugin/ha_ndbcluster.cc
136+
PROPERTY COMPILE_DEFINITIONS
137+
NDB_TLS_SEARCH_PATH="${WITH_NDB_TLS_SEARCH_PATH}")
138+
126139
# Sanity check that MYSQL_ADD_PLUGIN didn't decide to skip build
127140
IF (NOT WITH_NDBCLUSTER_STORAGE_ENGINE)
128141
IF(WITH_NDB)

storage/ndb/include/ndbapi/ndb_cluster_connection.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,26 @@ class Ndb_cluster_connection {
108108
*/
109109
void set_name(const char *name);
110110

111+
/**
112+
* Configure TLS for the connection.
113+
*
114+
* tls_search_path is a colon-delimited list of directories that may contain
115+
* TLS private key files or signed public key certificates. The search path
116+
* may contain absolute directories, relative directories, and environment
117+
* variables which will be expanded.
118+
*
119+
* The second (int) parameter will be introduced in WL#15524.
120+
*
121+
* If the node finds active NDB TLS node keys and certificates in the seach
122+
* path, it will be able to connect securely to other nodes. These keys and
123+
* certificates can be created using the ndb_sign_keys tool.
124+
*
125+
* If configure_tls() is not called for a connection, the search path used
126+
* will be the compile-time default NDB_TLS_SEARCH_PATH.
127+
128+
*/
129+
void configure_tls(const char * tls_search_path, int);
130+
111131
/**
112132
* For each Ndb_cluster_connection, NDB publishes a URI in the ndbinfo
113133
* processes table. A user may customize this URI using set_service_uri().

storage/ndb/plugin/ha_ndbcluster.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ static ulong opt_ndb_data_node_neighbour;
145145
static bool opt_ndb_fully_replicated;
146146
static ulong opt_ndb_row_checksum;
147147

148+
char *opt_ndb_tls_search_path;
149+
148150
// The version where ndbcluster uses DYNAMIC by default when creating columns
149151
static const ulong NDB_VERSION_DYNAMIC_IS_DEFAULT = 50711;
150152
enum ndb_default_colum_format_enum {
@@ -17606,6 +17608,12 @@ static MYSQL_SYSVAR_STR(
1760617608
nullptr /* default */
1760717609
);
1760817610

17611+
static MYSQL_SYSVAR_STR(tls_search_path, /* name */
17612+
opt_ndb_tls_search_path, /* var */
17613+
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
17614+
"Directory containing NDB Cluster TLS Private Keys",
17615+
NULL, NULL, NDB_TLS_SEARCH_PATH);
17616+
1760917617
static const int MIN_ACTIVATION_THRESHOLD = 0;
1761017618
static const int MAX_ACTIVATION_THRESHOLD = 16;
1761117619

@@ -18442,6 +18450,7 @@ static SYS_VAR *system_variables[] = {
1844218450
MYSQL_SYSVAR(optimization_delay),
1844318451
MYSQL_SYSVAR(index_stat_enable),
1844418452
MYSQL_SYSVAR(index_stat_option),
18453+
MYSQL_SYSVAR(tls_search_path),
1844518454
MYSQL_SYSVAR(table_no_logging),
1844618455
MYSQL_SYSVAR(table_temporary),
1844718456
MYSQL_SYSVAR(log_bin),

storage/ndb/plugin/ha_ndbcluster_connection.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ static uint g_pool_alloc = 0;
5959
static uint g_pool_pos = 0;
6060
static mysql_mutex_t g_pool_mutex;
6161

62+
extern char *opt_ndb_tls_search_path;
63+
6264
/**
6365
@brief Parse the --ndb-cluster-connection-pool-nodeids=nodeid[,nodeidN]
6466
comma separated list of nodeids to use for the pool
@@ -245,6 +247,7 @@ int ndbcluster_connect(ulong wait_connected, // Timeout in seconds
245247
char buf[128];
246248
snprintf(buf, sizeof(buf), "mysqld --server-id=%lu", server_id);
247249
g_ndb_cluster_connection->set_name(buf);
250+
g_ndb_cluster_connection->configure_tls(opt_ndb_tls_search_path, 0);
248251
snprintf(buf, sizeof(buf), "%s%s", processinfo_path, server_id_string);
249252
g_ndb_cluster_connection->set_service_uri("mysql", processinfo_host,
250253
processinfo_port, buf);
@@ -306,6 +309,7 @@ int ndbcluster_connect(ulong wait_connected, // Timeout in seconds
306309
snprintf(buf, sizeof(buf), "mysqld --server-id=%lu (connection %u)",
307310
server_id, i + 1);
308311
g_pool[i]->set_name(buf);
312+
g_pool[i]->configure_tls(opt_ndb_tls_search_path, 0);
309313
const char *uri_sep = server_id ? ";" : "?";
310314
snprintf(buf, sizeof(buf), "%s%s%sconnection=%u", processinfo_path,
311315
server_id_string, uri_sep, i + 1);

storage/ndb/src/ndbapi/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,8 @@ ADD_CONVENIENCE_LIBRARY(ndbapi
7878
LINK_LIBRARIES ext::zlib
7979
)
8080

81+
SET_PROPERTY(SOURCE TransporterFacade.cpp
82+
PROPERTY COMPILE_DEFINITIONS
83+
NDB_TLS_SEARCH_PATH="${WITH_NDB_TLS_SEARCH_PATH}")
8184

8285
NDB_ADD_TEST(SectionIterators-t SectionIterators.cpp NdbApiSignal.cpp)

storage/ndb/src/ndbapi/TransporterFacade.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,10 @@ TransporterFacade::start_instance(NodeId nodeId,
522522
DBUG_RETURN(-1);
523523
}
524524

525+
theTransporterRegistry->init_tls(m_tls_search_path,
526+
m_tls_node_type,
527+
m_tls_primary_api);
528+
525529
if (theClusterMgr == nullptr)
526530
{
527531
theClusterMgr = new ClusterMgr(*this);
@@ -1666,7 +1670,10 @@ TransporterFacade::TransporterFacade(GlobalDictCache *cache) :
16661670
m_send_thread_mutex(nullptr),
16671671
m_send_thread_cond(nullptr),
16681672
m_send_thread_nodes(),
1669-
m_has_data_nodes()
1673+
m_has_data_nodes(),
1674+
m_tls_search_path(NDB_TLS_SEARCH_PATH),
1675+
m_tls_node_type(NODE_TYPE_API),
1676+
m_tls_primary_api(true)
16701677
{
16711678
DBUG_ENTER("TransporterFacade::TransporterFacade");
16721679
thePollMutex = NdbMutex_CreateWithName("PollMutex");
@@ -1768,6 +1775,16 @@ TransporterFacade::set_up_node_active_in_send_buffers(Uint32 nodeId,
17681775
DBUG_VOID_RETURN;
17691776
}
17701777

1778+
void
1779+
TransporterFacade::configure_tls(const char * searchPath,
1780+
int nodeType, bool isPrimary)
1781+
{
1782+
assert(searchPath);
1783+
m_tls_search_path = searchPath;
1784+
m_tls_node_type = nodeType;
1785+
m_tls_primary_api = isPrimary;
1786+
}
1787+
17711788
bool
17721789
TransporterFacade::configure(NodeId nodeId,
17731790
const ndb_mgm_configuration* conf)

storage/ndb/src/ndbapi/TransporterFacade.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ 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)
78+
{
79+
configure_tls(searchPath, NODE_TYPE_API, primary);
80+
}
81+
7682
/*
7783
(Re)configure the TransporterFacade
7884
to a specific configuration
@@ -596,6 +602,11 @@ class TransporterFacade :
596602
* of sending to these nodes.
597603
*/
598604
NodeBitmask m_has_data_nodes;
605+
606+
/* TLS Configuration */
607+
const char * m_tls_search_path;
608+
int m_tls_node_type;
609+
bool m_tls_primary_api;
599610
};
600611

601612
inline

storage/ndb/src/ndbapi/ndb_cluster_connection.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,9 @@ Ndb_cluster_connection_impl::~Ndb_cluster_connection_impl()
615615
m_nodes_proximity_mutex = nullptr;
616616
}
617617

618+
free(const_cast<char *>(m_tls_search_path));
619+
m_tls_search_path = nullptr;
620+
618621
if (m_event_add_drop_mutex)
619622
NdbMutex_Destroy(m_event_add_drop_mutex);
620623
m_event_add_drop_mutex = nullptr;
@@ -938,6 +941,14 @@ Ndb_cluster_connection_impl::set_data_node_neighbour(Uint32 node)
938941
NdbMutex_Unlock(m_nodes_proximity_mutex);
939942
}
940943

944+
void
945+
Ndb_cluster_connection_impl::configure_tls(const char * searchPath)
946+
{
947+
bool isPrimary = ! (bool) m_main_connection;
948+
m_tls_search_path = strdup(searchPath);
949+
m_transporter_facade->api_configure_tls(m_tls_search_path, isPrimary);
950+
}
951+
941952
void
942953
Ndb_cluster_connection_impl::set_name(const char *name)
943954
{
@@ -1390,6 +1401,11 @@ Ndb_cluster_connection_impl::do_test()
13901401
delete[] nodes;
13911402
}
13921403

1404+
void Ndb_cluster_connection::configure_tls(const char * searchPath, int)
1405+
{
1406+
m_impl.configure_tls(searchPath);
1407+
}
1408+
13931409
void Ndb_cluster_connection::set_data_node_neighbour(Uint32 node)
13941410
{
13951411
m_impl.set_data_node_neighbour(node);

storage/ndb/src/ndbapi/ndb_cluster_connection_impl.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ class Ndb_cluster_connection_impl : public Ndb_cluster_connection
134134
int configure(Uint32 nodeid, const ndb_mgm_configuration *config);
135135
void connect_thread();
136136
void set_name(const char *name);
137+
void configure_tls(const char * search_path);
137138
int set_service_uri(const char *, const char *, int, const char *);
138139
void set_data_node_neighbour(Uint32 neighbour_node);
139140
void adjust_node_proximity(Uint32 node_id, Int32 adjustment);
@@ -208,6 +209,9 @@ class Ndb_cluster_connection_impl : public Ndb_cluster_connection
208209

209210
// Config generation of used configuration
210211
Uint32 m_config_generation{0};
212+
213+
// TLS Certificate Search Path
214+
const char * m_tls_search_path {nullptr};
211215
};
212216

213217
#endif

0 commit comments

Comments
 (0)