Skip to content

Commit 05dafc9

Browse files
committed
ACME: module configuration.
1 parent 3905e22 commit 05dafc9

File tree

14 files changed

+2057
-49
lines changed

14 files changed

+2057
-49
lines changed

Cargo.lock

Lines changed: 358 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ rust-version = "1.81.0"
1010
crate-type = ["cdylib"]
1111

1212
[dependencies]
13+
http = "1.3.1"
14+
openssl = { version = "0.10.73", features = ["bindgen"] }
15+
openssl-foreign-types = { package = "foreign-types", version = "0.3" }
16+
openssl-sys = { version = "0.9.109", features = ["bindgen"] }
17+
siphasher = { version = "1.0.1", default-features = false }
18+
thiserror = { version = "2.0.12", default-features = false }
1319

1420
[dependencies.nginx-sys]
1521
git = "https://github.com/nginx/ngx-rust"

README.md

Lines changed: 205 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ certificate management ([ACME]) protocol.
1010

1111
### Requirements
1212

13-
* Regular nginx build dependencies
14-
* System-wide installation of OpenSSL 1.1.1 or later
15-
* Rust toolchain (1.81.0 or later)
13+
- Regular nginx build dependencies
14+
- System-wide installation of OpenSSL 1.1.1 or later
15+
- Rust toolchain (1.81.0 or later)
1616

1717
### Commands
1818

