Create certificates
Create self-signed certificates to install on a Redis Software cluster.
| Redis Software |
|---|
When you first install Redis Software, self-signed certificates are created to enable encryption for Redis Software endpoints. These certificates expire after a year (365 days) and must be renewed.
You can renew these certificates by replacing them with new self-signed certificates or by replacing them with certificates signed by a certificate authority (CA).
Renew self-signed certificates
As of v6.2.18-70, Redis Software includes a script to generate self-signed certificates.
By default, the generate_self_signed_certs.sh script is located in /opt/redislabs/utils/.
Here, you learn how to use this script to generate new certificates and how to install them.
Generate self-signed certs script options
You can run the generate_self_signed_certs.sh script with the following options:
| Option | Description |
|---|---|
-h--help |
Displays usage instructions. (Optional) |
-d <days>--days <days> |
Number of days the self-signed certificate is valid for. Setting this field longer than a year (365 days) is not recommended. (Optional, default: 365) |
-f <names>--fqdnNames <names> |
Space-separated list of fully qualified domain names (FQDNs). Used for Subject Alternative Names (SANs). (Required) Example: -f "redis.example.com redis-1.example.com" |
-t <type>--type <type> |
Type of certificate to generate. (Optional, default: all) Values: cm: Cluster Manager UI certificate api: REST API certificate proxy: database endpoint proxy certificate syncer: syncer component certificate metrics: metrics exporter certificate all: generates all certificate types |
Step 1: Generate new certificates
Sign in to the machine hosting the cluster's master node and then run the following command:
% sudo -u redislabs /opt/redislabs/utils/generate_self_signed_certs.sh \
-f "<DomainName1 DomainName2>" -d <Days> -t <Type>
When you run the script, it either reports success ("Self signed cert generated successfully") or an error message. Use the error message to troubleshoot any issues.
The following example generates all self signed certificates for mycluster.example.com; these certificates expire one year after the command is run:
$ sudo -u redislabs /opt/redislabs/utils/generate_self_signed_certs.sh \
-f "mycluster.example.com"`
Suppose you want to create a Cluster Manager UI certificate to support two clusters for a period of two years. The following example shows how:
$ sudo -u redislabs /opt/redislabs/utils/generate_self_signed_certs.sh \
-f "mycluster.example.com anothercluster.example.com" -d 730 -t cm
Here, a certificate file and certificate key are generated to support the following domains:
mycluster.example.com
*.mycluster.example.com
anothercluster.example.com
*.anothercluster.example.com
Step 2: Locate the new certificate files
When successful, the script generates two .PEM files for each generated certificate: a certificate file and a certificate key, each named after the type of certificate generated (see earlier table for individual certificate names.)
These files can be found in the /tmp directory.
$ ls -la /tmp/*.pem
Step 3: Set permissions
We recommend setting the permissions of your new certificate files to limit read and write access to the file owner and to set group and other user permissions to read access.
$ sudo chmod 644 /tmp/*.pem
Step 4: Replace existing certificates
You can use rladmin to replace the existing certificates with new certificates:
$ rladmin cluster certificate set <CertName> certificate_file \
<CertFilename>.pem key_file <KeyFilename>.pem
The following values are supported for the <CertName> parameter:
| Value | Description |
|---|---|
api |
The REST API |
cm |
The Cluster Manager UI |
metrics_exporter |
The metrics exporter |
proxy |
The database endpoint |
syncer |
The synchronization process |
You can also use the REST API. To learn more, see Update certificates.
Create CA-signed certificates
You can use certificates signed by a certificate authority (CA) for Redis Software cluster security.
For best results, use the following guidelines to create the certificates.
Certificate requirements
-
Certificates must include both of the following in the extended key usage extension:
-
TLS Web Server Authentication (OID: 1.3.6.1.5.5.7.3.1)
-
TLS Web Client Authentication (OID: 1.3.6.1.5.5.7.3.2)
Warning:Using certificate templates that only include Server Authentication will cause SSL and TLS errors. -
-
Include the full certificate chain when creating certificate .PEM files. List certificates in order from leaf to root. Some deployments may not require the root CA in the certificate file.
-----BEGIN CERTIFICATE----- <Leaf/Domain Certificate> -----END CERTIFICATE----- -----BEGIN CERTIFICATE----- <Intermediate CA Certificate> -----END CERTIFICATE----- -----BEGIN CERTIFICATE----- <Root CA Certificate> -----END CERTIFICATE----- -
The Subject Alternative Name (SAN) extension must include the following DNS entries based on your cluster's fully qualified domain name (FQDN):
dns=<cluster-fqdn> dns=*.<cluster-fqdn> dns=internal.<cluster-fqdn> dns=*.internal.<cluster-fqdn>For example, if the cluster FQDN is
redis.example.com, the DNS entries include:dns=redis.example.com dns=*.redis.example.com dns=internal.redis.example.com dns=*.internal.redis.example.com -
The key usage extension must include:
-
Digital Signature
-
Key Encipherment
-
-
Use the cluster's fully qualified domain name (FQDN) for the Common Name (CN).
-
Use SHA-256 or SHA-512 for the signature algorithm.
Note:SHA-1 is deprecated and may be blocked by some operating systems. -
The minimum RSA key size is 2048 bits. 4096 bits is recommended for enhanced security.
-
A validity period of 1 year or less is recommended.
Create certificates with OpenSSL
-
Create a configuration file named
redis-cert.cnfwith the following content:[req] default_bits = 2048 prompt = no default_md = sha256 distinguished_name = dn req_extensions = v3_req [dn] C = US ST = California L = Los Angeles O = Your Organization CN = redis-cluster.example.com [v3_req] keyUsage = critical, digitalSignature, keyEncipherment extendedKeyUsage = serverAuth, clientAuth subjectAltName = @alt_names [alt_names] DNS.1 = redis-cluster.example.com DNS.2 = *.redis-cluster.example.com DNS.3 = internal.redis-cluster.example.com DNS.4 = *.internal.redis-cluster.example.comReplace
redis-cluster.example.comwith your cluster's FQDN and replace the[dn]section with your own details. Check with your security team or certificate authority for help creating a valid configuration file for your environment. -
Create a private key:
openssl genrsa -out redis-key.pem 2048For enhanced security, use a 4096-bit key:
openssl genrsa -out redis-key.pem 4096 -
Create a certificate signing request (CSR):
openssl req -new \ -key redis-key.pem \ -out redis-cert.csr \ -config redis-cert.cnf -
Verify the certificate signing request and submit it to your CA.
Submit CSR to the certificate authority
-
Before submitting to your CA, verify the certificate signing request contains all required attributes:
openssl req -text -noout -verify -in redis-cert.csrCheck the output for the following:
-
Subject contains the correct Common Name.
-
Subject Alternative Names include all required DNS entries.
-
Key Usage includes
Digital Signature, Key Encipherment. -
Extended Key Usage includes
TLS Web Server Authentication, TLS Web Client Authentication.
-
-
Submit
redis-cert.csrto your certificate authority for signing. The process varies by CA:-
For an internal CA, follow your organization's certificate request process.
-
For a commercial CA, use their web portal or API.
-
For testing or development purposes only, you can create a self-signed certificate:
openssl x509 -req \ -in redis-cert.csr \ -signkey redis-key.pem \ -out redis-cert.pem \ -days 365 \ -extensions v3_req \ -extfile redis-cert.cnfWarning:Do not use self-signed certificates in production.
-
Create a certificate chain file
After receiving the signed certificate from your CA, create a certificate chain file by combining the certificates in the correct order:
cat redis-cert.pem intermediate-ca.pem root-ca.pem > redis-cert-chain.pem
You must order your certificates as follows:
-
Leaf certificate, which is your domain certificate.
-
Intermediate CA certificates.
-
Root CA certificate, which is optional depending on your deployment.
Create certificates with Windows Active Directory Certificate Services
To create certificates using Windows Active Directory Certificate Services:
-
Complete the prerequisites.
Prerequisites
Before you can create certificates with Windows Active Directory Certificate Services, you need:
-
Access to Windows Active Directory Certificate Services.
-
Permissions to modify certificate templates.
-
Certificate Templates Console certtmpl.msc.
Create certificate template
The default Web Server template in Windows AD CS only includes Server Authentication. You must create a modified template that includes both Server and Client Authentication.
-
Open the Certificate Templates Console as an administrator:
certtmpl.msc -
Right-click the Web Server template, then select Duplicate Template.
-
In the General tab:
-
Set Template name to
Redis Software Server. -
Set the Validity period to 1 year.
-
-
In the Extensions tab:
-
Select Application Policies.
-
Click Edit and verify both of the following are present:
-
Server Authentication (1.3.6.1.5.5.7.3.1)
-
Client Authentication (1.3.6.1.5.5.7.3.2)
-
-
If Client Authentication is missing, click Add, select Client Authentication, and click OK.
-
-
In the Subject Name tab, select Supply in the request to allow specifying Subject Alternative Names during the certificate request.
-
In the Extensions tab:
-
Select Key Usage.
-
Click Edit.
-
Make sure Digital signature and Key encipherment are selected.
-
-
In the Security tab:
-
Add appropriate users and groups.
-
Grant Read and Enroll permissions.
-
-
Click OK to save the template.
Publish the template
-
Open the Certification Authority console:
certsrv.msc -
Expand your CA.
-
Right-click Certificate Templates, then select New > Certificate Template to Issue.
-
Select
Redis Software Serverand click OK.
Request a certificate using certreq
-
Create a certificate request file
redis-cert.inf:[NewRequest] Subject = "CN=redis-cluster.example.com,O=Your Organization,L=City,ST=State,C=US" KeyLength = 2048 KeySpec = 1 Exportable = TRUE MachineKeySet = TRUE ProviderName = "Microsoft RSA SChannel Cryptographic Provider" RequestType = PKCS10 [Extensions] 2.5.29.17 = "{text}" _continue_ = "dns=redis-cluster.example.com&" _continue_ = "dns=*.redis-cluster.example.com&" _continue_ = "dns=internal.redis-cluster.example.com&" _continue_ = "dns=*.internal.redis-cluster.example.com"Replace
redis-cluster.example.comwith your cluster's FQDN. -
Generate the certificate request:
certreq -new redis-cert.inf redis-cert.req -
Submit the request to your CA:
certreq -submit -config "CA-SERVER\CA-Name" redis-cert.req redis-cert.cer -
Accept the issued certificate:
certreq -accept redis-cert.cer
Export certificate and private key
-
Open Certificate Manager:
certlm.msc -
Go to Personal > Certificates.
-
Right-click your certificate, then select All Tasks > Export.
-
Export the certificate with the private key:
-
Select Yes, export the private key.
-
Choose Personal Information Exchange - PKCS #12 (.PFX).
-
Set a password.
-
Save as
redis-cert.pfx.
-
-
Convert the certificate and key to PEM format using OpenSSL:
-
Extract the certificate chain:
openssl pkcs12 -in redis-cert.pfx -nokeys -out redis-cert.pem -
Extract the private key:
openssl pkcs12 -in redis-cert.pfx -nocerts -out redis-key.pem -nodes
-
Validate certificates
Before you upload certificates to Redis Software, validate that they meet all requirements:
-
Validate extended key usage:
openssl x509 -in redis-cert-chain.pem -text -noout | grep -A 3 "Extended Key Usage"Expected output:
X509v3 Extended Key Usage: TLS Web Server Authentication, TLS Web Client AuthenticationIf Client Authentication is missing, the certificate will fail. You must reissue the certificate with both Server and Client Authentication.
-
Validate key usage:
openssl x509 -in redis-cert-chain.pem -text -noout | grep -A 2 "Key Usage"Expected output:
X509v3 Key Usage: critical Digital Signature, Key Encipherment -
Validate Subject Alternative Names:
openssl x509 -in redis-cert-chain.pem -text -noout | grep -A 10 "Subject Alternative Name"Expected output:
X509v3 Subject Alternative Name: DNS:redis-cluster.example.com DNS:*.redis-cluster.example.com DNS:internal.redis-cluster.example.com DNS:*.internal.redis-cluster.example.com -
Validate certificate chain:
-
Count the certificates in the chain:
grep -c "BEGIN CERTIFICATE" redis-cert-chain.pemExpected output: 2 or 3 if the root CA is included.
-
View all certificates in the chain:
openssl crl2pkcs7 -nocrl -certfile redis-cert-chain.pem | \ openssl pkcs7 -print_certs -text -noout | \ grep -E "Subject:|Issuer:" -
Verify the chain order. Each certificate's
Issuershould match theSubjectof the next certificate.
-
-
Validate the signature algorithm:
openssl x509 -in redis-cert-chain.pem -text -noout | grep "Signature Algorithm"Expected output:
sha256WithRSAEncryptionorsha512WithRSAEncryption.Note:Avoidsha1WithRSAEncryptionbecause it is deprecated and might be blocked. -
Validate the public key size:
openssl x509 -in redis-cert-chain.pem -text -noout | grep "Public-Key"Expected output:
Public-Key: (2048 bit)or higher. -
Verify the private key matches the certificate:
-
Get the certificate modulus:
openssl x509 -noout -modulus -in redis-cert-chain.pem | openssl md5 -
Get the key modulus:
openssl rsa -noout -modulus -in redis-key.pem | openssl md5 -
If the MD5 hashes do not match, you have the wrong private key file.
-
-
Verify the certificate is currently valid and not expired:
openssl x509 -in redis-cert-chain.pem -noout -dates
Install certificates
After creating and validating your certificates, install them on the Redis Software cluster:
-
Set restrictive file permissions for the private key:
$ chmod 600 redis-key.pem $ chown redislabs:redislabs redis-key.pem -
Set readable file permissions for the certificate:
$ chmod 644 redis-cert-chain.pem $ chown redislabs:redislabs redis-cert-chain.pem -
Replace the existing certificates with the new certificates using
rladmin cluster certificate:rladmin cluster certificate set <cert-name> \ certificate_file /path/to/redis-cert-chain.pem \ key_file /path/to/redis-key.pemReplace
<cert-name>with the relevant certificate name:Value Description apiREST API certificate cmCluster Manager UI certificate metrics_exporterMetrics exporter certificate proxyDatabase endpoint proxy certificate syncerSynchronization process certificate -
Check certificate status:
rladmin status certificates -
View certificate details:
rladmin info cluster
Troubleshooting
SSLV3_ALERT_UNSUPPORTED_CERTIFICATE error
If the certificate's extended key usage does not include TLS Web Client Authentication, the following error occurs:
[SSL: SSLV3_ALERT_UNSUPPORTED_CERTIFICATE] ssl/tls alert unsupported certificate
To fix this error:
-
Validate extended key usage:
openssl x509 -in redis-cert-chain.pem -text -noout | grep -A 3 "Extended Key Usage" -
If Client Authentication is missing, reissue the certificate:
-
For OpenSSL, add the following line to the configuration file.
extendedKeyUsage = serverAuth, clientAuth -
For Windows AD CS, modify the certificate template and add Client Authentication to Application Policies.
-
CERTIFICATE_VERIFY_FAILED error
If a CERTIFICATE_VERIFY_FAILED error occurs, the certificate chain is incomplete or in the wrong order.
To fix this error:
-
Verify the certificate chain order. Each certificate's
Issuershould match theSubjectof the next certificate.openssl crl2pkcs7 -nocrl -certfile redis-cert-chain.pem | \ openssl pkcs7 -print_certs -text -noout | \ grep -E "Subject:|Issuer:" -
Rebuild the certificate chain in the correct order:
-----BEGIN CERTIFICATE----- <Leaf/Domain Certificate> -----END CERTIFICATE----- -----BEGIN CERTIFICATE----- <Intermediate CA Certificate> -----END CERTIFICATE----- -----BEGIN CERTIFICATE----- <Root CA Certificate> -----END CERTIFICATE-----
Key values mismatch error
If a key_values_mismatch error occurs, the private key does not match the certificate.
Verify the private key matches the certificate:
-
Get the certificate modulus:
openssl x509 -noout -modulus -in redis-cert-chain.pem | openssl md5 -
Get the key modulus:
openssl rsa -noout -modulus -in redis-key.pem | openssl md5 -
If the MD5 hashes don't match, you have the wrong private key file. To fix this error, find the correct private key file.
Missing Subject Alternative Names
If a certificate only has a Common Name, but no Subject Alternative Names, modern TLS implementations might reject it.
To fix this issue, reissue the certificate with proper Subject Alternative Names, including all required DNS entries.