Skip to content

Delete local certificate files after dehydrated fails #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/resty/auto-ssl/ssl_providers/lets_encrypt.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local _M = {}

local shell_blocking = require "shell-games"
local shell_execute = require "resty.auto-ssl.utils.shell_execute"

function _M.issue_cert(auto_ssl_instance, domain)
Expand Down Expand Up @@ -36,8 +37,17 @@ function _M.issue_cert(auto_ssl_instance, domain)
"--config", base_dir .. "/letsencrypt/config",
"--hook", lua_root .. "/bin/resty-auto-ssl/letsencrypt_hooks",
})

if result["status"] ~= 0 then
ngx.log(ngx.ERR, "auto-ssl: dehydrated failed: ", result["command"], " status: ", result["status"], " out: ", result["output"], " err: ", err)
-- remove the created files from dehydrated's cert directory
assert(string.find(domain, "/") == nil)
assert(string.find(domain, "%.%.") == nil)
local dir = auto_ssl_instance:get("dir") .. "/letsencrypt/certs/" .. domain
local _, rm_err = shell_blocking.capture_combined({ "rm", "-rf", dir })
if rm_err then
ngx.log(ngx.ERR, "auto-ssl: failed to cleanup certs: ", rm_err)
end
return nil, "dehydrated failure"
end

Expand Down