Skip to content

Commit 6576ab9

Browse files
committed
WL#15154 patch #4 Transporter configuration
In class Transporter, add two new member variables: m_require_tls is a boolean TLS requirement m_encrypted is true only when TLS is actually in use A corresponding change in struct TransporterConfiguration also adds authMode. Some application logic is added in IPConfig.cpp to configure the new variables. On the server side, TransporterRegistry always uses a TLS authenticator. On the client side, all Transporter clients initialize a SocketAuthSimple authenticator, but then TCP Transporter clients delete this in the TCP_Transporter constructor and replace it with a TLS authenticator. Change-Id: I6392eecfc712f8a8f500697f34324eea01d29a8c
1 parent 7c83065 commit 6576ab9

File tree

7 files changed

+51
-10
lines changed

7 files changed

+51
-10
lines changed

storage/ndb/include/transporter/TransporterDefinitions.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <ndb_global.h>
2929
#include <kernel_types.h>
3030
#include <NdbOut.hpp>
31+
#include "SocketAuthenticator.hpp" // TlsAuth
3132

3233
/**
3334
* The sendbuffer limit after which the contents of the buffer is sent
@@ -92,6 +93,7 @@ struct TransporterConfiguration {
9293
NodeId remoteNodeId;
9394
NodeId localNodeId;
9495
NodeId serverNodeId;
96+
bool requireTls;
9597
bool checksum;
9698
bool signalId;
9799
bool isMgmConnection; // is a mgm connection, requires transforming

storage/ndb/include/transporter/TransporterRegistry.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,11 @@ class TransporterRegistry
541541
NodeId m_remote_nodeId;
542542
int m_s_service_port; // signed port number
543543
const char *m_interface;
544+
bool m_require_tls;
544545
};
545546
Vector<Transporter_interface> m_transporter_interface;
546547
void add_transporter_interface(NodeId remoteNodeId, const char *interf,
547-
int s_port); // signed port. <0 is dynamic
548+
int s_port, bool requireTls);
548549

549550
int get_transporter_count() const;
550551
Transporter* get_transporter(TrpId id) const;

storage/ndb/src/common/mgmcommon/IPCConfig.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,18 @@ IPCConfig::configureTransporters(Uint32 nodeId,
162162
Uint32 bindInAddrAny = 0;
163163
iter.get(CFG_TCP_BIND_INADDR_ANY, &bindInAddrAny);
164164

165+
bool requireTls = false;
166+
if(type == CONNECTION_TYPE_TCP && (nodeId1 != nodeId2))
167+
{
168+
Uint32 useTls= 0;
169+
iter.get(CFG_TCP_REQUIRE_TLS, &useTls);
170+
requireTls = useTls;
171+
}
172+
165173
if (nodeId == nodeIdServer && !conf.isMgmConnection) {
166-
tr.add_transporter_interface(remoteNodeId,
167-
!bindInAddrAny ? localHostName : "",
168-
server_port);
174+
tr.add_transporter_interface(remoteNodeId,
175+
!bindInAddrAny ? localHostName : "",
176+
server_port, requireTls);
169177
}
170178

171179
DBUG_PRINT("info", ("Transporter between this node %d and node %d using port %d, signalId %d, checksum %d,"
@@ -191,6 +199,7 @@ IPCConfig::configureTransporters(Uint32 nodeId,
191199
conf.localHostName = localHostName;
192200
conf.remoteHostName = remoteHostName;
193201
conf.serverNodeId = nodeIdServer;
202+
conf.requireTls = requireTls;
194203

195204
Uint32 spintime = 0;
196205
Uint32 shm_send_buffer_size = 2 * 1024 * 1024;
@@ -273,6 +282,8 @@ IPCConfig::configureTransporters(Uint32 nodeId,
273282
loopback_conf.tcp.tcpRcvBufSize = 0;
274283
loopback_conf.tcp.tcpMaxsegSize = 256*1024;
275284
loopback_conf.tcp.tcpOverloadLimit = 768*1024;
285+
loopback_conf.requireTls = false;
286+
276287
if (!tr.configureTransporter(&loopback_conf))
277288
{
278289
g_eventLogger->info("Failed to configure Loopback Transporter");

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ TCP_Transporter::TCP_Transporter(TransporterRegistry &t_reg,
132132
*/
133133
m_slowdown_limit = m_overload_limit * 6 / 10;
134134

135+
m_require_tls = conf->requireTls;
136+
if(! isServer)
137+
use_tls_client_auth();
138+
135139
send_checksum_state.init();
136140
}
137141

