Skip to content

Commit a5d5fd0

Browse files
committed
WL#15524 patch #13 ndb_waiter and new MTR tests
As a prerequisite for MTR testing, add support for the --ndb-tls-search-path and --ndb-mgm-tls options in ndb_waiter. A new MTR test require_mgm_tls demonstrates that cluster can run with [MGM]RequireTls=1 and --ndb-mgm-tls=strict A new MTR test api_require_trp demonstrates that an API node (ndb_desc) fails to connect to cluster when it does not have a certificate, but some data node requires TLS. Change-Id: I50595a7d9d2bbb8bb3a47d7640017a4101c41a30
1 parent a580ad7 commit a5d5fd0

File tree

7 files changed

+123
-3
lines changed

7 files changed

+123
-3
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
!include suite/ndbcluster/my.cnf
2+
3+
[cluster_config.ndbd.1.1]
4+
RequireTls=On
5+
6+
[cluster_config.ndbd.2.1]
7+
RequireTls=On
8+
9+
# In this test, ndb_desc does *not* have a certificate available
10+
11+
[ndbd.1.1]
12+
ndb-tls-search-path=$MYSQLTEST_VARDIR/std_data/ndb-tls/active
13+
14+
[ndbd.2.1]
15+
ndb-tls-search-path=$MYSQLTEST_VARDIR/std_data/ndb-tls/active
16+
17+
[mysqld.1.1]
18+
ndb-tls-search-path=$MYSQLTEST_VARDIR/std_data/ndb-tls/active
19+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
SELECT 1;
2+
1
3+
1
4+
Unable to connect to management server.
5+
6+
NDBT_ProgramExit: 1 - Failed
7+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--source include/have_ndb.inc
2+
3+
# Transporter TLS is required, but ndb_desc does not have a certificate
4+
5+
# The server is up
6+
#
7+
SELECT 1;
8+
9+
# ndb_desc fails without TLS
10+
--replace_regex /^.*--//
11+
--error 1
12+
--exec $NDB_DESC --connect-retries=0
13+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
!include suite/ndb_tls/my.cnf
2+
3+
[cluster_config.ndb_mgmd.1.1]
4+
RequireTls=true
5+
6+
# In this test, ndb_desc does *not* have a certificate available
7+
8+
# MTR stops cluster using ndb_mgm, but with no group suffix:
9+
[ndb_mgm]
10+
ndb-tls-search-path=$MYSQLTEST_VARDIR/std_data/ndb-tls/active
11+
12+
# MTR internally uses ndb_waiter:
13+
[ndb_waiter.1]
14+
ndb-tls-search-path=$MYSQLTEST_VARDIR/std_data/ndb-tls/active
15+
16+
[ndbd.1.1]
17+
ndb-tls-search-path=$MYSQLTEST_VARDIR/std_data/ndb-tls/active
18+
19+
[ndbd.2.1]
20+
ndb-tls-search-path=$MYSQLTEST_VARDIR/std_data/ndb-tls/active
21+
22+
[ndb_mgmd.1.1]
23+
ndb-tls-search-path=$MYSQLTEST_VARDIR/std_data/ndb-tls/active
24+
25+
[mysqld.1.1]
26+
ndb-tls-search-path=$MYSQLTEST_VARDIR/std_data/ndb-tls/active
27+
ndb-cluster-connection-pool=2
28+
ndb-cluster-connection-pool-nodeids=51,52
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
SELECT 1;
2+
1
3+
1
4+
SELECT node_id, remote_node_id, encrypted from ndbinfo.transporters
5+
WHERE status = 'CONNECTED' ORDER BY node_id, remote_node_id;
6+
node_id remote_node_id encrypted
7+
1 2 0
8+
1 3 1
9+
1 51 0
10+
1 52 0
11+
2 1 0
12+
2 3 1
13+
2 51 0
14+
2 52 0
15+
Configuration error: Not Authorized: TLS Required: Executing: ndb_mgm_alloc_nodeid
16+
Unable to connect to management server.
17+
18+
NDBT_ProgramExit: 1 - Failed
19+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--source include/have_ndb.inc
2+
3+
# Require MGM TLS, but not transporter TLS
4+
5+
# The server is up
6+
#
7+
SELECT 1;
8+
9+
## Expect 2 encrypted links
10+
SELECT node_id, remote_node_id, encrypted from ndbinfo.transporters
11+
WHERE status = 'CONNECTED' ORDER BY node_id, remote_node_id;
12+
13+
# ndb_desc fails without TLS
14+
--replace_regex /^.*--//
15+
--error 1
16+
--exec $NDB_DESC --connect-retries=0
17+

