mirror of https://github.com/breard-r/acmed.git
Browse Source
introduce a 'nginx' hook
introduce a 'nginx' hook
- introduce an nginx hook
the hook will resolve the new environment variables
* NGINX_CONFDIR -> default: /etc/nginx/conf.d
* NGINX_CHALLENGE_LOCTION -> default: 001-challenge-letsencrypt.conf
* NGINX_TLS_CERTIFICATE -> default:002-tls-certificates.conf
- group: nginx-config-challenge-location
this will generate -> $NGINX_CONFDIR/$NGINX_CHALLENGE_LOCATION
- group: nginx-config-certificate-location
this will generate -> $NGINX_CONFDIR/$NGINX_TLS_CERTIFICATE
ACMEd amims to minimize the amount of ReadWrite directories. The systemd.unit
(acmed.service), takes advantage of sandbox capabilities.
For nginx support, we need to ReadWrite to $NGINX_CONFDIR. Since
we are running with uid/gid of 'acmed' and probably aren't
authorized, an user with administrative rights need to call once
chmod g+w $NGINX_CONFIR
on systemd managed systems, we are able to correct/rewrite the directory
rights at installation time (tmpfiles.d/acmed.conf).
A website admin needs to include
* $NGINX_CHALLENGE_LOCATION and
* $NGINX_TLS_CERTIFICATE
inside the [virtual-]host configuration block of websites to
activate the templates (non automated task)
- adapt acmed.service
will hint to NGINX environment variables
defaults are handled inside the nginx hook
- adapt tempfiles.d/acmed.conf
preset default directory to store challenges (if acmed isn't started
via systemd)
- adapat Makefile
add nginx_hooks.toml
Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
pull/46/head
No known key found for this signature in database
GPG Key ID: D17312FD44A71C23
5 changed files with 152 additions and 8 deletions
-
1Makefile
-
1acmed/config/acmed.toml
-
130acmed/config/nginx_hooks.toml
-
21contrib/acmed.service
-
7contrib/tmpfiles.d/acmed.conf
@ -0,0 +1,130 @@ |
|||
# Copyright (c) 2021 Rodolphe Bréard <rodolphe@breard.tf> |
|||
# |
|||
# Copying and distribution of this file, with or without modification, |
|||
# are permitted in any medium without royalty provided the copyright |
|||
# notice and this notice are preserved. This file is offered as-is, |
|||
# without any warranty. |
|||
|
|||
# ------------------------------------------------------------------------ |
|||
# ACMEd hooks adapting nginx configuration |
|||
# You should not edit this file since it may be overridden by a newer one. |
|||
# ------------------------------------------------------------------------ |
|||
|
|||
|
|||
### |
|||
# nginx file storing challenge root in "/etc/nginx/conf.d/{{challenge-location}}/" |
|||
# env: NGINX_CONFDIR -> /etc/nginx/conf.d |
|||
# env: NGINX_CHALLENGE_LOCTION -> 001-challenge-letsencrypt.conf |
|||
### |
|||
|
|||
[[hook]] |
|||
name = "nginx-config-challenge-location-chmod" |
|||
type = ["challenge-http-01", "post-operation"] |
|||
cmd = "chmod" |
|||
args = [ |
|||
"ug+rw", |
|||
"{{#if env.NGINX_CONFDIR}}{{env.NGINX_CONFDIR}}{{else}}/etc/nginx/conf.d{{/if}}/{{#if env.NGINX_CHALLENGE_LOCATION}}{{env.NGINX_CHALLENGE_LOCATION}}{{else}}001-challenge-letsencrypt.conf{{/if}}" |
|||
] |
|||
allow_failure = true |
|||
|
|||
[[hook]] |
|||
name = "nginx-config-challenge-location-create" |
|||
type = ["challenge-http-01", "post-operation"] |
|||
cmd = "cat" |
|||
args = [ "-" ] |
|||
stdin_str = """### |
|||
# Let's Encrypt: acme-challenge location |
|||
### |
|||
|
|||
location ^~ /.well-known/acme-challenge/ { |
|||
allow all; |
|||
root "{{#if env.HTTP_ROOT}}{{env.HTTP_ROOT}}{{else}}/var/lib/acmed/domains{{/if}}"; |
|||
default_type "text/plain"; |
|||
try_files $uri =404; |
|||
} |
|||
""" |
|||
stdout = "{{#if env.NGINX_CONFDIR}}{{env.NGINX_CONFDIR}}{{else}}/etc/nginx/conf.d{{/if}}/{{#if env.NGINX_CHALLENGE_LOCATION}}{{env.NGINX_CHALLENGE_LOCATION}}{{else}}001-challenge-letsencrypt.conf{{/if}}" |
|||
|
|||
[[hook]] |
|||
name = "nginx-config-challenge-location-echo" |
|||
type = ["challenge-http-01", "post-operation"] |
|||
cmd = "echo" |
|||
args = [ |
|||
"{{#if env.NGINX_CONFDIR}}{{env.NGINX_CONFDIR}}{{else}}/etc/nginx/conf.d{{/if}}/{{#if env.NGINX_CHALLENGE_LOCATION}}{{env.NGINX_CHALLENGE_LOCATION}}{{else}}001-challenge-letsencrypt.conf{{/if}}" |
|||
] |
|||
allow_failure = true |
|||
|
|||
[[group]] |
|||
name = "nginx-config-challenge-location" |
|||
# hook execution in order of definition |
|||
hooks = [ |
|||
"nginx-config-challenge-location-create", |
|||
"nginx-config-challenge-location-echo", |
|||
"nginx-config-challenge-location-chmod" |
|||
] |
|||
|
|||
### |
|||
# nginx reference to TLS certificates |
|||
# env NGINX_TLS_CERTIFICATE -> 002-tls-certificates.conf |
|||
# global: {{certificates_directory}} |
|||
# certificate: {{name}}_{{key_type}}.{{file_type}}.{{ext}} |
|||
### |
|||
|
|||
[[hook]] |
|||
name = "nginx-config-certificate-location-chmod" |
|||
type = ["challenge-http-01", "post-operation"] |
|||
cmd = "chmod" |
|||
args = [ |
|||
"ug+rw", |
|||
"{{#if env.NGINX_CONFDIR}}{{env.NGINX_CONFDIR}}{{else}}/etc/nginx/conf.d{{/if}}/{{#if env.NGINX_TLS_CERTIFICATE}}{{env.NGINX_TLS_CERTIFICATE}}{{else}}002-tls-certificates.conf{{/if}}" |
|||
] |
|||
allow_failure = true |
|||
|
|||
[[hook]] |
|||
name = "nginx-config-certificate-location-create" |
|||
type = ["challenge-http-01", "post-operation"] |
|||
cmd = "cat" |
|||
args = [ "-" ] |
|||
## TODO |
|||
# make following handlebars accessible in post-operation |
|||
# ssl_certificate {{certificates_directory}}/{{name}}_{{key_type}}.crt.{{ext}}; |
|||
# ssl_certificate_key {{certificates_directory}}/{{name}}_{{key_type}}.pk.{{ext}}; |
|||
# workaround: define a env:ACMED_CERTS pointing to {{certificates_directory}} |
|||
## |
|||
stdin_str = """### |
|||
# Let's Encrypt TLS certificats |
|||
### |
|||
|
|||
ssl_certificate {{#if env.ACMED_CERTS}}{{env.ACMED_CERTS}}{{else}}/var/lib/acmed/certs{{/if}}/{{identifiers.[0]}}_{{key_type}}.crt.pem; # managed by ACMEd |
|||
ssl_certificate_key {{#if env.ACMED_CERTS}}{{env.ACMED_CERTS}}{{else}}/var/lib/acmed/certs{{/if}}/{{identifiers.[0]}}_{{key_type}}.pk.pem; # managed by ACMEd |
|||
|
|||
ssl_session_cache shared:le_nginx_SSL:10m; |
|||
ssl_session_timeout 1440m; |
|||
ssl_session_tickets off; |
|||
|
|||
ssl_protocols TLSv1.2 TLSv1.3; |
|||
ssl_prefer_server_ciphers off; |
|||
|
|||
ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-PO |
|||
LY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384'; |
|||
""" |
|||
stdout = "{{#if env.NGINX_CONFDIR}}{{env.NGINX_CONFDIR}}{{else}}/etc/nginx/conf.d{{/if}}/{{#if env.NGINX_TLS_CERTIFICATE}}{{env.NGINX_TLS_CERTIFICATE}}{{else}}002-tls-certificates.conf{{/if}}" |
|||
allow_failure = true |
|||
|
|||
[[hook]] |
|||
name = "nginx-config-certificate-location-echo" |
|||
type = ["challenge-http-01", "post-operation"] |
|||
cmd = "echo" |
|||
args = [ |
|||
"{{#if env.NGINX_CONFDIR}}{{env.NGINX_CONFDIR}}{{else}}/etc/nginx/conf.d{{/if}}/{{#if env.NGINX_TLS_CERTIFICATE}}{{env.NGINX_TLS_CERTIFICATE}}{{else}}002-tls-certificates.conf{{/if}}" |
|||
] |
|||
allow_failure = true |
|||
|
|||
[[group]] |
|||
name = "nginx-config-certificate-location" |
|||
# hook execution in order of definition |
|||
hooks = [ |
|||
"nginx-config-certificate-location-create", |
|||
"nginx-config-certificate-location-echo", |
|||
"nginx-config-certificate-location-chmod" |
|||
] |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue