Skip to content

Latest commit

 

History

History
33 lines (24 loc) · 2.17 KB

SslAndMtls.md

File metadata and controls

33 lines (24 loc) · 2.17 KB

Main page

SSL and mTLS usage examples

Iproto over SSL or mTLS supported only in Tarantool Enterprise Edition or Tarantool Data Grid.

First of all, we need to have certificates and keys to use SSL. For example we can generate them using gen.sh

Set up SSL

To start Tarantool with SSL specify the transport type and path to ssl key and to the ssl certificate. If you use a single Tarantool instance you can type them in box.cfg:

box.cfg { listen = {
uri = 3301,
params = {
transport = 'ssl',
ssl_key_file = 'key.pem',
ssl_cert_file = 'certificate.crt'
}
} }

A connector client should be prepared for SSL connection.
Generating SslContext:

private static SslContext getSslContext() throws SSLException {
return SslContextBuilder.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE)
.build();
}

Setting SslContext using withSslContext method:

final TarantoolClientBuilder tarantoolClientBuilder = TarantoolClientFactory.createClient()
.withAddress(containerWithSsl.getHost(), containerWithSsl.getMappedPort(3301))
.withCredentials("test_user", "test_password")
.withSslContext(getSslContext());
final TarantoolClient<TarantoolTuple, TarantoolResult<TarantoolTuple>> clientWithSsl =
tarantoolClientBuilder.build();
final TarantoolClient<TarantoolTuple, TarantoolResult<TarantoolTuple>> client =
tarantoolClientBuilder.withSecure(false).build();

Set up mTLS

To start Tarantool with mTLS we need to set ssl_ca_file beside the previous parameters:

transport = 'ssl',
ssl_key_file = 'server.key',
ssl_cert_file = 'server.crt',
ssl_ca_file = 'ca.crt'

Generating SslContext with mTLS:

private static SslContext getSslContextWithCA() throws Exception {
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
final File keyCertChainFile = new File(classloader
.getResource("org/testcontainers/containers/enterprise/ssl/mtls/ca.crt").toURI());
final File keyFile = new File(classloader
.getResource("org/testcontainers/containers/enterprise/ssl/mtls/ca.key").toURI());
String keyStoreFilePassword = "12345678";
KeyStore keyStore = KeyStore.getInstance("PKCS12");
InputStream trustStore = classloader
.getResourceAsStream("org/testcontainers/containers/enterprise/ssl/mtls/trustStoreFile");
keyStore.load(trustStore, keyStoreFilePassword.toCharArray());
TrustManagerFactory trustManagerFactory = TrustManagerFactory
.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keyStore);
return SslContextBuilder.forClient()
.trustManager(trustManagerFactory)
.keyManager(keyCertChainFile, keyFile)
.build();
}

Setting SslContext using withSslContext method:

final TarantoolClient<TarantoolTuple, TarantoolResult<TarantoolTuple>> clientWithSsl =
TarantoolClientFactory.createClient()
.withAddress(containerWithSsl.getHost(), containerWithSsl.getMappedPort(3301))
.withCredentials("test_user", "test_password")
.withSslContext(getSslContextWithCA())
.build();

Also, data in params can be set through environment variables starting with TARANTOOL_ for example params.transport can be specified by setting export TARANTOOL_TRANSPORT=ssl.