storage/ndb/tools/waiter.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#include <NdbTick.h>
3434
#include <portlib/ndb_localtime.h>
3535

36+
#include "util/TlsKeyManager.hpp"
37+
3638
#include <NdbToolsProgramExitCodes.hpp>
3739

3840
#include <kernel/NodeBitmask.hpp>
@@ -50,6 +52,8 @@ static const char* _wait_nodes = 0;
5052
static const char* _nowait_nodes = 0;
5153
static NdbNodeBitmask nowait_nodes_bitmask;
5254

55+
static TlsKeyManager tlsKeyManager;
56+
5357
static struct my_option my_long_options[] =
5458
{
5559
NdbStdOpt::usage,
@@ -60,6 +64,8 @@ static struct my_option my_long_options[] =
6064
NdbStdOpt::connectstring,
6165
NdbStdOpt::connect_retry_delay,
6266
NdbStdOpt::connect_retries,
67+
NdbStdOpt::tls_search_path,
68+
NdbStdOpt::mgm_tls,
6369
NDB_STD_OPT_DEBUG
6470
{ "no-contact", 'n', "Wait for cluster no contact",
6571
&_no_contact, nullptr, nullptr, GET_BOOL, NO_ARG,
@@ -93,7 +99,8 @@ void catch_signal(int signum)
9399

94100
int main(int argc, char** argv){
95101
NDB_INIT(argv[0]);
96-
Ndb_opts opts(argc, argv, my_long_options);
102+
const char * groups[] = {"mysql_cluster", "ndb_waiter", nullptr};
103+
Ndb_opts opts(argc, argv, my_long_options, groups);
97104

98105
#ifndef NDEBUG
99106
opt_debug= "d:t:O,/tmp/ndb_waiter.trace";
@@ -173,6 +180,10 @@ int main(int argc, char** argv){
173180
nowait_nodes_bitmask.bitNOT();
174181
}
175182

183+
tlsKeyManager.init_mgm_client(opt_tls_search_path);
184+
if(tlsKeyManager.ctx())
185+
ndbout_c("Using TLS.");
186+
176187
if (waitClusterStatus(connect_string, wait_status) != 0)
177188
return NdbToolsProgramExitCode::FAILED;
178189

@@ -203,7 +214,9 @@ getStatus(){
203214
MGMERR(handle);
204215
retries++;
205216
ndb_mgm_disconnect(handle);
206-
if (ndb_mgm_connect(handle, opt_connect_retries - 1, opt_connect_retry_delay, 1)) {
217+
if (ndb_mgm_connect_tls(handle,
218+
opt_connect_retries - 1, opt_connect_retry_delay,
219+
1, opt_mgm_tls)) {
207220
MGMERR(handle);
208221
ndberr << "Reconnect failed" << endl;
209222
break;
@@ -302,10 +315,14 @@ waitClusterStatus(const char* _addr,
302315
}
303316
return -1;
304317
}
318+
ndb_mgm_set_ssl_ctx(handle, tlsKeyManager.ctx());
319+
305320
char buf[1024];
306321
ndbout << "Connecting to management server at "
307322
<< ndb_mgm_get_connectstring(handle, buf, sizeof(buf)) << endl;
308-
if (ndb_mgm_connect(handle, opt_connect_retries - 1, opt_connect_retry_delay, 1)) {
323+
if (ndb_mgm_connect_tls(handle,
324+
opt_connect_retries - 1, opt_connect_retry_delay, 1,
325+
opt_mgm_tls)) {
309326
MGMERR(handle);
310327
ndberr << "Connection to "
311328
<< ndb_mgm_get_connectstring(handle, buf, sizeof(buf)) << " failed"

0 commit comments

Comments
 (0)