r/samba-cert: Obtain LDAP/TLS cert via ACME

The *samba-cert* role configures `lego` and HAProxy to obtain an X.509
certificate via the ACME HTTP-01 challenge.  HAProxy is necessary
because LDAP server certificates need to have the apex domain in their
SAN field, and the ACME server may contact *any* domain controller
server with an A record for that name.  HAProxy will forward the
challenge request on to the first available host on port 5000, where
`lego` is listening to provide validation.

Issuing certificates this way has a couple of advantages:

1. No need for the wildcard certificate for the *pyrocufflink.blue*
   domain any more
2. Renewals are automatic and handled by the server itself rather than
   Ansible via scheduled Jenkins job

Item (2) is particularly interesting because it avoids the bi-monthly
issue where replacing the LDAP server certificate and restarting Samba
causes the Jenkins job to fail.

Naturally, for this to work correctly, all LDAP client applications
need to trust the certificates issued by the ACME server, in this case
*DCH Root CA R2*.
This commit is contained in:
2024-06-12 18:33:24 -05:00
parent 7b6e0bd100
commit ffe972d79b
8 changed files with 203 additions and 2 deletions

View File

@@ -0,0 +1,18 @@
[Unit]
Description=Renew Samba LDAP server certificate
Wants=network-online.target
After=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/bin/lego \
--path /var/lib/samba/.lego \
--accept-tos \
--server {{ samba_cert_acme_server }} \
--http --http.port :5000 \
--domains {{ ansible_fqdn }} \
--domains {{ krb5_realm | lower }} \
--email {{ samba_cert_acme_email }} \
renew \
--renew-hook 'systemctl restart samba'
CapabilityBoundingSet=

View File

@@ -0,0 +1,9 @@
[Unit]
Description=Samba LDAP server certificate renewal
[Timer]
OnCalendar=daily
RandomizedDelaySec=12h
[Install]
WantedBy=timers.target

View File

@@ -0,0 +1,30 @@
frontend http
bind *:80
acl acme_challenge path_beg /.well-known/acme-challenge
# Proxy ACME challenge requests to Lego
use_backend lego if acme_challenge
#default_backend web
# Lego listens on port 5000 when it is requresting a certificate via
# ACME. Only one DC can be requesting a certificate at a time, or
# requests may be forwarded to the wrong machine.
#
# It is imperative that the `check` option is NOT enabled for any
# server/template in this back-end, or challenge requests may get lost
# if they are initiated between HAProxy health check intervals.
backend lego
balance roundrobin
server-template dc {{ groups["samba-dc"] | length + 3 }} {{ krb5_realm|lower }}:5000 resolvers local init-addr none
retries 10
option redispatch
retry-on all-retryable-errors 404
# Although there is not currently a use case for it, it is possible to run a
# web server on the apex domain, but it has to listen on an alternate port.
#backend web
# balance roundrobin
# server-template dc 5 {{ krb5_realm|lower }}:8080 resolvers local init-addr none