SSL Secure Connections min read


SingleStore DB supports secure connections over SSL. The configuration closely follows and is compatible with MySQL’s SSL features, including the standard MySQL client and drivers. The SSL library used is OpenSSL.

Connect to SingleStore Managed Service using TLS/SSL

Applies to: SingleStore Managed Service

To ensure a secure connection to SingleStore DB, SQL clients must be properly configured to both require a secure connection and to verify the supplied server certificate. Otherwise, the SQL client will not use TLS/SSL connections to SingleStore DB, even if TLS/SSL is enabled on the SingleStore DB cluster. This can compromise security and lead to man-in-the-middle attacks, where a would-be attacker can impersonate a server when SSL is disabled, or create a secure connection by impersonating a server using an illegitimate server certificate.

Configure the SingleStore Managed Service Connection

These instructions describe how to configure the MySQL command-line client to connect to SingleStore Managed Service with a secure connection. SQL clients other than MySQL’s will likely require a different configuration.

  1. Download the singlestore_bundle.pem certificate file and save it to your MySQL client machine.

  2. When connecting to SingleStore Managed Service, be sure to include:

    • The host shown under Admin Endpoint from your cluster in the Customer Portal.

    • Port 3306.

    • The --default-auth=mysql_native_password option.

    • The --ssl-ca option, including the path to the singlestore_bundle.pem file. This can be done via command-line option, as in --ssl-ca=/path/singlestore_bundle.pem, or by setting the appropriate option in the configuration files for the MySQL command-line client. Include the --ssl-mode=REQUIRED when using older versions of the MySQL client, even when the --ssl-ca option is specified.

    • The --ssl-mode=VERIFY_CA option to verify the certificate.

  3. Test the connection to SingleStore Managed Service. The MySQL client will abort with an error if a secure connection cannot be established. While this is most likely due to a misconfiguration, it can also be due to a would-be attacker manipulating the secure connection to SingleStore DB.

    mysql -u admin -p -h <admin-endpoint-host> -P 3306 \
    --default-auth=mysql_native_password \
    --ssl-ca=./singlestore_bundle.pem \
    --ssl-mode=VERIFY_CA
    
  4. Verify that a secure connection has been established to SingleStore Managed Service via the status command.

    mysql -u admin -p -h <admin-endpoint-host> -P 3306 \
    --default-auth=mysql_native_password \
    --ssl-ca=./singlestore_bundle.pem -e 'status' \
    --ssl-mode=VERIFY_CA
    ****
    mysql  Ver 14.14 Distrib 5.6.19, for osx10.9 (x86_64) using  EditLine wrapper
    
    Connection id:        13
    Current database:
    Current user:	      root@yyy.yyy.yyy.yyy
    SSL:                  Cipher in use is AES256-SHA
    Current pager:        stdout
    Using outfile:        ''
    Using delimiter:	  ;
    Server version:       5.5.8 MemSQL source distribution (compatible; MySQL Enterprise & MySQL Commercial)
    Protocol version:     10
    Connection:           xxx.xxx.xxx.xxx via TCP/IP
    Server characterset:  utf8
    Db     characterset:  utf8
    Client characterset:  utf8
    Conn.  characterset:  utf8
    TCP port:             3306
    

Configure the SingleStore Managed Service Connection with Node.js

To enable SSL connections between SingleStore Managed Service and Node.js, download the singlestore_bundle.pem certificate file and use it to create the connection.

The following is an example of using the singlestore_bundle.pem certificate file with node-mysql2.

var mysql = require("mysql2");
var fs = require("fs");

var connection = mysql.createConnection({
    host: HELIOS_CLUSTER_HOSTNAME,
    user: 'admin',
    password: HELIOS_ADMIN_PASSWORD,
    ssl: {
        ca: fs.readFileSync(__dirname + '/singlestore_bundle.pem')
    }
});

connection.connect();
connection.end();

End: Connect to SingleStore Managed Service using TLS/SSL

Generating SSL Certificates

To enable SSL, you must generate certificates and keys (or use existing ones, but sharing keys across different services is not recommended in general).

Each SingleStore DB node which will be receiving SSL connections needs a server certificate and key - these can be the same or different for all servers. The server certificate(s) should be signed by a CA certificate.

Here are example steps for generating a set of self-signed certificates and keys to use with SingleStore DB. You can also use certificates with more sophisticated X509 certificate chains, but the process to create these certificates is beyond the scope of this document.

mkdir certs
cd certs

## The subject string for certificate signing requests.
## Edit the details to match your organization.
SUBJ="/C=US/ST=CA/L=San Francisco/O=MemSQL/CN="
CA_SUBJ="${SUBJ}memsql.ssl.test.ca"
SERV_SUBJ="${SUBJ}memsql.ssl.test.server"

