Skip to content

Commit 1bbf39c

Browse files
authored
feat(autossl) add option to delete none whitelisted domains in certificate renewal (#112)
1 parent 6c9760f commit 1bbf39c

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/resty/acme/autossl.lua

+16-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ local default_config = {
5858
challenge_start_delay = 0,
5959
-- if true, the request to nginx waits until the cert has been generated and it is used right away
6060
blocking = false,
61+
enabled_delete_not_whitelisted_domain = false,
6162
}
6263

6364
local domain_pkeys = {}
@@ -332,10 +333,24 @@ function AUTOSSL.check_renew(premature)
332333
goto continue
333334
end
334335

336+
local domain = deserialized.domain
337+
if not AUTOSSL.is_domain_whitelisted(domain, true) then
338+
if AUTOSSL.config.enabled_delete_not_whitelisted_domain then
339+
local err = AUTOSSL.storage:delete(key)
340+
if err then
341+
log(ngx_ERR, "failed to delete certificate for ", domain, " error: ", err)
342+
else
343+
log(ngx_INFO, "successfully delete certificate for domain ", domain)
344+
end
345+
else
346+
log(ngx_INFO, "domain ", domain, " not in whitelist but exists in storage, skipping renewal")
347+
end
348+
goto continue
349+
end
350+
335351
local cert = openssl.x509.new(deserialized.cert)
336352
local _, not_after = cert:get_lifetime()
337353
if not_after - now < AUTOSSL.config.renew_threshold then
338-
local domain = deserialized.domain
339354
local err = AUTOSSL.update_cert({
340355
domain = domain,
341356
renew = true,

0 commit comments

Comments
 (0)