From 3be2f8fd0709d627f1b089dcdd508b6ac410dc22 Mon Sep 17 00:00:00 2001 From: Peter van Arkel Date: Sat, 21 Nov 2026 02:43:29 +0100 Subject: [PATCH] Add Certbot webroot setup and Apache renewal hook --- .gitea/workflows/ci.yml | 1 + deploy/apache/acme.conf.example | 7 ++++ deploy/certbot/reload-apache.sh | 14 ++++++++ docs/deployment.md | 7 ++++ docs/development.md | 58 +++++++++++++++++++++++++++++++++ 5 files changed, 87 insertions(+) create mode 100644 deploy/apache/acme.conf.example create mode 100755 deploy/certbot/reload-apache.sh diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 1bf9ee7..86d0ab4 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -43,6 +43,7 @@ jobs: ruff check . ruff format --check . sh -n tests/web-node/smoke.sh + sh -n deploy/certbot/reload-apache.sh - name: Check Django configuration and migrations run: | diff --git a/deploy/apache/acme.conf.example b/deploy/apache/acme.conf.example new file mode 100644 index 0000000..eeb05df --- /dev/null +++ b/deploy/apache/acme.conf.example @@ -0,0 +1,7 @@ +Alias "/.well-known/acme-challenge/" "/var/www/coulobre-acme/.well-known/acme-challenge/" + + + AllowOverride None + Options None + Require all granted + diff --git a/deploy/certbot/reload-apache.sh b/deploy/certbot/reload-apache.sh new file mode 100755 index 0000000..77ff5d8 --- /dev/null +++ b/deploy/certbot/reload-apache.sh @@ -0,0 +1,14 @@ +#!/bin/sh +set -eu + +case "${RENEWED_LINEAGE:-}" in + /etc/letsencrypt/live/coulobre-*) + lock=/var/lib/coulobre/web-node/apply.lock + if [ -f "$lock" ]; then + exec 9<"$lock" + flock -x 9 + /usr/sbin/apache2ctl configtest 2>&1 + /usr/sbin/service apache2 reload + fi + ;; +esac diff --git a/docs/deployment.md b/docs/deployment.md index 3a7b10c..a5a2930 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -212,6 +212,13 @@ The worker applies the domain shown in the preview. If the account's primary domain changes before the worker starts, create a preview for the new domain. An existing web node reservation stays bound to the domain it was created for. +## Enable HTTPS for hosted websites + +Once a site is active, obtain the website certificate with Certbot on the +web node and enable its HTTPS virtual host. Each site uses its own +certificate. The renewal hook reloads Apache after Certbot renews it. +[Hosted website HTTPS setup](development.md#enable-https-for-a-hosted-website) + ## Provision local databases from the panel Enable the [database provisioning socket](development.md#enable-local-database-provisioning) diff --git a/docs/development.md b/docs/development.md index d6288c7..3299dde 100644 --- a/docs/development.md +++ b/docs/development.md @@ -670,6 +670,63 @@ The status command reads local state. It exits with code 0 for `configured`, code 2 for the other report states, and code 1 if it cannot read the manifest or inspect the node. Use an HTTP request to verify the site's response as well. +### Enable HTTPS for a hosted website + +Apply the web deployment manifest first. Use Certbot to obtain and renew +the website's Let's Encrypt certificate. The HTTP-01 challenge requires +public DNS for the domain and an inbound connection on port 80. If a +reverse proxy handles that port, forward `/.well-known/acme-challenge/` +for the domain to the web node, preserving the host and path. +[Let's Encrypt challenge types](https://letsencrypt.org/docs/challenge-types/) + +Prepare Apache and the shared challenge directory once per web node. +Apache serves challenge files from this directory, which the web node +operator controls. + +```sh +sudo apt install certbot +sudo a2enmod ssl +sudo install -d -m 0755 /var/www/coulobre-acme/.well-known/acme-challenge +sudo install -m 0644 deploy/apache/acme.conf.example \ + /etc/apache2/conf-available/coulobre-acme.conf +sudo a2enconf coulobre-acme +sudo apache2ctl configtest +sudo systemctl reload apache2 +``` + +Use the manifest's account ID for the Certbot certificate name and its +primary domain for the certificate hostname. Keep Certbot's private key +root-owned with mode `0600`. Apache uses the managed Certbot lineage on +port 443, with the same document root and PHP-FPM pool as the HTTP site. + +```sh +sudo certbot certonly --webroot --webroot-path /var/www/coulobre-acme \ + --cert-name coulobre-1 --domains example.org +sudo /opt/coulobre/bin/coulobre-web-node enable-https coulobre-web-plan-1.json +sudo /opt/coulobre/bin/coulobre-web-node https-status coulobre-web-plan-1.json +curl --fail https://example.org/ +``` + +`https-status` checks the local virtual host and certificate on disk. +An HTTPS request verifies the certificate and response clients receive. +HTTP remains available for the site and future HTTP-01 challenges. + +Install the renewal hook and check the Certbot timer. After a successful +renewal of a Coulobre certificate, the hook validates the Apache +configuration and reloads the service. + +```sh +sudo install -D -m 0755 deploy/certbot/reload-apache.sh \ + /etc/letsencrypt/renewal-hooks/deploy/coulobre-apache +systemctl status certbot.timer +sudo certbot renew --dry-run --run-deploy-hooks --cert-name coulobre-1 +``` + +For a public domain that cannot accept inbound HTTP on port 80, Certbot +can use a DNS plugin for validation. Request the certificate under the +same lineage name before running `enable-https`. +[Certbot certificate guide](https://eff-certbot.readthedocs.io/en/stable/using.html) + ### Enable local web activation On a web node with the same Apache and PHP-FPM setup, systemd can accept local @@ -741,6 +798,7 @@ fixtures. Then run the checks from the repository root. ruff check . ruff format --check . sh -n tests/web-node/smoke.sh +sh -n deploy/certbot/reload-apache.sh python manage.py check python manage.py makemigrations --check --dry-run python manage.py test coulobre