Skip to content

Commit f80daf7

Browse files
authored
Merge pull request #92 from mklauber/issue-#91
Generate a new certificate unless ssl_options["generate_certs"] == false
2 parents 8227d90 + 620bf07 commit f80daf7

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ http {
133133
}
134134
```
135135

136-
## Configuration
136+
## `auto_ssl` Configuration
137137

138138
Additional configuration options can be set on the `auto_ssl` instance that is created:
139139

@@ -271,6 +271,20 @@ Additional configuration options can be set on the `auto_ssl` instance that is c
271271
auto_ssl:set("hook_server_port", 90)
272272
```
273273

274+
### `ssl_certificate` Configuration
275+
276+
- **`generate_certs`**
277+
*Default:* true
278+
279+
This variable can be used to disable generating certs on a per server block location.
280+
281+
*Example:*
282+
283+
```lua
284+
auto_ssl:ssl_certificate({ generate_certs=false })
285+
```
286+
287+
274288
### Advanced Let's Encrypt Configuration
275289

276290
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/ssl_certificate.lua

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ local function issue_cert(auto_ssl_instance, storage, domain)
9696
return fullchain_pem, privkey_pem, err
9797
end
9898

99-
local function get_cert(auto_ssl_instance, domain)
99+
local function get_cert(auto_ssl_instance, domain, ssl_options)
100100
-- Look for the certificate in shared memory first.
101101
local fullchain_der = ngx.shared.auto_ssl:get("domain:fullchain_der:" .. domain)
102102
local privkey_der = ngx.shared.auto_ssl:get("domain:privkey_der:" .. domain)
@@ -113,9 +113,13 @@ local function get_cert(auto_ssl_instance, domain)
113113
end
114114

115115
-- Finally, issue a new certificate if one hasn't been found yet.
116-
fullchain_pem, privkey_pem = issue_cert(auto_ssl_instance, storage, domain)
117-
if fullchain_pem and privkey_pem then
118-
return convert_to_der_and_cache(domain, fullchain_pem, privkey_pem, true)
116+
if not ssl_options or ssl_options["generate_certs"] ~= false then
117+
fullchain_pem, privkey_pem = issue_cert(auto_ssl_instance, storage, domain)
118+
if fullchain_pem and privkey_pem then
119+
return convert_to_der_and_cache(domain, fullchain_pem, privkey_pem, true)
120+
end
121+
else
122+
return nil, nil, nil, "did not issue certificate, because the generate_certs setting is false"
119123
end
120124

121125
-- Return an error if issuing the certificate failed.
@@ -251,7 +255,7 @@ local function do_ssl(auto_ssl_instance, ssl_options)
251255
end
252256

253257
-- Get or issue the certificate for this domain.
254-
local fullchain_der, privkey_der, newly_issued, get_cert_err = get_cert(auto_ssl_instance, domain)
258+
local fullchain_der, privkey_der, newly_issued, get_cert_err = get_cert(auto_ssl_instance, domain, ssl_options)
255259
if get_cert_err then
256260
ngx.log(ngx.ERR, "auto-ssl: could not get certificate for ", domain, " - using fallback - ", get_cert_err)
257261
return

0 commit comments

Comments
 (0)