Skip to content

Commit cee3eea

Browse files
committed
Update docs on ssl_options to try and clarify general usage.
This also better documents the other existing arguments to the callback functions that can be customized.
1 parent 482fd41 commit cee3eea

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

README.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,22 @@ A function that determines whether the incoming domain should automatically issu
144144

145145
By default, resty-auto-ssl will not perform any SSL registrations until you define the `allow_domain` function. You may return `true` to handle all possible domains, but be aware that bogus SNI hostnames can then be used to trigger an indefinite number of SSL registration attempts (which will be rejected). A better approach may be to whitelist the allowed domains in some way.
146146

147+
The callback function's arguments are:
148+
149+
- `domain`: The domain of the incoming request.
150+
- `auto_ssl`: The current auto-ssl instance.
151+
- `ssl_options`: A table of optional configuration options that were passed to the [`ssl_configuration` function](#ssl_certificate-configuration). This can be used to customize the behavior on a per nginx `server` basis (see example in [`request_domain`](#request_domain)).
152+
147153
When using the Redis storage adapter, you can access the current Redis connection inside the `allow_domain` callback by accessing `auto_ssl.storage.adapter:get_connection()`.
148154

149155
*Example:*
150156

151157
```lua
152-
auto_ssl:set("allow_domain", function(domain, auto_ssl)
158+
auto_ssl:set("allow_domain", function(domain, auto_ssl, ssl_options)
153159
return ngx.re.match(domain, "^(example.com|example.net)$", "ijo")
154160
end)
155161
```
156162

157-
Use `ssl_options` to make the behavior vary based on port - see the example in listed for `request_domain` for details.
158-
159163
### `dir`
160164
*Default:* `/etc/resty-auto-ssl`
161165

@@ -219,6 +223,11 @@ auto_ssl:set("redis", {
219223

220224
A function that determines the hostname of the request. By default, the SNI domain is used, but a custom function can be implemented to determine the domain name for non-SNI requests (by basing the domain on something that can be determined outside of SSL, like the port or IP address that received the request).
221225

226+
The callback function's arguments are:
227+
228+
- `ssl`: An instance of the [`ngx.ssl`](https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/ssl.md) module.
229+
- `ssl_options`: A table of optional configuration options that were passed to the [`ssl_configuration` function](#ssl_certificate-configuration). This can be used to customize the behavior on a per nginx `server` basis.
230+
222231
*Example:*
223232

224233
This example, along with the accompanying nginx `server` blocks, will default to SNI domain names, but for non-SNI clients will respond with predefined hosts based on the connecting port. Connections to port 9000 will register and return a certificate for `foo.example.com`, while connections to port 9001 will register and return a certificate for `bar.example.com`. Any other ports will return the default nginx fallback certificate.
@@ -292,18 +301,26 @@ auto_ssl:set("json_adapter", "resty.auto-ssl.json_adapters.dkjson")
292301

293302
## `ssl_certificate` Configuration
294303

304+
The `ssl_certificate` function accepts an optional table of configuration options. These options can be used to customize and control the SSL behavior on a per nginx `server` basis. Some built-in options may control the default behavior of lua-resty-auto-ssl, but any other custom data can be given as options, which will then be passed along to the [`allow_domain`](#allow_domain) and [`request_domain`](#request_domain) callback functions.
305+
306+
Built-in configuration options:
307+
295308
### `generate_certs`
296309
*Default:* true
297310

298311
This variable can be used to disable generating certs on a per server block location.
299312

300313
*Example:*
301314

302-
```lua
303-
auto_ssl:ssl_certificate({ generate_certs = false })
315+
```nginx
316+
server {
317+
listen 8443 ssl;
318+
ssl_certificate_by_lua_block {
319+
auto_ssl:ssl_certificate({ generate_certs = false })
320+
}
321+
}
304322
```
305323

306-
307324
### Advanced Let's Encrypt Configuration
308325

309326
Internally, lua-resty-auto-ssl uses [dehydrated](https://github.com/lukas2511/dehydrated) as it's Let's Encrypt client. If you'd like to adjust lower-level settings, like the private key size, public key algorithm, or your registration e-mail, these settings can be configured in a custom dehydrated configuration file.

lib/resty/auto-ssl.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function _M.new(options)
2323
end
2424

2525
if not options["allow_domain"] then
26-
options["allow_domain"] = function(domain) -- luacheck: ignore
26+
options["allow_domain"] = function(domain, auto_ssl, ssl_options) -- luacheck: ignore
2727
return false
2828
end
2929
end

0 commit comments

Comments
 (0)