Skip to content

Commit

Permalink
fix(acme): fix ACME renewal bug
Browse files Browse the repository at this point in the history
Using client.renew_certificate directly as the callback function in ngx_timer_at
causes the parameter value to not be the plugin's config.

KAG-4008
  • Loading branch information
Water-Melon committed Mar 28, 2024
1 parent 50cd3f5 commit 286eb94
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelog/unreleased/kong/fix-acme-renewal-bug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: "**ACME**: Fixed an issue where the certificate was not successfully renewed during ACME renewal."
type: bugfix
scope: Plugin
2 changes: 1 addition & 1 deletion kong/plugins/acme/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ return {
end,

PATCH = function()
ngx_timer_at(0, client.renew_certificate)
ngx_timer_at(0, handler.renew)
return kong.response.exit(202, { message = "Renewal process started successfully" })
end,
},
Expand Down
3 changes: 3 additions & 0 deletions kong/plugins/acme/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ local function renew(premature)
end


ACMEHandler.renew = renew


function ACMEHandler:init_worker()
local worker_id = ngx.worker.id() or -1
kong.log.info("acme renew timer started on worker ", worker_id)
Expand Down
12 changes: 12 additions & 0 deletions spec/03-plugins/29-acme/01-client_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,18 @@ for _, strategy in ipairs({"off"}) do
assert.is_nil(err)
assert.is_falsy(renew)
end)

it("calling handler.renew with a false argument should be successful", function()
local handler = require("kong.plugins.acme.handler")
handler:configure({{domains = {"example.com"}}})

local original = client.renew_certificate
client.renew_certificate = function (config)
print("mock renew_certificate")
end
handler.renew(false)
client.renew_certificate = original
end)
end)

end)
Expand Down

0 comments on commit 286eb94

Please sign in to comment.