Configure TLS
Introduction
This section provides instructions on how to enable Transport Layer Security so that requests can be served over the HTTPS protocol.
Warning
|
HTTP is not secure: credentials can be sniffed by a man-in-the-middle attack. It is paramount to use HTTPS |
Note
|
This section is about securing HTTP requests between Clients and RESTHeart. Read Secure connection to MongoDB for more information on how to secure the connection between RESTHeart and MongoDB. |
The HTTPS listener
There are many ways of enabling HTTS; for instance you can setup a web server such as nginx as a reverse proxy in front of RESTHeart or you may rely on cloud services that provides load balancers that manages SSL for you (such are Amazon WS or Google Cloud).
In any case, restheart is able to expose directly the HTTS protocol and this is done configuring the https listener. This is the suggested configuration for small systems.
The following configuration file except shows the involved options:
https-listener:
enabled: true
host: 0.0.0.0
port: 4443
keystore-path: /path/to/keystore/file
keystore-password: secret
certificate-password: secret
Example:
$ http -d https://raw.githubusercontent.com/SoftInstigate/restheart/master/core/bin/generate-certauthority-and-keystore.sh # download the script generate-certauthority-and-keystore.sh
$ ./generate-certauthority-and-keystore.sh -d localhost -a /tmp -p secret # generate a test keystore and certificate authority
$ RHO='/https-listener->{ "enabled": true, "host": "localhost", "port": 4443, "keystore-path": "/tmp/localhost.jks", "keystore-password": "secret", "certificate-password": "secret" }' java -jar restheart.jar # run RESTHeart with TLS enabled
$ http -b --verify /tmp/devCA.pem https://restheart.local:4443/ping # execute a test TLS request
Greetings from RESTHeart!
To enable https configure the https listener using the following options:
-
/https-listener/enabled
true to enable it -
/https-listener/host
the ip where to bind the listener -
/https-listener/port
the port where to bind the listener -
/https-listener/keystore-path
the path of the keystore -
/https-listener/keystore-password
the password of the keystore -
/https-listener/certificate-password
the password of the certificate
A SSL certificate must configured in order to enable the https listener.
Configure the SSL certificate
The SSL certificate must be added to the java keystore set by the keystore-file
configuration property.
Two scripts are available to help configuring the keystore.
generate-certauthority-and-keystore.sh
This is useful for testing purposes. It generates a CA and uses it to issue a SSL certificate, finally generating the keystore file.
Download the script from generate-certauthority-and-keystore.sh
After having generated the keystore file and configured RESTHeart to use it, you need to install the CA root certificate into your OS.
For example, in OSX:
-
Open up
Keychain Access
application by searching it onSpotlight
-
Select
File > Import Items
. Navigate to CA root certificate file generated by the script. SelectSystem
as "Destination Keychain". -
Right click on the certificate in Keychain Access and select
Get Info
-
Expand the Trust section
-
Under When using this certificate select
Always Trust
.
-
convert-letsencrypt-java-keystore.sh
Let’s Encrypt is a popular and nonprofit Certificate Authority providing free TLS certificates.
This script generates the java keystore from Let’s Encrypt certificate archive.
Download the script from convert-letsencrypt-java-keystore.sh