Using Let's Encrypt SSL Certificates with Spacewalk
By default, Spacewalk creates and uses self-signed certificates for its SSL configuration. This requires the end-user to accept and trust the CA certificiate created by Spacewalk in each browser. This post details how to replace the self-signed certificates with CA-signed certificates from Let’s Encrypt.
Prerequisites
Before you begin, ensure your Spacewalk server is subscribed to the appropriate EPEL channel, either directly or via a Spacewalk-delivered Software Channel.
We will use the certbot
utility that is provided by EPEL to obtain and renew
certificates from Let’s Encrypt.
This process requires that your Spacewalk server is accessible via the Internet on HTTP (port 80). Let’s Encrypt uses HTTP to validate the request for a certificate. If you cannot connect your Spacewalk instance to the Internet, review alternative methods for obtaining a certificate using DNS.
DNS configuration
As Let’s Encrypt uses HTTP by default to validate the certificate request, ensure that the fully-qualified domain name (FQDN) of the Spacewalk server is resolvable on the Internet and can be used to connect to your Spacewalk instance remotely.
Step 1: Obtain the certificate
First, install the certbot
tool:
|
|
Next, use certbot
to request a certificate for your Spacewalk server’s FQDN:
|
|
Replace spacewalk.domain.com
with the actual FQDN of your server. The certbot
tool will create an HTML file in /var/www/html/.well-known/
and then attempt
to connect to http://spacewalk.domain.com/.well-known/ to retrieve the content
of that file. This verifies that the request came from spacewalk.domain.com
.
This will fail if:
- Let’s Encrypt’s servers cannot resolve
spacewalk.domain.com
using DNS. - Let’s Encrypt’s servers cannot connect to
spacewalk.domain.com
via HTTP.
Assuming it succeeds, certbot
will create certificates in /etc/letsencrypt/live
for your server. We will use those certificates to configure Spacewalk.
Step 2: Setup automatic renewal of certificates
Let’s Encrypt creates certificates that are only valid for 90 days. We need to
enable a cron
job or systemd
timer to check for certificate expiry on a
regular basis and renew the certificate before it expires.
Let’s Encrypt recommends checking for expiry twice daily.
Create a script that triggers on renew
jabberd
requires a full chain certificate that includes the private key as
well as the public key chain. This is not created automatically by certbot
so
we need a script that runs on renewal to create it automatically.
Edit /usr/local/bin/certbot-renew.sh
and add the following:
|
|
And then make it executable by running:
# chmod +x /usr/local/bin/certbot-renew.sh
We will configure certbot
to run this script whenever the certificates are
successfully renewed.
Using Cron (Oracle Linux 6 or 7)
A sample cron
script to check for renewals:
43 0,12 * * * certbot renew --renew-hook "/usr/local/bin/certbot-renew.sh"
This job will run twice a day and if the certificate is renewed, will restart all the Spacewalk services. No action is taken if the certificate is not renewed.
Using Systemd (Oracle Linux 7)
The latest certbot
package ships with a systemd
timer that can be used
to automatically renew the certificate.
First, enable and start the timer:
|
|
You can view the status of the timer as well:
|
|
You should then edit /etc/sysconfig/certbot
to restart Spacewalk if the
certificate is renewed by the timer. Add the following command to the RENEW_HOOK
directive:
|
|
Step 3: Build the CA Certificate Chain
While the certbot
tool will create and renew the client-side certificates,
it doesn’t automatically save the full CA chain. This is not an issue for
standard HTTPS sites, as the chain is embedded in most browsers. However,
Spacewalk distributes the CA chain to all clients so that the Spacewalk client
software can verify the certificate presented by the browser.
To build the Let’s Encrypt CA chain, we need two different certificates.
IdenTrust DST Root CA X3
Copy and paste the IdenTrust DST Root CA X3 certificate into a text file from https://www.identrust.com/certificates/trustid/root-download-x3.html and save it locally on your Spacewalk server.
You should add -----BEGIN CERTIFICATE-----
at the top of the file and
-----END CERTIFICATE-----
at the end of the file so that it looks like this:
-----BEGIN CERTIFICATE-----
MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/
MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT
DkRTVCBSb290IENBIFgzMB4XDTAwMDkzMDIxMTIxOVoXDTIxMDkzMDE0MDExNVow
PzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD
Ew5EU1QgUm9vdCBDQSBYMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
AN+v6ZdQCINXtMxiZfaQguzH0yxrMMpb7NnDfcdAwRgUi+DoM3ZJKuM/IUmTrE4O
rz5Iy2Xu/NMhD2XSKtkyj4zl93ewEnu1lcCJo6m67XMuegwGMoOifooUMM0RoOEq
OLl5CjH9UL2AZd+3UWODyOKIYepLYYHsUmu5ouJLGiifSKOeDNoJjj4XLh7dIN9b
xiqKqy69cK3FCxolkHRyxXtqqzTWMIn/5WgTe1QLyNau7Fqckh49ZLOMxt+/yUFw
7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40dutolucbY38EVAjqr2m7xPi71XAicPNaD
aeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNV
HQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMSnsaR7LHH62+FLkHX/xBVghYkQMA0GCSqG
SIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69
ikugdB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXr
AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz
R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5
JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo
Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ
-----END CERTIFICATE-----
Next, grab the [Let’s Encrypt Authority X3 (IdenTrust cross-signed)] (https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.pem.txt) from https://letsencrypt.org/certificates/ and save that to a text file too:
-----BEGIN CERTIFICATE-----
MIIEkjCCA3qgAwIBAgIQCgFBQgAAAVOFc2oLheynCDANBgkqhkiG9w0BAQsFADA/
MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT
DkRTVCBSb290IENBIFgzMB4XDTE2MDMxNzE2NDA0NloXDTIxMDMxNzE2NDA0Nlow
SjELMAkGA1UEBhMCVVMxFjAUB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
uM2VcGfl96S8TihRzZvoroed6ti6WqEBmtzw3Wodatg+VyOeph4EYpr/1wXKtx8/
wApIvJSwtmVi4MFU5aMqrSDE6ea73Mj2tcMyo5jMd6jmeWUHK8so/joWUoHOUgwu
X4Po1QYz+3dszkDqMp4fklxBwXRsW10KXzPMTZ+sOPAveyxindmjkW8lGy+QsRlG
PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6
KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==
-----END CERTIFICATE-----
Finally, combine the two text files to create the chain, with the IdenTrust certificate first and the Let’s Encrypt certificate second. The final file should look like this:
-----BEGIN CERTIFICATE-----
MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/
MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT
DkRTVCBSb290IENBIFgzMB4XDTAwMDkzMDIxMTIxOVoXDTIxMDkzMDE0MDExNVow
PzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD
Ew5EU1QgUm9vdCBDQSBYMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
AN+v6ZdQCINXtMxiZfaQguzH0yxrMMpb7NnDfcdAwRgUi+DoM3ZJKuM/IUmTrE4O
rz5Iy2Xu/NMhD2XSKtkyj4zl93ewEnu1lcCJo6m67XMuegwGMoOifooUMM0RoOEq
OLl5CjH9UL2AZd+3UWODyOKIYepLYYHsUmu5ouJLGiifSKOeDNoJjj4XLh7dIN9b
xiqKqy69cK3FCxolkHRyxXtqqzTWMIn/5WgTe1QLyNau7Fqckh49ZLOMxt+/yUFw
7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40dutolucbY38EVAjqr2m7xPi71XAicPNaD
aeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDV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6xK8xuQSXgvopZPKiAlKQTGdMDQMc2PMTiVFrqoM7hD8bEfwzB/onkxEz0tNvjj
/PIzark5McWvxI0NHWQWM6r6hCm21AvA2H3DkwIDAQABo4IBfTCCAXkwEgYDVR0T
AQH/BAgwBgEB/wIBADAOBgNVHQ8BAf8EBAMCAYYwfwYIKwYBBQUHAQEEczBxMDIG
CCsGAQUFBzABhiZodHRwOi8vaXNyZy50cnVzdGlkLm9jc3AuaWRlbnRydXN0LmNv
bTA7BggrBgEFBQcwAoYvaHR0cDovL2FwcHMuaWRlbnRydXN0LmNvbS9yb290cy9k
c3Ryb290Y2F4My5wN2MwHwYDVR0jBBgwFoAUxKexpHsscfrb4UuQdf/EFWCFiRAw
VAYDVR0gBE0wSzAIBgZngQwBAgEwPwYLKwYBBAGC3xMBAQEwMDAuBggrBgEFBQcC
ARYiaHR0cDovL2Nwcy5yb290LXgxLmxldHNlbmNyeXB0Lm9yZzA8BgNVHR8ENTAz
MDGgL6AthitodHRwOi8vY3JsLmlkZW50cnVzdC5jb20vRFNUUk9PVENBWDNDUkwu
Y3JsMB0GA1UdDgQWBBSoSmpjBH3duubRObemRWXv86jsoTANBgkqhkiG9w0BAQsF
AAOCAQEA3TPXEfNjWDjdGBX7CVW+dla5cEilaUcne8IkCJLxWh9KEik3JHRRHGJo
uM2VcGfl96S8TihRzZvoroed6ti6WqEBmtzw3Wodatg+VyOeph4EYpr/1wXKtx8/
wApIvJSwtmVi4MFU5aMqrSDE6ea73Mj2tcMyo5jMd6jmeWUHK8so/joWUoHOUgwu
X4Po1QYz+3dszkDqMp4fklxBwXRsW10KXzPMTZ+sOPAveyxindmjkW8lGy+QsRlG
PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6
KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==
-----END CERTIFICATE-----
You should save that as /root/ca-chain.pem
on your Spacewalk server.
You can then validate the chain using the openssl
tool:
|
|
If you get the OK
, you’re OK to reconfigure Spcaewalk.
Step 4: Update ssl-build with the Let’s Encrypt Certificate
First, backup the SSL configuration currently in use by Spacewalk:
|
|
Then, replace the self-signed certificates created by Spacewalk with links to the live Let’s Encrypt certificates.
In the following commands, replace <hostname>
with the hostname of your
Spacewalk server and <fqdn>
with the fully-qualified domain name of your
Spacewalk server.
# cd /root/ssl-build/<hostname>/
# mv server.crt server.crt.self-signed
# mv server.key server.key.self-signed
# ln -s /etc/letsencrypt/live/<fqdn>/fullchain.pem server.crt
# ln -s /etc/letsencrypt/live/<fqdn>/privkey.pem server.key
Next, replace the existing CA certificate with the Let’s Encrypt chain:
|
|
You should now be able to validate the certificate in-place using the same
openssl
command we used before:
|
|
If you get the OK, it’s time to tell Spacewalk about your new certificate.
Step 5: Add the CA to Spacewalk and create the certificate RPMs
We need to add the CA certificate to the Spacewalk database so that it is automatically installed on provisioned systems during kickstart:
|
|
Generate the web server SSL package
Take care to note the actual filename of the RPMs created. You’ll need to use that filename in subsequent commands.
|
|
Then, install it:
|
|
Generate the CA certificate package
Take care to note the actual filename of the RPMs created. You’ll need to use that filename in subsequent commands.
|
|
Then, install it:
|
|
Make the CA certificates available to clients
We need to copy the CA certificate and the CA RPM to /var/www/html/pub
so that
they’re accessible to client machines.
|
|
Step 6: Link Let’s Encrypt Certificates
The Let’s Encrypt certificates are updated every 90 days by the renew timer. We
don’t want to have to manually build a new rhn-org-httpd-ssl-key-pair-spacewalk
RPM every time they’re updated, so let’s just create symlinks instead.
First, move the old Apache/httpd certificates and keys out of the way
|
|
Then, link the live Let’s Encrypt certificates in their place
|
|
Finally, move and link the jabberd certificate
|
|
Now all the services will update their certificates automatically when the
certbot
renewal timer fires the renew-hook
on a successful renewal.
Step 7: Restart Spacewalk
This is pretty simple:
|
|
At this point, you should be able to visit https://spacewalk.domain.com and see the Let’s Encrypt certificate trusted by your browser.
Step 8: Install the updated CA on your clients
Remember to use the actual filenames of the RPMs created in the previous steps and the actual FQDN of your Spacewalk server.
In Step 5, we copied rhn-org-trusted-ssl-cert-1.0-rev.noarch.rpm
to
/var/www/html/pub
so it will be available at
http://spacewalk.domain.com/pub/rhn-org-trusted-ssl-cert-1.0-rev.noarch.rpm. You
can use that URL to install it on each client.
However, as the SSL certificate has already changed, yum
on the client will
not be able to connect to Spacewalk until the new CA has been installed.
Therefore, we have to update the RPM manually:
|
|
This will disable all plugins (including the Spacewalk client) to bypass the connection error. It will then grab the new RPM from your server and install it, replacing the old certificate. At this point, yum should resume working.
Finally, restart osad
(if enabled) using service
(OL6):
|
|
or systemctl
(OL7):
|
|