Menu
#TLS
Set a certificate and its key, both PEM files, and every connection has to use TLS. There is no mix of plain and TLS on one port.
export FERRITE_TLS_CERT=cert.pem
export FERRITE_TLS_KEY=key.pem
ferrite_db 0.0.0.0:7878| variable | meaning |
|---|---|
FERRITE_TLS_CERT |
server certificate, PEM |
FERRITE_TLS_KEY |
its private key, PEM, without a passphrase |
FERRITE_TLS_CLIENT_CA |
PEM file of authorities; clients must show a certificate signed by one |
FERRITE_TLS_CRL |
PEM file of certificate revocation lists for those authorities |
The certificate and key must be set together. A missing file, a file with no certificate, or a key that does not fit the certificate stops the server from starting, with the file named.
Only TLS 1.3 is accepted, and there is no setting for TLS versions or ciphers: it uses the rustls defaults. A plain-text client gets an error from the handshake and nothing else. A TLS failure that is not a plain-text client, such as a refused client certificate, is printed by the server at most once a second.
Clients check the certificate as usual, so it has to be for the name they connect to. See connection strings for tls=true, caFile= and the rest.
#A self-signed certificate
For trying it out:
openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -nodes \
-keyout key.pem -out cert.pem -days 30 -subj "/CN=localhost" \
-addext "subjectAltName=DNS:localhost,IP:127.0.0.1"
openssl s_client -connect localhost:7878 -CAfile cert.pem -quietA plain
openssl req -x509certificate hasCA:TRUE, and client libraries refuse it as a server certificate. Add-addext basicConstraints=critical,CA:FALSEand asubjectAltNamefor the name or address clients use, for example-addext subjectAltName=IP:10.0.0.5,DNS:localhost.
Under the service, put the files where the ferrite user can read them, for example /etc/ferrite/tls/ with the key at 0640 root:ferrite. See deployment.
#Client certificates
Give FERRITE_TLS_CLIENT_CA a PEM file of the authorities that sign client certificates. A client without a certificate from one of them is refused in the handshake and never reaches the protocol. It needs the server certificate and key set too.
The certificate is a gate on the connection and nothing more. The token or a user login is still needed after it, and the name in the certificate is not used for anything. The authority file is read at start only.
#Revocation
FERRITE_TLS_CRL is a PEM file of CRLs from those authorities. Every client certificate then has to be covered by one of the lists, or it is refused. There is no OCSP.
#Reloading
The certificate, key, client authorities and CRLs are checked every 10 seconds. When one changes, in its modified time or its length, they are all read again and used for new connections, so a renewal (certbot, say) needs no restart. Connections that are open keep the certificate they started with.
If the files do not load together, which can be a renewal caught half way, the server tries once more after half a second, then prints what is wrong and keeps using what it had loaded before.
#Notes
- Without
FERRITE_TLS_CLIENT_CA, anyone who can reach the port can try the token. - Not measured: what TLS costs in speed.
- The follower side of replication has its own TLS variables.