## create the CA cert and key
openssl genrsa 2048 > ca-key.pem
openssl req -new -x509 -nodes -days 3600 -key ca-key.pem -out ca-cert.pem -subj "$CA_SUBJ"

## create the server cert, key, and sign with CA
openssl req -newkey rsa:2048 -days 3600 -nodes -keyout server-key.pem -out server-req.pem -subj "$SERV_SUBJ"
openssl rsa -in server-key.pem -out server-key.pem
openssl x509 -req -in server-req.pem -days 3600 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 -out server-cert.pem

## verify the certificate chain
openssl verify -CAfile ca-cert.pem server-cert.pem

Configuring SingleStore DB for Secure Connections

It’s important to note that enabling secure connections between the client and the SingleStore DB cluster is separate from enabling secure connections between nodes inside the SingleStore DB cluster itself. To configure the SingleStore DB cluster to use secure connections, see either of:

  • Server Configuration for Secure Client Connections, or
  • Server Configuration for Secure Client and Intra-Cluster Connections

To configure your client to use secure connections, see Client Configuration for Secure Client Connections.

Info

When configuring SSL in SingleStore DB, you should specify an absolute path (/path/to/files) to your files. If you specify a relative path (./path/to/files), SingleStore first looks for the path relative to the location of the memsql.cnf file. If the path is not found there, SingleStore looks for the path relative to the current working directory. If neither of those paths work, the operation fails.

Warning

Do not place your SSL certificates in the SingleStore installation directory as that directory is subject to change during upgrades.

Specifying the TLS Version

Use the tls_version global variable to specify the TLS versions allowed by the server.

SELECT @@tls_version;
****
+-----------------------+
| @@tls_version         |
+-----------------------+
| TLSv1,TLSv1.1,TLSv1.2 |
+-----------------------+

By default, TLS versions TLSv1, TLSv1.1, and TLSv1.2 are supported by SingleStore DB and can be set only at startup.

Server Configuration for Secure Client Connections

This section describes how to enable secure connections between clients and the SingleStore DB cluster, but not between nodes within the SingleStore DB cluster. This requires configuring the ssl_cert and ssl_key settings on all aggregators.

Note that, depending on the client configuration, a client connecting to SingleStore DB may or may not use a secure connection even when SSL is enabled on the server. See the Server Configuration to Require Secure Client-Cluster Connections section.

SingleStore Tools

  1. Place server-cert.pem and server-key.pem files on each aggregator in the cluster. You can copy the files from the Generating SSL Certificates section to all aggregators.

  2. Update the SingleStore DB configuration for all aggregators (it is also fine to configure all nodes) to set the ssl_cert and ssl_key settings to the paths to the server-cert.pem and server-key.pem files, respectively. These can be absolute paths, or relative to the SingleStore DB installation directory. You can do this by using sdb-admin update-config. For example:

    sdb-admin list-nodes -q -r aggregator | xargs bash -c '</dev/tty sdb-admin update-config --key ssl_cert --value ./certs/server-cert.pem --memsql-id "$@"' memsql
    
    sdb-admin list-nodes -q -r master | xargs bash -c '</dev/tty sdb-admin update-config --key ssl_cert --value ./certs/server-cert.pem --memsql-id "$@"' memsql
    
    sdb-admin list-nodes -q -r aggregator | xargs bash -c '</dev/tty sdb-admin update-config --key ssl_key --value ./certs/server-key.pem --memsql-id "$@"' memsql
    
    sdb-admin list-nodes -q -r master | xargs bash -c '</dev/tty sdb-admin update-config --key ssl_key --value ./certs/server-key.pem --memsql-id "$@"' memsql
    
  3. Alternatively, edit the memsql.cnf file on all aggregators to add the certificate paths in the [server] section. For example:

    ssl_cert = ./certs/server-cert.pem
    ssl_key = ./certs/server-key.pem
    
  4. Restart all SingleStore DB aggregators.

    sdb-admin restart-node --all
    

MemSQL Ops

  1. Place server-cert.pem and server-key.pem files on each aggregator in the cluster. You can copy the files from the Generating SSL Certificates section to all aggregators.

  2. Update the SingleStore DB configuration for all aggregators (it is also fine to configure all nodes) to set the ssl_cert and ssl_key settings to the paths to the server-cert.pem and server-key.pem files, respectively. These can be absolute paths, or relative to the SingleStore DB installation directory. You can do this by using memsql-ops memsql-update-config. For example:

    memsql-ops memsql-list -q -r aggregator | xargs memsql-ops memsql-update-config --key ssl_cert --value ./certs/server-cert.pem
    
    memsql-ops memsql-list -q -r master | xargs memsql-ops memsql-update-config --key ssl_cert --value ./certs/server-cert.pem
    
    memsql-ops memsql-list -q -r aggregator | xargs memsql-ops memsql-update-config --key ssl_key --value ./certs/server-key.pem
    
    memsql-ops memsql-list -q -r master | xargs memsql-ops memsql-update-config --key ssl_key --value ./certs/server-key.pem
    
  3. Alternatively, edit the memsql.cnf file on all aggregators to add the certificate paths in the [server] section. For example:

    ssl_cert = ./certs/server-cert.pem
    ssl_key = ./certs/server-key.pem
    
  4. Restart all SingleStore DB aggregators.

    memsql-ops memsql-restart --all
    

Server Configuration for Secure Client and Intra-Cluster Connections

This section describes how to enable secure connections between clients and the SingleStore DB cluster, as well as between nodes within the SingleStore DB cluster. This requires configuring the ssl_cert, ssl_key, and ssl_ca settings on all SingleStore DB nodes.

This configuration secures intra-cluster communication by making each SingleStore DB node connect to other SingleStore DB nodes only over secure connections authenticated by a valid server certificate signed by the CA cert specified by the ssl_ca setting.

Note that, depending on the client configuration, a client connecting to SingleStore DB may or may not use a secure connection even when SSL is enabled on the server. See the Server Configuration to Require Secure Client-Cluster Connections section.

Info

This secures communication between all nodes in the cluster and also secures communication between that cluster and a secondary cluster that is replicating databases using SingleStore DB replication. If the performance cost of securing intra-cluster communication is too high but you still want to secure the communication to the secondary cluster, then set node_replication_ssl_only = true in memsql.cnf on every node in your primary cluster. This will disable SSL within the cluster but secure the communication to the secondary replicated cluster. See examples below on how to persist this behavior across your cluster.

SingleStore Tools

  1. Place server-cert.pem, server-key.pem, and ca-cert.pem files on each SingleStore DB node in the cluster. You can copy the files from the Generating SSL Certificates section to all nodes.

  2. Update the SingleStore DB configuration for all nodes to set the ssl_cert, ssl_key, and ssl_ca settings to the paths to the server-cert.pem, server-key.pem, and ca-cert.pem files, respectively. These can be absolute paths, or relative to the SingleStore DB installation directory. You can do this by using sdb-admin update-config. For example:

    sdb-admin update-config --all --key ssl_cert --value ./certs/server-cert.pem
    
    sdb-admin update-config --all --key ssl_key --value ./certs/server-key.pem
    
    sdb-admin update-config --all --key ssl_ca --value ./certs/ca-cert.pem
    
  3. Alternatively, edit the memsql.cnf file on all aggregators to add the certificate paths in the [server] section. For example:

    ssl_cert = ./certs/server-cert.pem
    ssl_key = ./certs/server-key.pem
    ssl_ca = ./certs/ca-cert.pem
    
  4. Restart all SingleStore DB nodes.

    sdb-admin restart-node --all
    

It is also recommended to add REQUIRE SSL, as described in the next section, to the GRANT statement of all SingleStore DB accounts used to connect to aggregator and leaf nodes in ADD AGGREGATOR and ADD LEAF statements (by default, root).

MemSQL Ops

  1. Place server-cert.pem, server-key.pem, and ca-cert.pem files on each SingleStore DB node in the cluster. You can copy the files from the Generating SSL Certificates section to all nodes.

  2. Update the SingleStore DB configuration for all nodes to set the ssl_cert, ssl_key, and ssl_ca settings to the paths to the server-cert.pem, server-key.pem, and ca-cert.pem files, respectively. These can be absolute paths, or relative to the SingleStore DB installation directory. You can do this by using memsql-ops memsql-update-config. For example:

    memsql-ops memsql-update-config --all --key ssl_cert --value ./certs/server-cert.pem
    
    memsql-ops memsql-update-config --all --key ssl_key --value ./certs/server-key.pem
    
    memsql-ops memsql-update-config --all --key ssl_ca --value ./certs/ca-cert.pem
    
  3. Alternatively, edit the memsql.cnf file on all aggregators to add the certificate paths in the [server] section. For example:

    ssl_cert = ./certs/server-cert.pem
    ssl_key = ./certs/server-key.pem
    ssl_ca = ./certs/ca-cert.pem
    
  4. Restart all SingleStore DB nodes.

    memsql-ops memsql-restart --all
    

