Skip to content

Commit 05bfd53

Browse files
committed
Delete local certificate files after dehydrated fails
For each issue that doesn't succeed we're still creating three files (cert-*.csr, cert-*.pem, privkey-*.pem) in dehydrated's cert directory that don't get deleted. While they are not big in size, a seizable number of (sub-) domains can this silently exhaust the number of available inodes. This is a follow-up to 49256f8
1 parent 9d43c23 commit 05bfd53

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/resty/auto-ssl/ssl_providers/lets_encrypt.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local _M = {}
22

3+
local shell_blocking = require "shell-games"
34
local shell_execute = require "resty.auto-ssl.utils.shell_execute"
45

56
function _M.issue_cert(auto_ssl_instance, domain)
@@ -36,8 +37,17 @@ function _M.issue_cert(auto_ssl_instance, domain)
3637
"--config", base_dir .. "/letsencrypt/config",
3738
"--hook", lua_root .. "/bin/resty-auto-ssl/letsencrypt_hooks",
3839
})
40+
3941
if result["status"] ~= 0 then
4042
ngx.log(ngx.ERR, "auto-ssl: dehydrated failed: ", result["command"], " status: ", result["status"], " out: ", result["output"], " err: ", err)
43+
-- remove the created files from dehydrated's cert directory
44+
assert(string.find(domain, "/") == nil)
45+
assert(string.find(domain, "%.%.") == nil)
46+
local dir = auto_ssl_instance:get("dir") .. "/letsencrypt/certs/" .. domain
47+
local _, rm_err = shell_blocking.capture_combined({ "rm", "-rf", dir })
48+
if rm_err then
49+
ngx.log(ngx.ERR, "auto-ssl: failed to cleanup certs: ", rm_err)
50+
end
4151
return nil, "dehydrated failure"
4252
end
4353

0 commit comments

Comments
 (0)