|
28 | 28 | -- secret token is an extra precaution to ensure the server is not accidentally |
29 | 29 | -- opened up or proxied to the outside world. |
30 | 30 | local function generate_hook_sever_secret() |
| 31 | + if ngx.shared.auto_ssl_settings:get("hook_server:secret") then |
| 32 | + -- if we've already got a secret token, do not overwrite it, as this causes |
| 33 | + -- problems in reload-heavy envrionments. |
| 34 | + -- See https://github.com/GUI/lua-resty-auto-ssl/issues/66 |
| 35 | + return |
| 36 | + end |
| 37 | + |
31 | 38 | -- Generate the secret token. |
32 | 39 | local random = resty_random.bytes(32) |
33 | | - AUTO_SSL_HOOK_SECRET = str.to_hex(random) |
| 40 | + local _, set_err, set_forcible = ngx.shared.auto_ssl_settings:set("hook_server:secret", str.to_hex(random)) |
| 41 | + if set_err then |
| 42 | + ngx.log(ngx.ERR, "auto-ssl: failed to set shdict for hook_server:secret: ", set_err) |
| 43 | + elseif set_forcible then |
| 44 | + ngx.log(ngx.ERR, "auto-ssl: 'lua_shared_dict auto_ssl_settings' might be too small - consider increasing its configured size (old entries were removed while adding hook_server:secret)") |
| 45 | + end |
34 | 46 | end |
35 | 47 |
|
36 | 48 | local function generate_config(auto_ssl_instance) |
@@ -82,6 +94,10 @@ local function setup_storage(auto_ssl_instance) |
82 | 94 | end |
83 | 95 |
|
84 | 96 | return function(auto_ssl_instance) |
| 97 | + if not ngx.shared.auto_ssl_settings then |
| 98 | + ngx.log(ngx.ERR, "auto-ssl: dict auto_ssl_settings could not be found. Please add it to your configuration: `lua_shared_dict auto_ssl_settings 64k;`") |
| 99 | + end |
| 100 | + |
85 | 101 | check_dependencies() |
86 | 102 | generate_hook_sever_secret() |
87 | 103 | generate_config(auto_ssl_instance) |
|
0 commit comments