@@ -164,6 +168,7 @@ TCP_Transporter::TCP_Transporter(TransporterRegistry &t_reg,
164168
sockOptTcpMaxSeg = t->sockOptTcpMaxSeg;
165169
m_overload_limit = t->m_overload_limit;
166170
m_slowdown_limit = t->m_slowdown_limit;
171+
if(! isServer) use_tls_client_auth();
167172
send_checksum_state.init();
168173
}
169174

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ Transporter::Transporter(TransporterRegistry &t_reg,
8484
isMgmConnection(_isMgmConnection),
8585
m_connected(false),
8686
m_type(_type),
87+
m_require_tls(false),
88+
m_encrypted(false),
8789
reportFreq(4096),
8890
receiveCount(0),
8991
receiveSize(0),
@@ -161,6 +163,16 @@ Transporter::Transporter(TransporterRegistry &t_reg,
161163
DBUG_VOID_RETURN;
162164
}
163165

166+
void
167+
Transporter::use_tls_client_auth()
168+
{
169+
delete m_socket_client;
170+
SocketAuthTls * authTls =
171+
new SocketAuthTls(& m_transporter_registry.m_tls_keys, m_require_tls);
172+
m_socket_client= new SocketClient(authTls);
173+
m_socket_client->set_connect_timeout(m_timeOutMillis);
174+
}
175+
164176
Transporter::~Transporter()
165177
{
166178
delete m_socket_client;
@@ -199,6 +211,7 @@ Transporter::configure(const TransporterConfiguration* conf)
199211
{
200212
if (configure_derived(conf) &&
201213
conf->s_port == m_s_port &&
214+
conf->requireTls == m_require_tls &&
202215
strcmp(conf->remoteHostName, remoteHostName) == 0 &&
203216
strcmp(conf->localHostName, localHostName) == 0 &&
204217
conf->remoteNodeId == remoteNodeId &&
@@ -335,12 +348,14 @@ Transporter::connect_client()
335348
m_socket_client->connect(secureSocket, remote_addr);
336349

337350
/** Socket Authentication */
338-
if(m_socket_client->authenticate(secureSocket) < SocketAuthSimple::AuthOk)
351+
int auth = m_socket_client->authenticate(secureSocket);
352+
if(auth < SocketAuthenticator::AuthOk)
339353
{
340354
DEBUG_FPRINTF((stderr, "Socket Authenticator failed\n"));
341355
DBUG_RETURN(false);
342356
}
343-
357+
g_eventLogger->debug("Transporter client auth result: %d [%s]", auth,
358+
SocketAuthenticator::error(auth));
344359
}
345360

346361
DBUG_RETURN(connect_client(secureSocket));

storage/ndb/src/common/transporter/Transporter.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ class Transporter {
241241

242242
virtual bool configure(const TransporterConfiguration* conf);
243243
virtual bool configure_derived(const TransporterConfiguration* conf) = 0;
244+
void use_tls_client_auth();
244245

245246
/**
246247
* Blocking, for max timeOut milli seconds
@@ -254,7 +255,7 @@ class Transporter {
254255
* Blocking
255256
*/
256257
virtual void disconnectImpl() = 0;
257-
258+
258259
/**
259260
* Remote host name/and address
260261
*/
@@ -317,6 +318,8 @@ class Transporter {
317318
Uint32 m_timeOutMillis;
318319
bool m_connected; // Are we connected
319320
TransporterType m_type;
321+
bool m_require_tls; // Configured mode
322+
bool m_encrypted; // Actual: true only if current connection is secure.
320323

321324
/**
322325
* Statistics

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3548,16 +3548,19 @@ TransporterRegistry::stop_clients()
35483548
void
35493549
TransporterRegistry::add_transporter_interface(NodeId remoteNodeId,
35503550
const char *interf,
3551-
int s_port)
3551+
int s_port, bool require_tls)
35523552
{
35533553
DBUG_ENTER("TransporterRegistry::add_transporter_interface");
35543554
DBUG_PRINT("enter",("interface=%s, s_port= %d", interf, s_port));
35553555
if (interf && strlen(interf) == 0)
35563556
interf= nullptr;
35573557

3558+
// Iterate over m_transporter_interface. If an identical one
3559+
// already exists there, return without adding this one.
35583560
for (unsigned i= 0; i < m_transporter_interface.size(); i++)
35593561
{
35603562
Transporter_interface &tmp= m_transporter_interface[i];
3563+
if (require_tls != tmp.m_require_tls) continue;
35613564
if (s_port != tmp.m_s_service_port || tmp.m_s_service_port==0)
35623565
continue;
35633566
if (interf != nullptr && tmp.m_interface != nullptr &&
@@ -3570,10 +3573,12 @@ TransporterRegistry::add_transporter_interface(NodeId remoteNodeId,
35703573
DBUG_VOID_RETURN; // found match, no need to insert
35713574
}
35723575
}
3576+
35733577
Transporter_interface t;
35743578
t.m_remote_nodeId= remoteNodeId;
35753579
t.m_s_service_port= s_port;
35763580
t.m_interface= interf;
3581+
t.m_require_tls= require_tls;
35773582
m_transporter_interface.push_back(t);
35783583
DBUG_PRINT("exit",("interface and port added"));
35793584
DBUG_VOID_RETURN;
@@ -3597,8 +3602,7 @@ TransporterRegistry::start_service(SocketServer& socket_server)
35973602
unsigned short port= (unsigned short)t.m_s_service_port;
35983603
if(t.m_s_service_port<0)
35993604
port= -t.m_s_service_port; // is a dynamic port
3600-
// FIXME, use t.m_require_tls in patch#4:
3601-
SocketAuthTls * auth = new SocketAuthTls(& m_tls_keys, false);
3605+
SocketAuthTls * auth = new SocketAuthTls(& m_tls_keys, t.m_require_tls);
36023606
TransporterService *transporter_service = new TransporterService(auth);
36033607
ndb_sockaddr addr;
36043608
if (t.m_interface && Ndb_getAddr(&addr, t.m_interface))

0 commit comments

Comments
 (0)