diff --git a/deploy/panel.env.example b/deploy/panel.env.example index 25f85f6..90ed0f3 100644 --- a/deploy/panel.env.example +++ b/deploy/panel.env.example @@ -9,6 +9,7 @@ COULOBRE_DB_PASSWORD= COULOBRE_DB_HOST=/run/mysqld/mysqld.sock COULOBRE_BROKER_URL=amqp://coulobre:@127.0.0.1:5672/coulobre # COULOBRE_LOCAL_WEB_ACTIVATION=1 +# COULOBRE_LOCAL_WEB_HTTPS=1 # COULOBRE_LOCAL_DATABASE_PROVISIONING=1 # COULOBRE_LOCAL_DNS_PUBLISHING=1 # COULOBRE_LOCAL_MAILBOX_PROVISIONING=1 diff --git a/deploy/systemd/coulobre-https-apply.socket b/deploy/systemd/coulobre-https-apply.socket new file mode 100644 index 0000000..841960c --- /dev/null +++ b/deploy/systemd/coulobre-https-apply.socket @@ -0,0 +1,14 @@ +[Unit] +Description=Coulobre local website HTTPS socket + +[Socket] +ListenStream=/run/coulobre-https-apply.sock +SocketUser=root +SocketGroup=coulobre-https-provisioning +SocketMode=0660 +Accept=yes +MaxConnections=1 +RemoveOnStop=true + +[Install] +WantedBy=sockets.target diff --git a/deploy/systemd/coulobre-https-apply@.service b/deploy/systemd/coulobre-https-apply@.service new file mode 100644 index 0000000..542b3eb --- /dev/null +++ b/deploy/systemd/coulobre-https-apply@.service @@ -0,0 +1,20 @@ +[Unit] +Description=Coulobre local website HTTPS request +After=apache2.service php8.5-fpm.service +CollectMode=inactive-or-failed + +[Service] +Type=exec +User=root +WorkingDirectory=/opt/coulobre +UMask=0022 +ExecStart=/opt/coulobre/bin/coulobre-web-node https-request +StandardInput=socket +StandardOutput=socket +StandardError=journal +RuntimeMaxSec=3min +KillSignal=SIGINT +KillMode=mixed +NoNewPrivileges=true +PrivateTmp=true +ProtectHome=true diff --git a/deploy/systemd/coulobre-https-provisioner.service b/deploy/systemd/coulobre-https-provisioner.service new file mode 100644 index 0000000..7d253c3 --- /dev/null +++ b/deploy/systemd/coulobre-https-provisioner.service @@ -0,0 +1,26 @@ +[Unit] +Description=Coulobre Panel website HTTPS worker +Requires=coulobre-https-apply.socket +Wants=network-online.target +After=network-online.target coulobre-https-apply.socket mariadb.service rabbitmq-server.service + +[Service] +Type=exec +User=coulobre-https-provisioner +Group=coulobre-https-provisioner +SupplementaryGroups=coulobre-https-provisioning +EnvironmentFile=/etc/coulobre/panel.env +WorkingDirectory=/opt/coulobre +UMask=0077 +ExecStart=/opt/coulobre/bin/celery -A coulobre worker --loglevel=INFO --queues=coulobre-web-https --hostname=https-provisioner@%H --concurrency=1 +KillMode=mixed +TimeoutStopSec=4min +Restart=on-failure +RestartSec=5s +NoNewPrivileges=true +PrivateTmp=true +ProtectHome=true +ProtectSystem=strict + +[Install] +WantedBy=multi-user.target diff --git a/docs/deployment.md b/docs/deployment.md index a5a2930..dab51f2 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -219,6 +219,48 @@ 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) +### Request HTTPS from the panel + +Set up Apache's HTTP-01 webroot and the Certbot renewal hook on the local +web node. Register a Certbot account if this node does not already have one, +using an email address monitored by the operator. +[Hosted website HTTPS setup](development.md#enable-https-for-a-hosted-website) + +```sh +sudo certbot register --email hostmaster@example.org --agree-tos +sudo groupadd --system coulobre-https-provisioning +sudo useradd --system --user-group --no-create-home --home-dir /nonexistent \ + --shell /usr/sbin/nologin coulobre-https-provisioner +sudo install -m 0644 deploy/systemd/coulobre-https-apply.socket \ + deploy/systemd/coulobre-https-apply@.service \ + deploy/systemd/coulobre-https-provisioner.service /etc/systemd/system/ +sudo systemctl daemon-reload +``` + +Set `COULOBRE_LOCAL_WEB_HTTPS=1` in `/etc/coulobre/panel.env`, then apply +pending migrations and restart the panel services. + +```sh +panel_manage migrate --noinput +sudo systemctl restart coulobre-panel coulobre-worker coulobre-beat +sudo systemctl enable --now coulobre-https-apply.socket \ + coulobre-https-provisioner.service +``` + +On an active site's Apache preview, select **Enable HTTPS** and use +**Refresh status** to follow the request. This requires the **Can add +website HTTPS request** permission and access to view hosting accounts +and web provisioning plans. The worker uses the manifest's primary +domain and keeps Certbot logs and credentials on the web node. If the +request fails, check the diagnostic and use **Retry HTTPS** after +resolving the problem. Certbot handles later renewals. + +The panel uses HTTP-01 for initial issuance. For DNS validation, obtain +the certificate on the web node with its configured Certbot DNS plugin +and the expected lineage name. The panel can then enable HTTPS using +that certificate. Certbot renews it with its saved authenticator. +[Certbot DNS plugins](https://eff-certbot.readthedocs.io/en/stable/using.html#dns-plugins) + ## 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 3299dde..fe65d94 100644 --- a/docs/development.md +++ b/docs/development.md @@ -727,6 +727,11 @@ 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) +To request and enable HTTPS from the panel, set up the dedicated socket +and worker on the local web node. They use the same Certbot webroot, +lineage name, and renewal hook. +[Panel HTTPS setup](deployment.md#request-https-from-the-panel) + ### Enable local web activation On a web node with the same Apache and PHP-FPM setup, systemd can accept local diff --git a/src/coulobre/hosting/migrations/0018_web_https.py b/src/coulobre/hosting/migrations/0018_web_https.py new file mode 100644 index 0000000..e2a36bf --- /dev/null +++ b/src/coulobre/hosting/migrations/0018_web_https.py @@ -0,0 +1,50 @@ +# Generated by Django 5.2.19 on 2026-11-21 01:46 + +import django.db.models.deletion +import django.utils.timezone +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("hosting", "0017_customer_impersonation"), + ] + + operations = [ + migrations.CreateModel( + name="WebHTTPS", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "requested_at", + models.DateTimeField(default=django.utils.timezone.now), + ), + ( + "last_dispatched_at", + models.DateTimeField(blank=True, null=True), + ), + ("started_at", models.DateTimeField(blank=True, null=True)), + ("finished_at", models.DateTimeField(blank=True, null=True)), + ("problem", models.TextField(blank=True)), + ( + "plan", + models.OneToOneField( + on_delete=django.db.models.deletion.CASCADE, + related_name="https", + to="hosting.webprovisioningplan", + ), + ), + ], + options={ + "verbose_name": "website HTTPS request", + }, + ), + ] diff --git a/src/coulobre/hosting/models.py b/src/coulobre/hosting/models.py index 2bd3e9c..0ebbbde 100644 --- a/src/coulobre/hosting/models.py +++ b/src/coulobre/hosting/models.py @@ -290,6 +290,15 @@ class WebProvisioningPlan(models.Model): and self.primary_domain == self.account.primary_domain ) + @property + def can_enable_https(self): + activation = getattr(self, "activation", None) + return ( + self.can_export + and activation is not None + and activation.state == "configured" + ) + class ProvisioningJobManager(models.Manager): def queue(self, **target): @@ -334,6 +343,15 @@ class WebActivation(ProvisioningJob): ) +class WebHTTPS(ProvisioningJob): + plan = models.OneToOneField( + WebProvisioningPlan, on_delete=models.CASCADE, related_name="https" + ) + + class Meta: + verbose_name = "website HTTPS request" + + class DatabaseProvisioning(ProvisioningJob): database = models.OneToOneField( HostingDatabase, on_delete=models.CASCADE, related_name="provisioning" diff --git a/src/coulobre/hosting/node_client.py b/src/coulobre/hosting/node_client.py index b4a2e4e..b246da1 100644 --- a/src/coulobre/hosting/node_client.py +++ b/src/coulobre/hosting/node_client.py @@ -10,6 +10,12 @@ def activate_local_site(site): ) +def enable_local_https(site): + apply_on_local_node( + site, "/run/coulobre-https-apply.sock", "web node", "HTTPS request" + ) + + def provision_local_database(database): apply_on_local_node( database, diff --git a/src/coulobre/hosting/tasks.py b/src/coulobre/hosting/tasks.py index d61d12b..72586af 100644 --- a/src/coulobre/hosting/tasks.py +++ b/src/coulobre/hosting/tasks.py @@ -13,10 +13,12 @@ from .models import ( DnsPublication, MailboxProvisioning, WebActivation, + WebHTTPS, WebProvisioningPlan, ) from .node_client import ( activate_local_site, + enable_local_https, provision_local_database, provision_local_mailbox, publish_local_zone, @@ -24,6 +26,7 @@ from .node_client import ( REDISPATCH_AFTER = timedelta(minutes=5) WEB_ACTIVATION_QUEUE = "coulobre-web-activation" +WEB_HTTPS_QUEUE = "coulobre-web-https" DATABASE_PROVISIONING_QUEUE = "coulobre-database-provisioning" DNS_PUBLISHING_QUEUE = "coulobre-dns-publishing" MAILBOX_PROVISIONING_QUEUE = "coulobre-mailbox-provisioning" @@ -72,6 +75,12 @@ def dispatch_web_activations(): ) +@shared_task +def dispatch_web_https(): + if settings.LOCAL_WEB_HTTPS: + dispatch_provisioning_jobs(WebHTTPS, enable_web_https, WEB_HTTPS_QUEUE) + + @shared_task def dispatch_database_provisioning(): if settings.LOCAL_DATABASE_PROVISIONING: @@ -139,6 +148,27 @@ def apply_web_activation(activation): activate_local_site(WebSite(plan.account_id, plan.primary_domain)) +@shared_task(acks_late=True, reject_on_worker_lost=True) +def enable_web_https(request_id): + if settings.LOCAL_WEB_HTTPS: + run_provisioning_job( + WebHTTPS.objects.select_related( + "plan__account", "plan__activation" + ), + request_id, + apply_web_https, + "Could not contact the local HTTPS service. " + "Check its socket and try again.", + ) + + +def apply_web_https(provisioning): + plan = provisioning.plan + if not plan.can_enable_https: + raise ValueError("Activate the site for the current domain first.") + enable_local_https(WebSite(plan.account_id, plan.primary_domain)) + + @shared_task(acks_late=True, reject_on_worker_lost=True) def provision_database(provisioning_id): if settings.LOCAL_DATABASE_PROVISIONING: diff --git a/src/coulobre/hosting/templates/hosting/plan_detail.html b/src/coulobre/hosting/templates/hosting/plan_detail.html index eb5dc4c..7de41d2 100644 --- a/src/coulobre/hosting/templates/hosting/plan_detail.html +++ b/src/coulobre/hosting/templates/hosting/plan_detail.html @@ -7,7 +7,7 @@
{{ provisioning.problem }}
{% endif %} +