nginx / njs-acme

Nginx NJS module runtime to work with ACME providers like Let's Encrypt for automated no-reload TLS certificate issue/renewal.
Apache License 2.0
70 stars 11 forks source link

Fixes #52 - Ensure key/cert are in a consistent state despite errors #53

Closed zsteinkamp closed 8 months ago

zsteinkamp commented 8 months ago

Proposed changes

Issue #52 details a scenario where a failure during ACME validation can leave the target system in a failed state where HTTPS does not work at all. The nature of the problem is that the new .key file is written before the ACME validation step runs. If that validation fails, then the system is left with a new .key file and an old .crt file, which is invalid.

This change is to first write the new .key to a .key.tmp file, do the ACME validation, store the .crt, then rename the .key.tmp file to .key before purging the cache.

Checklist

Before creating a PR, run through this checklist and mark each as complete.