From 77ce7aa5e79980d2ae6f9be7d321156870edc53a Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Sun, 1 Sep 2024 07:45:59 -0500 Subject: [PATCH] r/minio-backups-cert: Certbot for MinIO+nginx The MinIO server for backups has special requirements for HTTPS. I want to use subdomains for bucket names, so the certificate must have a wildcard name, which requires using the DNS-01 challenge. Fortunately, it is actually pretty easy to use `nsupdate` with GSS-TSIG authentication to automate DNS record creation, and by default, all domain-member machines can create any records. Thus, using the `manual` auth plugin for `certbot` and a script to run `nsupdate`, obtaining the wildcard certificate is fairly straightforward. The biggest issue I encountered while developing this feature was caching of NXDOMAIN responses. There doesn't seem to be a way to change the TTL of the SOA record of the Active Directory DNS domain, which defaults to 3600, meaning NXDOMAIN responses are always cached for an hour. When adding a record using `nsupdate -g`, the tool always performs a SOA lookup of new name to find the target zone for it. Since the name does not exist yet, the domain controller responds with NXDOMAIN, which gets cached by the main DNS server. Thus, even after adding the record, the ACME server will not be able to resolve the name for up to an hour. We can a void this by explicitly setting the target zone. That would not work in a multi-domain forest, but fortunately, we do not have to worry about that. This role borrows some logic from the *postgresql-cert* role. Eventually, I probably want to combine some of the steps from both of these roles, possibly replacing the old *certbot* role. --- roles/minio-backups-cert/files/deploy-hook.sh | 3 + .../minio-backups-cert/files/nsupdate-auth.sh | 19 +++++ .../files/nsupdate-cleanup.sh | 11 +++ roles/minio-backups-cert/handlers/main.yml | 8 ++ roles/minio-backups-cert/tasks/main.yml | 80 +++++++++++++++++++ .../templates/certbot-renew.timer.j2 | 3 + roles/minio-backups-cert/vars/main.yml | 2 + 7 files changed, 126 insertions(+) create mode 100644 roles/minio-backups-cert/files/deploy-hook.sh create mode 100755 roles/minio-backups-cert/files/nsupdate-auth.sh create mode 100755 roles/minio-backups-cert/files/nsupdate-cleanup.sh create mode 100644 roles/minio-backups-cert/handlers/main.yml create mode 100644 roles/minio-backups-cert/tasks/main.yml create mode 100644 roles/minio-backups-cert/templates/certbot-renew.timer.j2 create mode 100644 roles/minio-backups-cert/vars/main.yml diff --git a/roles/minio-backups-cert/files/deploy-hook.sh b/roles/minio-backups-cert/files/deploy-hook.sh new file mode 100644 index 0000000..0964002 --- /dev/null +++ b/roles/minio-backups-cert/files/deploy-hook.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +systemctl reload nginx diff --git a/roles/minio-backups-cert/files/nsupdate-auth.sh b/roles/minio-backups-cert/files/nsupdate-auth.sh new file mode 100755 index 0000000..720bfa2 --- /dev/null +++ b/roles/minio-backups-cert/files/nsupdate-auth.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +export KRB5CCNAME=/run/certbot.krb5_ccache +klist -s || net ads kerberos kinit -P || exit +nsupdate -g <