0

I have a script that auto renews a let's encrypt certificate when it becomes available. We run this script everyday at 17:00

#!/bin/sh
/usr/bin/certbot --cert-name sitename.com --text --agree-tos certonly -a webroot --keep-until-expiring --webroot-path /var/www/path/public -d sitename.com -d www.sitename.com

Recently i've seen that a new certificate is getting generated with a new directory every day with a 00XX suffix.

There has been no chance to this file since it was created (19th August)

So /etc/letsencrypt/archive looks like this:

drwxr-xr-x. 2 root root 4096 Nov 11 09:45 sitename.com
drwxr-xr-x. 2 root root 4096 Aug 19 16:39 sitename.com-0001
drwxr-xr-x. 2 root root 4096 Aug 19 16:43 sitename.com-0002
drwxr-xr-x. 2 root root 4096 Oct 16 17:00 sitename.com-0003
drwxr-xr-x. 2 root root 4096 Oct 17 17:00 sitename.com-0004
drwxr-xr-x. 2 root root 4096 Oct 18 17:00 sitename.com-0005
drwxr-xr-x. 2 root root 4096 Oct 19 17:00 sitename.com-0006
drwxr-xr-x. 2 root root 4096 Oct 20 17:00 sitename.com-0007
drwxr-xr-x. 2 root root 4096 Oct 23 17:00 sitename.com-0008
drwxr-xr-x. 2 root root 4096 Oct 24 17:00 sitename.com-0009
drwxr-xr-x. 2 root root 4096 Oct 25 17:01 sitename.com-0010
drwxr-xr-x. 2 root root 4096 Oct 26 17:00 sitename.com-0011
drwxr-xr-x. 2 root root 4096 Oct 27 17:00 sitename.com-0012
drwxr-xr-x. 2 root root 4096 Oct 30 17:00 sitename.com-0013
drwxr-xr-x. 2 root root 4096 Oct 31 17:00 sitename.com-0014
drwxr-xr-x. 2 root root 4096 Nov  1 17:00 sitename.com-0015
drwxr-xr-x. 2 root root 4096 Nov  2 17:00 sitename.com-0016
drwxr-xr-x. 2 root root 4096 Nov  3 17:00 sitename.com-0017
drwxr-xr-x. 2 root root 4096 Nov  6 17:00 sitename.com-0018
drwxr-xr-x. 2 root root 4096 Nov  7 17:00 sitename.com-0019
drwxr-xr-x. 2 root root 4096 Nov  8 17:00 sitename.com-0020
drwxr-xr-x. 2 root root 4096 Nov  9 17:01 sitename.com-0021
drwxr-xr-x. 2 root root 4096 Nov 10 17:00 sitename.com-0022

I believe that -0001 and -0002 were created because of a misconfiguration when the certificate was first generated.

But can anybody help explain why a certificate and directory has been created each day since october 16th?

dinnertoast
  • 81
  • 1
  • 9

1 Answers1

1

I managed to figure out the problem.

After running

/usr/bin/certbot certificates

There was error:

Renewal configuration file /etc/letsencrypt/renewal/sitename.com.conf produced an unexpected error: renewal config file {} is missing a required file reference. Skipping.

And it appears that there is a conf file for each of the -00XX directories.

Upon looking at /etc/letsencrypt/renewal/sitename.com.conf I found that the file was empty.

So I took the latest -00XX conf file and removed the 00XX suffix from the text lines.

The conf file should appear like this:

# renew_before_expiry = 30 days
version = 1.0.0
archive_dir = /etc/letsencrypt/archive/sitename.com
cert = /etc/letsencrypt/live/sitename.com/cert.pem
privkey = /etc/letsencrypt/live/sitename.com/privkey.pem
chain = /etc/letsencrypt/live/sitename.com/chain.pem
fullchain = /etc/letsencrypt/live/sitename.com/fullchain.pem

# Options used in the renewal process
[renewalparams]
authenticator = webroot
account = XXXXXXXXXXXXXXXXXXXXXXX
webroot_path = /var/www/path/public,
server = https://acme-v02.api.letsencrypt.org/directory

But this will still create a new directory and certificate for each day

You will need to prepend this to your conf file, include a line for each domain associated with your certificate.

[[webroot_map]]
sitename.com = /var/www/path/public
www.sitename.com = /var/www/path/public

And that should prevent certificates being generated everyday.

I believe that the problem is a result of removing domains from a certificate and manually renewing.

dinnertoast
  • 81
  • 1
  • 9