It is also recommended to add REQUIRE SSL, as described in the next section, to the GRANT statement of all SingleStore DB accounts used to connect to aggregator and leaf nodes in ADD AGGREGATOR and ADD LEAF statements (by default, root).

Server Configuration to Require Secure Client Connections

To make the server restrict access to clients over SSL only, add the REQUIRE SSL clause to the user’s GRANT statement, for example:

GRANT all ON *.* TO 'user'@'%' REQUIRE SSL;

For example, if REQUIRE SSL is specified for the user user:

## this connection attempt is rejected with an "Access denied" error:
$ mysql -u user -h 1.2.3.4

## this works:
$ mysql -u user -h 1.2.3.4 --ssl-ca=ca-cert.pem

Unless the client is configured properly, the client may or may not use SSL to connect to SingleStore DB even if SSL is enabled on the SingleStore DB cluster. Adding REQUIRE SSL helps protect against misconfigured clients by preventing them from connecting over an insecure plaintext connection. However, proper client configuration is still necessary for security against active network attacks, regardless of server configuration. See the Client Configuration for Secure Client Connections section.

Client Configuration for Secure Client Connections

To ensure secure connections, clients must be properly configured to require a secure connection and verify the appropriate server certificate. Otherwise, the client may or may not use SSL to connect to SingleStore DB even if SSL is enabled on the SingleStore DB cluster, and man in the middle attacks can compromise security, e.g. an attacker may impersonate a server with SSL disabled or impersonate a server while presenting a different server certificate.

The instructions below describe how to configure the MySQL command-line client to connect to SingleStore DB with a secure connection. Other clients may need to be configured differently.

Copy ca-cert.pem to your client machine. Specify the path to ca-cert.pem with the --ssl-ca option. This can be given as a command line option, as in --ssl-ca=path/ca-cert.pem, or by setting the appropriate option in the configuration files for the MySQL command-line client. Add the --ssl-mode=REQUIRED option to require a secure connection (this is necessary in older versions of the MySQL client, even when --ssl-ca is specified). The client will abort with an error if a secure connection cannot be established, e.g. if the server is misconfigured or an attacker is modifying the connection.

You can use the status command to print connection details. For example:

$ mysql -uroot -h1.2.3.4 --ssl-ca=ca-cert.pem -e 'status'
--------------
mysql  Ver 14.14 Distrib 5.6.19, for osx10.9 (x86_64) using  EditLine wrapper

Connection id:		13
Current database:
Current user:		root@4.5.6.7
SSL:			Cipher in use is AES256-SHA
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		5.5.8 MemSQL source distribution (compatible; MySQL Enterprise & MySQL Commercial)
Protocol version:	10
Connection:		1.2.3.4 via TCP/IP
Server characterset:	utf8
Db     characterset:	utf8
Client characterset:	utf8
Conn.  characterset:	utf8
TCP port:		3306
--------------

Configuring MemSQL Ops for Secure Connections

As of version 4.0.31, MemSQL Ops supports SSL secure connections to protect communications between the browser and Ops primary agent. By default, Ops will be reachable via HTTPS on port 9001.

To enable SSL you need a private key and a certificate for MemSQL Ops, issued by a trusted Certificate Authority. In this guide we assume the private key is stored in key.pem and the certificate in cert.pem.

Connect to MemSQL Ops primary agent, then follow the steps below.

  1. Make sure to have your private key key.pem and certificate cert.pem. If you don’t have a key or certificate, you can generate a fresh RSA key and a self-signed certificate (replace location, organization name, and OPS_IP_ADDRESS with the primary agent IP address or hostname, e.g. if you connect to Ops via http://192.168.0.1:9000, then replace OPS_IP_ADDRESS with 192.168.0.1):

    openssl req -x509 -newkey rsa:2048 -sha256 -keyout key.pem -out cert.pem \
      -nodes -subj "/C=US/ST=CA/L=San Francisco/O=My Org/CN=OPS_IP_ADDRESS"
    
  2. Install the key and certificate in MemSQL Ops

    sudo memsql-ops ssl-set-cert -k key.pem -c cert.pem
    
  3. Restart MemSQL Ops

    sudo memsql-ops restart [--ssl-port 9001]
    

    Make sure the SSL port (default 9001) is open and reachable on your primary agent host.

  4. Reload the web page in the browser.

    Note that, if you have generated a self-signed certificate as above, your browser won’t trust this certificate and will refuse to connect to MemSQL Ops. You may want to ignore the error message or add the self signed certificate to the browser’s trusted sources. Depending on browser and operating system the procedure is slightly different, if not familiar we recommend to search the web with keywords add self signed certificate.

    Info

    This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit. (http://www.openssl.org/). This product includes cryptographic software written by Eric Young (eay@cryptsoft.com).