Add website HTTPS requests to Coulobre Panel
Coulobre Panel CI / Checks (Python 3.12) (pull_request) Canceled after 0s
Coulobre Panel CI / Checks (Python 3.14) (pull_request) Canceled after 0s

This commit is contained in:
parkel committed 2026-11-21 10:31:32 +01:00
1 parent 43d03d207e
commit 4d6aa0c281
14 files changed
+368 -3

No files matched your search

+1
View File
@@ -9,6 +9,7 @@ COULOBRE_DB_PASSWORD=
COULOBRE_DB_HOST=/run/mysqld/mysqld.sock COULOBRE_DB_HOST=/run/mysqld/mysqld.sock
COULOBRE_BROKER_URL=amqp://coulobre:@127.0.0.1:5672/coulobre COULOBRE_BROKER_URL=amqp://coulobre:@127.0.0.1:5672/coulobre
# COULOBRE_LOCAL_WEB_ACTIVATION=1 # COULOBRE_LOCAL_WEB_ACTIVATION=1
# COULOBRE_LOCAL_WEB_HTTPS=1
# COULOBRE_LOCAL_DATABASE_PROVISIONING=1 # COULOBRE_LOCAL_DATABASE_PROVISIONING=1
# COULOBRE_LOCAL_DNS_PUBLISHING=1 # COULOBRE_LOCAL_DNS_PUBLISHING=1
# COULOBRE_LOCAL_MAILBOX_PROVISIONING=1 # COULOBRE_LOCAL_MAILBOX_PROVISIONING=1
@@ -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
+42
View File
@@ -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. certificate. The renewal hook reloads Apache after Certbot renews it.
[Hosted website HTTPS setup](development.md#enable-https-for-a-hosted-website) [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 ## Provision local databases from the panel
Enable the [database provisioning socket](development.md#enable-local-database-provisioning) Enable the [database provisioning socket](development.md#enable-local-database-provisioning)
+5
View File
@@ -727,6 +727,11 @@ can use a DNS plugin for validation. Request the certificate under the
same lineage name before running `enable-https`. same lineage name before running `enable-https`.
[Certbot certificate guide](https://eff-certbot.readthedocs.io/en/stable/using.html) [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 ### Enable local web activation
On a web node with the same Apache and PHP-FPM setup, systemd can accept local On a web node with the same Apache and PHP-FPM setup, systemd can accept local
@@ -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",
},
),
]
+18
View File
@@ -290,6 +290,15 @@ class WebProvisioningPlan(models.Model):
and self.primary_domain == self.account.primary_domain 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): class ProvisioningJobManager(models.Manager):
def queue(self, **target): 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): class DatabaseProvisioning(ProvisioningJob):
database = models.OneToOneField( database = models.OneToOneField(
HostingDatabase, on_delete=models.CASCADE, related_name="provisioning" HostingDatabase, on_delete=models.CASCADE, related_name="provisioning"
+6
View File
@@ -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): def provision_local_database(database):
apply_on_local_node( apply_on_local_node(
database, database,
+30
View File
@@ -13,10 +13,12 @@ from .models import (
DnsPublication, DnsPublication,
MailboxProvisioning, MailboxProvisioning,
WebActivation, WebActivation,
WebHTTPS,
WebProvisioningPlan, WebProvisioningPlan,
) )
from .node_client import ( from .node_client import (
activate_local_site, activate_local_site,
enable_local_https,
provision_local_database, provision_local_database,
provision_local_mailbox, provision_local_mailbox,
publish_local_zone, publish_local_zone,
@@ -24,6 +26,7 @@ from .node_client import (
REDISPATCH_AFTER = timedelta(minutes=5) REDISPATCH_AFTER = timedelta(minutes=5)
WEB_ACTIVATION_QUEUE = "coulobre-web-activation" WEB_ACTIVATION_QUEUE = "coulobre-web-activation"
WEB_HTTPS_QUEUE = "coulobre-web-https"
DATABASE_PROVISIONING_QUEUE = "coulobre-database-provisioning" DATABASE_PROVISIONING_QUEUE = "coulobre-database-provisioning"
DNS_PUBLISHING_QUEUE = "coulobre-dns-publishing" DNS_PUBLISHING_QUEUE = "coulobre-dns-publishing"
MAILBOX_PROVISIONING_QUEUE = "coulobre-mailbox-provisioning" 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 @shared_task
def dispatch_database_provisioning(): def dispatch_database_provisioning():
if settings.LOCAL_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)) 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) @shared_task(acks_late=True, reject_on_worker_lost=True)
def provision_database(provisioning_id): def provision_database(provisioning_id):
if settings.LOCAL_DATABASE_PROVISIONING: if settings.LOCAL_DATABASE_PROVISIONING:
@@ -7,7 +7,7 @@
<h1>Apache preview</h1> <h1>Apache preview</h1>
<p class="heading-meta domain">{{ plan.primary_domain }}</p> <p class="heading-meta domain">{{ plan.primary_domain }}</p>
</div> </div>
{% if not plan.completed_at or manage_activation and plan.activation and not plan.activation.finished_at %} {% if not plan.completed_at or manage_activation and plan.activation and not plan.activation.finished_at or manage_https and plan.https and not plan.https.finished_at %}
<a class="button secondary" href="{% url 'panel:plan' plan.pk %}">Refresh status</a> <a class="button secondary" href="{% url 'panel:plan' plan.pk %}">Refresh status</a>
{% endif %} {% endif %}
</header> </header>
@@ -66,4 +66,20 @@
{% endif %} {% endif %}
{% endwith %} {% endwith %}
{% endif %} {% endif %}
{% if manage_https %}
{% with provisioning=plan.https %}
{% if provisioning or local_https_enabled and plan.can_enable_https %}
<section class="surface" aria-labelledby="https-heading">
<header class="section-heading">
<h2 id="https-heading">Website HTTPS</h2>
{% if local_https_enabled and plan.can_enable_https %}
{% url 'panel:plan_https' plan.pk as https_action %}
{% endif %}
{% include "hosting/resource_provisioning.html" with enabled=https_action action=https_action resource=plan.primary_domain provision_label="Enable HTTPS" retry_label="Retry HTTPS" %}
</header>
{% if provisioning.problem %}<p class="empty">{{ provisioning.problem }}</p>{% endif %}
</section>
{% endif %}
{% endwith %}
{% endif %}
{% endblock %} {% endblock %}
@@ -12,7 +12,7 @@
<form method="post" action="{{ action }}"> <form method="post" action="{{ action }}">
{% csrf_token %} {% csrf_token %}
{% if provisioning %} {% if provisioning %}
<button class="button secondary" type="submit" aria-label="Retry provisioning {{ resource }}">Retry provisioning</button> <button class="button secondary" type="submit" aria-label="{{ retry_label|default:'Retry provisioning' }} {{ resource }}">{{ retry_label|default:"Retry provisioning" }}</button>
{% else %} {% else %}
<button class="button secondary" type="submit" aria-label="{{ provision_label }} {{ resource }}">{{ provision_label }}</button> <button class="button secondary" type="submit" aria-label="{{ provision_label }} {{ resource }}">{{ provision_label }}</button>
{% endif %} {% endif %}
+132
View File
@@ -0,0 +1,132 @@
from unittest.mock import patch
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Permission
from django.test import TestCase, override_settings
from django.urls import reverse
from django.utils import timezone
from coulobre.web_node import WebSite
from .models import (
HostingAccount,
WebActivation,
WebHTTPS,
WebProvisioningPlan,
)
from .tasks import WEB_HTTPS_QUEUE, dispatch_web_https, enable_web_https
@override_settings(LOCAL_WEB_HTTPS=True)
class WebHTTPSTests(TestCase):
@classmethod
def setUpTestData(cls):
cls.operator = get_user_model().objects.create_superuser("operator")
cls.account = HostingAccount.objects.create(
name="Example site", primary_domain="site.example"
)
cls.plan = WebProvisioningPlan.objects.create(
account=cls.account,
primary_domain=cls.account.primary_domain,
apache_config="Rendered Apache configuration",
completed_at=timezone.now(),
)
def setUp(self):
self.client.force_login(self.operator)
self.url = reverse("panel:plan_https", args=[self.plan.pk])
self.detail = reverse("panel:plan", args=[self.plan.pk])
def activate_site(self):
WebActivation.objects.create(
plan=self.plan, finished_at=timezone.now()
)
def test_requires_an_active_site_for_the_current_domain(self):
self.assertEqual(self.client.post(self.url).status_code, 409)
self.assertNotContains(self.client.get(self.detail), "Enable HTTPS")
self.activate_site()
self.account.primary_domain = "new.example"
self.account.save(update_fields=["primary_domain"])
self.assertEqual(self.client.post(self.url).status_code, 409)
self.assertFalse(WebHTTPS.objects.exists())
def test_operator_can_queue_once_and_track_https(self):
self.activate_site()
self.assertContains(self.client.get(self.detail), "Enable HTTPS")
self.assertEqual(self.client.get(self.url).status_code, 405)
self.assertRedirects(self.client.post(self.url), self.detail)
self.client.post(self.url)
request = WebHTTPS.objects.get(plan=self.plan)
self.assertContains(self.client.get(self.detail), "Refresh status")
with patch(
"coulobre.hosting.tasks.enable_web_https.apply_async"
) as send:
dispatch_web_https()
send.assert_called_once_with(
args=[request.pk], queue=WEB_HTTPS_QUEUE, retry=False
)
with patch("coulobre.hosting.tasks.enable_local_https") as enable:
enable_web_https(request.pk)
enable_web_https(request.pk)
enable.assert_called_once_with(
WebSite(self.account.pk, self.account.primary_domain)
)
request.refresh_from_db()
self.assertEqual(request.state, "configured")
self.assertNotContains(self.client.get(self.detail), "Enable HTTPS")
def test_failed_attempt_can_be_retried(self):
self.activate_site()
request = WebHTTPS.objects.create(plan=self.plan)
with patch(
"coulobre.hosting.tasks.enable_local_https",
side_effect=ValueError("Check the HTTP-01 route."),
):
enable_web_https(request.pk)
response = self.client.get(self.detail)
self.assertContains(response, "Check the HTTP-01 route.")
self.assertContains(response, "Retry HTTPS")
self.assertRedirects(self.client.post(self.url), self.detail)
request.refresh_from_db()
self.assertEqual(request.state, "queued")
self.assertIsNone(request.started_at)
self.assertEqual(request.problem, "")
def test_worker_rechecks_the_domain_before_requesting_a_certificate(self):
self.activate_site()
request = WebHTTPS.objects.create(plan=self.plan)
self.account.primary_domain = "new.example"
self.account.save(update_fields=["primary_domain"])
with patch("coulobre.hosting.tasks.enable_local_https") as enable:
enable_web_https(request.pk)
enable.assert_not_called()
request.refresh_from_db()
self.assertEqual(request.state, "failed")
def test_activation_permission_does_not_grant_https_access(self):
self.activate_site()
reader = get_user_model().objects.create_user("reader", is_staff=True)
reader.user_permissions.add(
*Permission.objects.filter(
content_type__app_label="hosting",
codename__in=(
"view_hostingaccount",
"view_webprovisioningplan",
"add_webactivation",
),
)
)
self.client.force_login(reader)
self.assertNotContains(self.client.get(self.detail), "Enable HTTPS")
self.assertEqual(self.client.post(self.url).status_code, 403)
@override_settings(LOCAL_WEB_HTTPS=False)
def test_feature_flag_disables_requests(self):
self.activate_site()
self.assertNotContains(self.client.get(self.detail), "Enable HTTPS")
self.assertEqual(self.client.post(self.url).status_code, 404)
+5
View File
@@ -121,6 +121,11 @@ urlpatterns = [
views.RequestWebActivation.as_view(), views.RequestWebActivation.as_view(),
name="plan_activate", name="plan_activate",
), ),
path(
"plans/<int:pk>/https/",
views.RequestWebHTTPS.as_view(),
name="plan_https",
),
path( path(
"plans/<int:pk>/smoke-bundle/", "plans/<int:pk>/smoke-bundle/",
views.DownloadWebPlan.as_view(), views.DownloadWebPlan.as_view(),
+28 -1
View File
@@ -55,6 +55,7 @@ from .models import (
MailboxProvisioning, MailboxProvisioning,
Reseller, Reseller,
WebActivation, WebActivation,
WebHTTPS,
WebProvisioningPlan, WebProvisioningPlan,
) )
from .reseller_accounts import create_reseller_account from .reseller_accounts import create_reseller_account
@@ -71,6 +72,7 @@ VIEW_DATABASES = "hosting.view_hostingdatabase"
VIEW_DNS_ZONES = "hosting.view_hostingdnszone" VIEW_DNS_ZONES = "hosting.view_hostingdnszone"
VIEW_MAILBOXES = "hosting.view_hostingmailbox" VIEW_MAILBOXES = "hosting.view_hostingmailbox"
ACTIVATE_WEB = (VIEW_ACCOUNTS, VIEW_PLANS, "hosting.add_webactivation") ACTIVATE_WEB = (VIEW_ACCOUNTS, VIEW_PLANS, "hosting.add_webactivation")
ENABLE_WEB_HTTPS = (VIEW_ACCOUNTS, VIEW_PLANS, "hosting.add_webhttps")
PROVISION_DATABASE = ( PROVISION_DATABASE = (
VIEW_ACCOUNTS, VIEW_ACCOUNTS,
VIEW_DATABASES, VIEW_DATABASES,
@@ -717,7 +719,7 @@ class PlanList(TenantScopeMixin, PermissionRequiredMixin, ListView):
class PlanDetail(TenantScopeMixin, PermissionRequiredMixin, DetailView): class PlanDetail(TenantScopeMixin, PermissionRequiredMixin, DetailView):
queryset = WebProvisioningPlan.objects.select_related( queryset = WebProvisioningPlan.objects.select_related(
"account", "activation" "account", "activation", "https"
) )
permission_required = VIEW_PLANS permission_required = VIEW_PLANS
reseller_relation = "account__reseller" reseller_relation = "account__reseller"
@@ -730,6 +732,9 @@ class PlanDetail(TenantScopeMixin, PermissionRequiredMixin, DetailView):
manage_activation=not is_tenant(user) manage_activation=not is_tenant(user)
and user.has_perms(ACTIVATE_WEB), and user.has_perms(ACTIVATE_WEB),
local_activation_enabled=settings.LOCAL_WEB_ACTIVATION, local_activation_enabled=settings.LOCAL_WEB_ACTIVATION,
manage_https=not is_tenant(user)
and user.has_perms(ENABLE_WEB_HTTPS),
local_https_enabled=settings.LOCAL_WEB_HTTPS,
**kwargs, **kwargs,
) )
@@ -755,6 +760,28 @@ class RequestWebActivation(
return redirect("panel:plan", pk=plan.pk) return redirect("panel:plan", pk=plan.pk)
class RequestWebHTTPS(
OperatorOnlyMixin, PermissionRequiredMixin, SingleObjectMixin, View
):
queryset = WebProvisioningPlan.objects.select_related(
"account", "activation"
)
permission_required = ENABLE_WEB_HTTPS
def post(self, request, *args, **kwargs):
if not settings.LOCAL_WEB_HTTPS:
raise Http404
plan = self.get_object()
if not plan.can_enable_https:
return HttpResponse(
"Activate the site for the current domain first.",
status=409,
content_type="text/plain",
)
WebHTTPS.objects.queue(plan=plan)
return redirect("panel:plan", pk=plan.pk)
class DownloadWebPlan(OperatorOnlyMixin, PlanDetail): class DownloadWebPlan(OperatorOnlyMixin, PlanDetail):
manifest = False manifest = False
+7
View File
@@ -119,6 +119,7 @@ CELERY_BROKER_TRANSPORT_OPTIONS = {"confirm_publish": True}
CELERY_TASK_DEFAULT_QUEUE = "coulobre" CELERY_TASK_DEFAULT_QUEUE = "coulobre"
CELERY_TASK_IGNORE_RESULT = True CELERY_TASK_IGNORE_RESULT = True
LOCAL_WEB_ACTIVATION = os.environ.get("COULOBRE_LOCAL_WEB_ACTIVATION") == "1" LOCAL_WEB_ACTIVATION = os.environ.get("COULOBRE_LOCAL_WEB_ACTIVATION") == "1"
LOCAL_WEB_HTTPS = os.environ.get("COULOBRE_LOCAL_WEB_HTTPS") == "1"
LOCAL_DATABASE_PROVISIONING = ( LOCAL_DATABASE_PROVISIONING = (
os.environ.get("COULOBRE_LOCAL_DATABASE_PROVISIONING") == "1" os.environ.get("COULOBRE_LOCAL_DATABASE_PROVISIONING") == "1"
) )
@@ -139,6 +140,12 @@ if LOCAL_WEB_ACTIVATION:
"schedule": 5.0, "schedule": 5.0,
"options": {"expires": 4.0}, "options": {"expires": 4.0},
} }
if LOCAL_WEB_HTTPS:
CELERY_BEAT_SCHEDULE["dispatch-web-https"] = {
"task": "coulobre.hosting.tasks.dispatch_web_https",
"schedule": 5.0,
"options": {"expires": 4.0},
}
if LOCAL_DATABASE_PROVISIONING: if LOCAL_DATABASE_PROVISIONING:
CELERY_BEAT_SCHEDULE["dispatch-database-provisioning"] = { CELERY_BEAT_SCHEDULE["dispatch-database-provisioning"] = {
"task": "coulobre.hosting.tasks.dispatch_database_provisioning", "task": "coulobre.hosting.tasks.dispatch_database_provisioning",