@@ -25,24 +25,224 @@ cd nginx-acme
2525
export NGINX_BUILD_DIR=$(realpath ../nginx/objs)
2626
cargo build --release
2727
```
28+
2829
The result will be located at `target/release/libnginx_acme.so`.
2930

3031
Another way is to use the provided config script:
32+
3133
```sh
3234
# in the nginx source directory
3335
auto/configure \
3436
--with-compat \
3537
--with-http_ssl_module \
3638
--add-[dynamic-]module=/path/to/nginx-acme
3739
```
40+
3841
The result will be located at `$NGX_OBJS/ngx_http_acme_module.so`.
3942

4043
Currently this method produces a slightly larger library, as we don't instruct
41-
the linker to perform dead code elimination.
44+
the linker to perform LTO and dead code elimination.
4245

4346
## How to Use
4447

45-
To be added later.
48+
Add the moduel to the nginx configuration and configure as described below.
49+
50+
## Example Configuration
51+
52+
53+
```nginx
54+
resolver 127.0.0.1;
55+
56+
acme_issuer example {
57+
uri https://acme.example.com/directory;
58+
contact mailto:[email protected];
59+
state_path /var/lib/nginx/acme-example;
60+
}
61+
62+
acme_shared_zone 1M;
63+
64+
server {
65+
server_name .example.test;
66+
67+
acme_certificate .example.test
68+
issuer=example;
69+
70+
ssl_certificate $acme_certificate;
71+
ssl_certificate_key $acme_certificate_key;
72+
}
73+
74+
```
75+
76+
## Directives
77+
78+
### acme_issuer
79+
80+
**Syntax:** acme_issuer `name`
81+
82+
**Default:** -
83+
84+
**Context:** http
85+
86+
Defines an ACME certificate issuer object.
87+
88+
### uri
89+
90+
**Syntax:** uri `uri`
91+
92+
**Default:** -
93+
94+
**Context:** acme_issuer
95+
96+
The [directory URL](https://www.rfc-editor.org/rfc/rfc8555#section-7.1.1)
97+
of the ACME server. This is the only mandatory parameter in the
98+
[](#acme_issuer) block.
99+
100+
### account_key
101+
102+
**Syntax:** account_key `alg[:size]` | `file`
103+
104+
**Default:** -
105+
106+
**Context:** acme_issuer
107+
108+
The account's private key used for request authentication.
109+
Accepted values:
110+
111+
- `ecdsa:256/384/521` for `ES256` / `ES384` / `ES512` JSON Web Signature algorithms
112+
- `rsa:2048..4096` for `RS256` .
113+
- File path for an existing key, using one of the algorithms above.
114+
115+
The generated account keys are preserved across reloads, but will be lost on
116+
restart unless [](#state_path) is configured.
117+
118+
### contact
119+
120+
**Syntax:** contact `url`
121+
122+
**Default:** -
123+
124+
**Context:** acme_issuer
125+
126+
An array of URLs that the ACME server can use to contact the client for issues
127+
related to this account.
128+
129+
Can be specified multiple times.
130+
131+
### resolver
132+
133+
**Syntax:** resolver `address` ... [ `valid` = `time` ] [ `ipv4` = `on` | `off` ] [ `ipv6` = `on` | `off` ] [ `status_zone` = `zone` ]
134+
135+
**Default:** -
136+
137+
**Context:** acme_issuer
138+
139+
Configures name servers used to resolve names of upstream servers into
140+
addresses.
141+
See [resolver](https://nginx.org/en/docs/http/ngx_http_core_module.html#resolver)
142+
for the parameter reference.
143+
144+
Required, but can be inherited from the `http` block.
145+
### resolver_timeout
146+
147+
**Syntax:** resolver_timeout `time`
148+
149+
**Default:** 30s
150+
151+
**Context:** acme_issuer
152+
153+
Sets a timeout for name resolution, for example:
154+
155+
```nginx
156+
resolver_timeout 5s;
157+
158+
```
159+
160+
### ssl_trusted_certificate
161+
162+
**Syntax:** ssl_trusted_certificate `file`
163+
164+
**Default:** system CA bundle
165+
166+
**Context:** acme_issuer
167+
168+
Specifies a `file` with trusted CA certificates in the PEM format
169+
used to [verify](#ssl_verify)
170+
the certificate of the ACME server.
171+
172+
### ssl_verify
173+
174+
**Syntax:** ssl_verify `on` | `off`
175+
176+
**Default:** on
177+
178+
**Context:** acme_issuer
179+
180+
Enables or disables verification of the ACME servier certificate.
181+
182+
### state_path
183+
184+
**Syntax:** state_path `path`
185+
186+
**Default:** -
187+
188+
**Context:** acme_issuer
189+
190+
Defines a directory for storing the module data that can be persisted across
191+
restarts. This could greatly improve the time until the server is ready and
192+
help with rate-limiting ACME servers.
193+
194+
The directory, if configured, will contain sensitive content:
195+
the account key, the issued certificates and private keys.
196+
197+
### acme_shared_zone
198+
199+
**Syntax:** acme_shared_zone `size`
200+
201+
**Default:** 262k
202+
203+
**Context:** http
204+
205+
An optional directive that allows increasing the size of in-memory storage of
206+
the module.
207+
The shared memory zone will be used to store the issued certificates, keys and
208+
challenge data for all the configured certificate issuers.
209+
210+
### acme_certificate
211+
212+
**Syntax:** acme_certificate `identifier` ... `issuer` = `issuer_name` [ `key` = `alg[:size]` | `file` ]
213+
214+
**Default:** -
215+
216+
**Context:** server
217+
218+
Defines a certificate with the list of `identifier`s requested from
219+
issuer `issuer_name`.
220+
The `key` parameter sets the type of generated private key or a
221+
path to an existing file. Supported key algorithms and sizes:
222+
`ecdsa:256` (default), `ecdsa:384`,
223+
`ecdsa:521`,
224+
`rsa:2048` .. `rsa:4096`.
225+
226+
> Since 1.27.2, the `key` parameter supports the additional schemes implemented in the
227+
> [ssl_certificate_key](https://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_certificate_key)
228+
> directive: `data:` , `engine:` and more recently `store:` ,
229+
> with a caveat that password-protected keys are not supported.
230+
231+
## Embedded Variables
232+
233+
The `ngx_http_acme_module` module defines following embedded
234+
variables, valid in the `server` block with the
235+
[acme_certificate](#acme_certificate) directive:
236+
237+
### ``$acme_certificate``
238+
239+
SSL certificate that can be passed to the
240+
[ssl_certificate](https://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_certificate).
241+
242+
### ``$acme_certificate_key``
243+
244+
SSL certificate private key that can be passed to the
245+
[ssl_certificate_key](https://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_certificate_key).
46246

47247
## License
48248

build.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,16 @@ fn detect_nginx_features() {
4444
if let Ok(os) = env::var("DEP_NGINX_OS") {
4545
println!("cargo::rustc-cfg=ngx_os=\"{os}\"");
4646
}
47+
48+
// Generate cfg values for version checks
49+
50+
println!("cargo::rustc-check-cfg=cfg(ngx_ssl_cache)");
51+
println!("cargo::rerun-if-env-changed=DEP_NGINX_VERSION_NUMBER");
52+
if let Ok(version) = env::var("DEP_NGINX_VERSION_NUMBER") {
53+
let version: u64 = version.parse().unwrap();
54+
55+
if version >= 1_027_002 {
56+
println!("cargo::rustc-cfg=ngx_ssl_cache");
57+
}
58+
}
4759
}

0 commit comments

Comments
 (0)