Skip to content

Commit 26ac1d9

Browse files
committed
Give up trying to renew certificates in storage once they are expired
There are various legitimate reasons why a certificate can't be renewed, such as the domain holder pointing it elsewhere. We don't want to retry those forever.
1 parent fbf726b commit 26ac1d9

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/resty/auto-ssl/jobs/renewal.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,15 @@ local function renew_check_cert(auto_ssl_instance, storage, domain)
158158
local _, issue_err = ssl_provider.issue_cert(auto_ssl_instance, domain)
159159
if issue_err then
160160
ngx.log(ngx.ERR, "auto-ssl: issuing renewal certificate failed: ", err)
161+
-- Give up on renewing this certificate if we didn't manage to renew
162+
-- it before the expiration date
163+
local now = ngx.now()
164+
if cert["expiry"] then
165+
if cert["expiry"] < now then
166+
ngx.log(ngx.NOTICE, "auto-ssl: existing certificate is expired, deleting: ", domain)
167+
storage:delete_cert(domain)
168+
end
169+
end
161170
end
162171

163172
renew_check_cert_unlock(domain, storage, local_lock, distributed_lock_value)

lib/resty/auto-ssl/storage.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ function _M.set_cert(self, domain, fullchain_pem, privkey_pem, cert_pem, expiry)
6060
return self.adapter:set(domain .. ":latest", string)
6161
end
6262

63+
function _M.delete_cert(self, domain)
64+
return self.adapter:delete(domain .. ":latest")
65+
end
66+
6367
function _M.all_cert_domains(self)
6468
local keys, err = self.adapter:keys_with_suffix(":latest")
6569
if err then

0 commit comments

Comments
 (0)