Introduction
Some weeks ago, while I was upgrading my server operating system, I had to reboot the machine to load the new kernel. Unfortunately, the machine actually wasn’t feeling well and decided not to reboot. After contacting the data center support, it appeared the chassis had a critical hardware failure which prevented it from booting again.
This event taught me several things :
-
reboot is not an innocuous operation (in my very case : IPMI fails very quickly after power on, and serial console was not reading anything interesting) ;
-
hardware issues may have nothing to do with current runtime (no kernel warning popped out recently) ;
-
backups are primordial (you can’t imagine how the last backup I’ve run some days before the upgrade reassured me during this period) ;
-
SLA means something, including for IaaS (in my very case : probably due to a blade containing multiple servers, data center operators couldn’t access the chassis to get the disk out without impacting other clients. So they did not, according to the SLA).
On our “new” machine, I had to go through re-setup Web server(s) and, among other things, TLS certificates.
Do I really need to introduce you to EFF’s Certbot, which you are very likely already using to obtained HTTPS certificates from Let’s Encrypt ? I guess not, ‘cause you wouldn’t be reading this blog post if you know nothing about it.
So what is the link between your server crash and Certbot ?
Well, this time I decided not to grant administrator privileges to this piece of software, and we’ll see how we can achieve that.
Installation
Official setup procedure recommends to go through Canonical’s snapd software to deploy Certbot, but I tend to reject these approaches, mostly when it’s about running interpreted code (and not compiled C/C++ programs, which can require several libraries loaded at runtime, which can “justify” [please note the quotes] shipping tons of BLOBs to ease deployment among heterogeneous systems).
As Certbot is still distributed through PyPI, we’ll go this way.
Asking for a certificate
So there is two ways to ask for an HTTPS certificate : either Certbot spawns an HTTP Web server and directly responds to CA’s http-01 challenge, or it could write to an already “served” HTTP Web root.
The standalone http-01 server way
The idea here is to make Certbot bind a local port > 1024, redirect new HTTP traffic to this port and let it directly respond to the http-01 challenge (as it were the actual Web server behind your domain name/IP address).
For a certificate that has been asked for the first time this way (as certbot
user) :
… I propose you below Bash renewal script (mainly the detailed steps to adapt with your setup) :
For this script to work, I assume :
-
jq
is available on the system (used to parsenft
JSON output) ; -
The firewall is managed through nftables ;
-
(nftables) tables
ip nat
andinet filter
exist ; -
(nftables) chains
prerouting
(ip nat
) andinput
(inet filter
) exist.
Note : http-01 server configuration is stored by Certbot so we don’t have to specify --http-01-*
arguments during renewal.
The already “served” HTTP Web root
This is the method I’d prefer, as we don’t have to play with firewall.
First, you will have to tweak your Web server configuration (i.e. the default VHOST) to :
-
Disable HTTPS redirection for
.well-known
URIs (if any) ; -
Allows access to
.well-known/acme-challenge
Web root (if restricted).
Below, for instance, Apache httpd configuration :
Now, you can run the following commands :
A typical renewal procedure would then be :
Note : Web root path configuration is stored by Certbot so we don’t have to specify --webroot-path
argument during renewal.
The trick with --deploy-hook
is required as Certbot exits with status code 0
on “success” (i.e. either when zero, one or multiple certificates got renewed). @iquito’s workaround is thus required here if we want to prevent unconditional Web server restart.
Conclusion
Do backup. Try your restoration procedure. Encrypt the world. Get rid of unnecessary privileges. KISS.