Skip to content

Commit 2becd16

Browse files
committed
Increase the suggested body buffer size for the HTTP hook server.
This eliminates potential issues if the HTTP POST size to the hook server containing the cert exceeded nginx's default buffer size (which would prevent the hook server from being able to parse the POST args): auto-ssl#65 Based on some quick tests, it looks like the POST to `/deploy-cert`, containing the certificate chain and private key was the largest POST. These look to be in the neighborhood of 10KB, while nginx's default `client_body_buffer_size` might be either 8KB or 16KB depending on the exact system architecture. To address this, increase the suggested configuration in the README to 128KB (which is probably overkill, but provides plenty of space in case Let's Encrypt's full certificate chain ever becomes bigger). This also adds some better error logging and error handling to the hook server, and adds more specific tests around the hook server.
1 parent 41c3750 commit 2becd16

File tree

10 files changed

+464
-5
lines changed

10 files changed

+464
-5
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ http {
116116
# Internal server running on port 8999 for handling certificate tasks.
117117
server {
118118
listen 127.0.0.1:8999;
119+
120+
# Increase the body buffer size, to ensure the internal POSTs can always
121+
# parse the full POST contents into memory.
122+
client_body_buffer_size 128k;
123+
client_max_body_size 128k;
124+
119125
location / {
120126
content_by_lua_block {
121127
auto_ssl:hook_server()

lib/resty/auto-ssl/servers/hook.lua

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44
-- that can be shared across multiple servers, so this can work in a
55
-- multi-server, load-balanced environment).
66
return function(auto_ssl_instance)
7-
ngx.req.read_body()
8-
local path = ngx.var.request_uri
9-
local params = ngx.req.get_post_args()
10-
117
if ngx.var.http_x_hook_secret ~= ngx.shared.auto_ssl_settings:get("hook_server:secret") then
12-
return ngx.exit(ngx.HTTP_FORBIDDEN)
8+
ngx.log(ngx.ERR, "auto-ssl: unauthorized access to hook server (hook secret did not match)")
9+
return ngx.exit(ngx.HTTP_UNAUTHORIZED)
1310
end
1411

12+
ngx.req.read_body()
13+
local params, params_err = ngx.req.get_post_args()
14+
if not params then
15+
ngx.log(ngx.ERR, "auto-ssl: failed to parse POST args: ", params_err)
16+
return ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
17+
end
18+
19+
local path = ngx.var.request_uri
1520
local storage = auto_ssl_instance:get("storage")
1621
if path == "/deploy-challenge" then
1722
assert(params["domain"])
@@ -20,13 +25,15 @@ return function(auto_ssl_instance)
2025
local _, err = storage:set_challenge(params["domain"], params["token_filename"], params["token_value"])
2126
if err then
2227
ngx.log(ngx.ERR, "auto-ssl: failed to set challenge: ", err)
28+
return ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
2329
end
2430
elseif path == "/clean-challenge" then
2531
assert(params["domain"])
2632
assert(params["token_filename"])
2733
local _, err = storage:delete_challenge(params["domain"], params["token_filename"])
2834
if err then
2935
ngx.log(ngx.ERR, "auto-ssl: failed to delete challenge: ", err)
36+
return ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
3037
end
3138
elseif path == "/deploy-cert" then
3239
assert(params["domain"])
@@ -35,6 +42,10 @@ return function(auto_ssl_instance)
3542
local _, err = storage:set_cert(params["domain"], params["fullchain"], params["privkey"], params["cert"])
3643
if err then
3744
ngx.log(ngx.ERR, "auto-ssl: failed to set cert: ", err)
45+
return ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
3846
end
47+
else
48+
ngx.log(ngx.ERR, "auto-ssl: unknown request to hook server: ", path)
49+
return ngx.exit(ngx.HTTP_NOT_FOUND)
3950
end
4051
end

t/file.t

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ __DATA__
6464
6565
server {
6666
listen 127.0.0.1:8999;
67+
client_body_buffer_size 128k;
68+
client_max_body_size 128k;
6769
location / {
6870
content_by_lua_block {
6971
auto_ssl:hook_server()
@@ -190,6 +192,8 @@ auto-ssl: issuing new certificate for
190192
191193
server {
192194
listen 127.0.0.1:8999;
195+
client_body_buffer_size 128k;
196+
client_max_body_size 128k;
193197
location / {
194198
content_by_lua_block {
195199
auto_ssl:hook_server()

0 commit comments

Comments
 (0)