Secured communications (SSL/TLS)¶
You can encrypt the internal communication between CrateDB nodes and the external communication with HTTP and PostgreSQL clients. When you configure encryption, CrateDB secures connections using Transport Layer Security (TLS).
You can enable SSL on a per-protocol basis:
If you enable SSL for HTTP, all connections will require HTTPS.
By default, if you enable SSL for the PostgreSQL wire protocol, clients can negotiate on a per-connection basis whether to use SSL. However, you can enforce SSL via Host-Based Authentication.
If you enable SSL for the CrateDB transport protocol (used for intra-node communication), nodes only accept SSL connections (ssl.transport.mode set to
on
).
Tip
You can use on
SSL mode to configure a multi-zone cluster to ensure
encryption for nodes communicating between zones. Please note, that SSL has
to be on
in all nodes as communication is point-2-point, and intra-zone
communication will also be encrypted.
Table of contents
SSL/TLS configuration¶
To enable SSL a keystore
and a few configuration changes are necessary.
These changes need to be made in the crate.yml
file on each node that
should have secure communications enabled.
Skip to Generate Keystore with a private key for a step-by-step instruction on how to
create a keystore
.
Once the keystore
(and optional truststore
) is created, continue with
the following steps:
Set
ssl.psql.enabled
orssl.http.enabled
totrue
.Set
ssl.transport.mode
toon
.(Optional) Configuring a separate Truststore
Note
CrateDB monitors SSL files such as keystore and truststore that are configured as values of the node settings. If any of these files are updated CrateDB dynamically reloads them. The polling frequency of the files is set via the ssl.resource_poll_interval setting.
Configuring the Keystore¶
SSL/TLS needs a keystore. The keystore holds the node certificate(s) which should be signed by a certificate authority (CA). A third-party CA or your organization’s existing CA can be used.
When a client connects to a node using SSL/TLS, the client receives the certificate provided by the node and will determine if the node’s certificate is valid, trusted, and matches the hostname or IP address it is trying to connect to.
Caution
Technically, it’s possible to disable CA checks for certificates on the client. It is strongly recommended however to use certificates signed by an official CA or by a private CA (company PKI) that is also known to the client. This will help to ensure that establishing trust is as painless as possible.
See Generate Keystore with a private key for information about how to create a keystore.
Once the keystore is prepared, define the absolute file path to the keystore
.jks
file on the node using ssl.keystore_filepath
setting.
Note
Make sure that the keystore file has the right permissions and is
accessible by the system user crate
.
Also, define the password needed to decrypt the keystore by using the
ssl.keystore_password
setting.
Use ssl.keystore_key_password
setting to define the key password used when
creating the Keystore.
For a full list of the settings needed to configure SSL/TLS, refer to SSL configuration reference.
Configuring a separate Truststore¶
Trusted CA certificates can be stored in a node’s keystore or a separate truststore can be used to store them.
If you want to use a separate truststore, create a node truststore and import
the CA certificate(s) you want to trust. Once the truststore is prepared,
define the absolute file path of the truststore .jks
file on the node
using the ssl.truststore_filepath
setting.
Note
Make sure that the truststore file has the right permissions and is
accessible by the system user crate
.
Also define the password needed to decrypt the keystore by using the
ssl.truststore_password
setting.
For a full list of the settings needed to configure SSL/TLS, refer to SSL configuration reference.
Connecting to a CrateDB node using HTTPS¶
Connect to a CrateDB node using the Admin UI¶
Crate’s HTTP endpoint remains unchanged. When you have turned on secure communication, it will use HTTPS instead of plain HTTP. Simply point your browser to the same URL you used before but changing the protocol to HTTPS:
For example, https://localhost:4200
becomes https://localhost:4200
.
If you have not configured the CrateDB node’s keystore with a signed
certificate from a Certificate Authority (CA), then you will get something
like the following: NET::ERR_CERT_AUTHORITY_INVALID
. You either need to
get your certificate signed from one of the CAs included in your browser or
import your owned certificates into the browser. A third option is storing
an exception for the CrateDB node certification in your browser after
verifying that this is indeed a certificate you trust.
Connect to a CrateDB node using Crash¶
You can connect to a CrateDB node using a secure communication:
crash --hosts https://localhost:4200
To validate the provided certificates, please see the options
--verify-ssl
and --key-file
.
Connect to a CrateDB node using REST¶
Issue your REST requests to the node using the https://
protocol. You
may have to configure your client to validate the received certificate
accordingly.
Connecting to a CrateDB node using the PostgreSQL wire protocol with SSL/TLS¶
Connect to a CrateDB node using JDBC¶
JDBC needs to validate the CrateDB node’s identity by checking that the node certificate is signed by a trusted authority. If the certificate is signed by a certificate authority (CA) that is known to the Java runtime, there is nothing further to do (as Java comes with copies of the most common CA’s certificates).
If you have a certificate that is signed by a CA not known to the Java runtime, you need to configure a truststore which contains the node’s certificate and provide the path to the truststore file along with the password when starting your Java application:
java -Djavax.net.ssl.trustStore=mystore -Djavax.net.ssl.trustStorePassword=mypassword com.mycompany.MyApp
In case you face any issues extra debugging information is available by adding
-Djavax.net.debug=ssl
to your command line.
Last but not least, the connection parameter ssl=true
must be added to the
connection URL so that the JDBC driver will try and establish an SSL
connection.
For further information, visit JDBC SSL documentation.
Connect to a CrateDB node using psql
¶
By default, psql
attempts to use SSL if available on the node. For further
information including the different SSL modes please visit the
PSQL documentation.
Setting up a Keystore/Truststore with a certificate chain¶
In case you need to setup a Keystore or a Truststore, here are the commands to get you started. All the commands use a validity of 36500 days (about 100 years). You might want to use less.
Generate Keystore with a private key¶
The first step is to create a Keystore with a private key using the RSA algorithm. The “first and last name” is the common name (CN) which should overlap with the URL the service it is used with.
Command:
keytool -keystore keystore -genkey -keyalg RSA -alias server -validity 36500
Output:
Enter keystore password:
Re-enter new password:
What is your first and last name?
[Unknown]: ssl.crate.io
What is the name of your organizational unit?
[Unknown]: Cryptography Department
What is the name of your organization?
[Unknown]: Crate.io GmbH
What is the name of your City or Locality?
[Unknown]: Berlin
What is the name of your State or Province?
[Unknown]: Berlin
What is the two-letter country code for this unit?
[Unknown]: DE
Is CN=ssl.crate.io, OU=Cryptography Department, O=Crate.io GmbH, L=Berlin, ST=Berlin, C=DE correct?
[no]: yes
Enter key password for <server>
(RETURN if same as keystore password):
Re-enter new password:
Generate a certificate signing request¶
To establish trust for this key, we need to sign it. This is done by generating a certificate signing request.
If you have access to a certificate authority (CA), you can skip the next steps and get the signed certificate from the CA using the signing request which we will generate with the command below. If you don’t have access to a CA, then follow the optional steps after this step to establish your own CA.
Command:
keytool -keystore keystore -certreq -alias server -keyalg RSA -file server.csr
Output:
Enter keystore password:
Enter key password for <server>
Import the signed certificate¶
Now we have a signed certificate, signed by either from a official CA or from our own CA. Let’s import it to the Keystore.
Command:
keytool -import -keystore keystore -file server.crt -alias server
Output:
Enter keystore password:
Enter key password for <server>
Certificate reply was installed in keystore
Configuring CrateDB¶
Finally, you want to supply the Keystore/Truststore in the CrateDB configuration, see Secured communications (SSL/TLS).