Skip to content

Commit 3f1c47d

Browse files
authored
Merge pull request #209 from Cargo/renew-allow_domain-delete-expired
Purge expired domains that fail the allow_domain check
2 parents 23412ce + 7aa9931 commit 3f1c47d

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ local function renew_check_cert_unlock(domain, storage, local_lock, distributed_
4646
end
4747
end
4848

49+
local function delete_cert_if_expired(domain, storage, cert)
50+
-- Give up on renewing this certificate if we didn't manage to renew
51+
-- it before the expiration date
52+
if cert["expiry"] and cert["expiry"] < ngx.now() then
53+
ngx.log(ngx.WARN, "auto-ssl: existing certificate is expired, deleting: ", domain)
54+
storage:delete_cert(domain)
55+
end
56+
end
57+
4958
local function renew_check_cert(auto_ssl_instance, storage, domain)
5059
-- Before issuing a cert, create a local lock to ensure multiple workers
5160
-- don't simultaneously try to register the same cert.
@@ -138,6 +147,7 @@ local function renew_check_cert(auto_ssl_instance, storage, domain)
138147
local allow_domain = auto_ssl_instance:get("allow_domain")
139148
if not allow_domain(domain, auto_ssl_instance, nil, true) then
140149
ngx.log(ngx.NOTICE, "auto-ssl: domain not allowed, not renewing: ", domain)
150+
delete_cert_if_expired(domain, storage, cert)
141151
renew_check_cert_unlock(domain, storage, local_lock, distributed_lock_value)
142152
return
143153
end
@@ -175,13 +185,7 @@ local function renew_check_cert(auto_ssl_instance, storage, domain)
175185
local _, issue_err = ssl_provider.issue_cert(auto_ssl_instance, domain)
176186
if issue_err then
177187
ngx.log(ngx.ERR, "auto-ssl: issuing renewal certificate failed: ", issue_err)
178-
179-
-- Give up on renewing this certificate if we didn't manage to renew
180-
-- it before the expiration date
181-
if cert["expiry"] and cert["expiry"] < ngx.now() then
182-
ngx.log(ngx.WARN, "auto-ssl: existing certificate is expired, deleting: ", domain)
183-
storage:delete_cert(domain)
184-
end
188+
delete_cert_if_expired(domain, storage, cert)
185189
end
186190

187191
renew_check_cert_unlock(domain, storage, local_lock, distributed_lock_value)

0 commit comments

Comments
 (0)