16

A quick review of my Let's Encrypt setup

 3 years ago
source link: https://drewdevault.com/2018/06/27/My-lets-encrypt-setup.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
A quick review of my Let's Encrypt setup

A quick review of my Let's Encrypt setup June 27, 2018 on Drew DeVault's blog

Let’s Encrypt makes TLS much easier for pretty much everyone, but can still be annoying to use. It took me a while to smooth over the cracks in my Let’s Encrypt configuration across my (large) fleet of different TLS-enabled services. I wanted to take a quick moment to share setup with you.

2020-01-02 update: acme-client is unmaintained and caught the BSD disease anyway. I use uacme and my current procedure is documented on my new server checklist. It might not be exactly applicable to your circumstances, YMMV.

The main components are:

nginx and cron need no introduction, but acme-client deserves a closer look. The acme client blessed by Let’s Encrypt is certbot, but BOY is it complicated. It’s a big ol' pile of Python and I’ve found it fragile, complicated, and annoying. The goal of maintaining your nginx and apache configs for you is well intentioned but ultimately useless for advanced users. The complexity of certbot is through the roof, and complicated software breaks.

I bounced between alternatives for a while but when I found acme-client, it totally clicked. This one is written in C with minimal dependencies (LibreSSL and libcurl, no brainers IMO). I bring a statically linked acme-client binary with me to new servers and setup time approaches zero as a result.

I use nginx to answer challenges (and for some services, to use the final certificates for HTTPS - did you know you can use Let’s Encrypt for more protocols than just HTTPS?). I quickly mkdir -p /var/www/acme/.well-known/acme-challenge, make sure nginx can read it, and add the following rules to nginx to handle challenges:

server {
    listen 80;
    listen [::]:80;
    server_name example.org;

    location ^~ /.well-known/acme-challenge {
        alias /var/www/acme;
    }
}

If I’m not using the certificates for HTTPS, this is all I need. But assuming I have some kind of website going, the full configuration usually looks more like this:

server {
    listen 80;
    listen [::]:80;
    server_name example.org;

    location / {
        return 302 https://$server_name$request_uri;
    }

    location ^~ /.well-known/acme-challenge {
        alias /var/www/acme;
    }
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name example.org;

    ssl_certificate /etc/ssl/acme/$server_name/fullchain.pem;
    ssl_certificate_key /etc/ssl/acme/$server_name/privkey.pem;

    location ^~ /.well-known/acme-challenge {
        alias /var/www/acme;
    }

    # ...application specific rules...
}

This covers the nginx side of things. To actually do certificate negotiation, I have a simple script I carry around:

exec >>/var/log/acme 2>&1
date

acme() {
    site=$1
    shift
    acme-client -vNn \
        -c /etc/ssl/acme/$site/ \
        -k /etc/ssl/acme/$site/privkey.pem \
        $site $*
}

acme example.org subd1.example.org subd2.example.org

nginx -s reload

The first two lines set up a log file in /var/log/acme I can use to debug any issues that arise. Then I have a little helper function that wires up acme-client the way I like it, and I can call it for each domain I need certs for on this server. The last line changes if I’m doing something other than HTTPS with the certs (for example, postfix reload).

One gotcha is that acme-client will bail out if the directories don’t exist when you run it, so a quick mkdir -p /etc/ssl/acme/example.org when adding new sites is necessary

The final step is a simple cron entry that runs the script daily:

0 0 * * * /usr/local/bin/acme-update-certs

It’s that easy. It took me a while to get a Let’s Encrypt setup that was simple and satisfactory, but I believe I’ve settled on this one. I hope you find it useful!

Have a comment on one of my posts? Start a discussion in my public inbox by sending an email to ~sircmpwn/[email protected] [mailing list etiquette]

Articles from blogs I read Generated by openring

Go on ARM and Beyond

The industry is abuzz about non-x86 processors recently, so we thought it would be worth a brief post about Go’s support for them. It has always been important to us for Go to be portable, not overfitting to any particular operating sys…

via The Go Programming Language Blog December 17, 2020

Status update, December 2020

Hi all! This status update is the 24th one, so it’s been 2 years I’ve started writing those now (ignoring a little hiatus). Time flies! This month I’ve invested a lot of time into wlroots. My main focus has been renderer v6, which has now been internally rol…

via emersion December 16, 2020

What's cooking on Sourcehut? December 2020

A brisk wind of winter chill sets a stir down my spine, as I sit down with a fresh cup of coffee to yarn a story of careful engineering and passionate spirit that took place over the course of 30 days. The last 30 days. Cause this is the monthly “what’s cook…

via Blogs on Sourcehut December 15, 2020
The content for this site is CC-BY-SA. The code for this site is MIT.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK