From dc19e4a59a5ea2b1d1b36e98b6516e815fa66d57 Mon Sep 17 00:00:00 2001 From: Peter van Arkel Date: Sat, 21 Nov 2026 17:31:00 +0100 Subject: [PATCH 1/3] Relay DNS and mailbox provisioning over restricted SSH connections --- .../coulobre-node-requests.conf.example | 20 +++++++++++++++++++ deploy/openssh/dns-node-client.conf.example | 13 ++++++++++++ deploy/openssh/mail-node-client.conf.example | 13 ++++++++++++ deploy/panel.env.example | 1 + .../coulobre-dns-apply@.service.d/remote.conf | 11 ++++++++++ deploy/systemd/coulobre-dns-publisher.service | 2 +- .../remote.conf | 11 ++++++++++ .../coulobre-mailbox-provisioner.service | 2 +- src/coulobre/hosting/node_client.py | 4 ++++ src/coulobre/hosting/test_dns_publication.py | 16 +++++++++++++++ 10 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 deploy/openssh/coulobre-node-requests.conf.example create mode 100644 deploy/openssh/dns-node-client.conf.example create mode 100644 deploy/openssh/mail-node-client.conf.example create mode 100644 deploy/systemd/coulobre-dns-apply@.service.d/remote.conf create mode 100644 deploy/systemd/coulobre-mail-apply@.service.d/remote.conf diff --git a/deploy/openssh/coulobre-node-requests.conf.example b/deploy/openssh/coulobre-node-requests.conf.example new file mode 100644 index 0000000..ecd6be7 --- /dev/null +++ b/deploy/openssh/coulobre-node-requests.conf.example @@ -0,0 +1,20 @@ +Match User coulobre-dns-request,coulobre-mail-request + AuthenticationMethods publickey + PubkeyAuthentication yes + PasswordAuthentication no + KbdInteractiveAuthentication no + AuthorizedKeysFile /etc/ssh/coulobre-node-keys/%u + AuthorizedKeysCommand none + TrustedUserCAKeys none + DisableForwarding yes + PermitTunnel no + PermitTTY no + PermitUserRC no + +Match User coulobre-dns-request + ForceCommand /usr/bin/socat -t 185 STDIO UNIX-CONNECT:/run/coulobre-dns-apply.sock + +Match User coulobre-mail-request + ForceCommand /usr/bin/socat -t 185 STDIO UNIX-CONNECT:/run/coulobre-mail-apply.sock + +Match all diff --git a/deploy/openssh/dns-node-client.conf.example b/deploy/openssh/dns-node-client.conf.example new file mode 100644 index 0000000..9ae3d2f --- /dev/null +++ b/deploy/openssh/dns-node-client.conf.example @@ -0,0 +1,13 @@ +Host coulobre-dns-node + HostName dns.example.org + Port 22 + User coulobre-dns-request + IdentityFile /etc/coulobre-remote/dns/id_ed25519 + IdentityAgent none + IdentitiesOnly yes + PreferredAuthentications publickey + UserKnownHostsFile /etc/coulobre-remote/dns/known_hosts + GlobalKnownHostsFile none + StrictHostKeyChecking yes + BatchMode yes + ConnectTimeout 5 diff --git a/deploy/openssh/mail-node-client.conf.example b/deploy/openssh/mail-node-client.conf.example new file mode 100644 index 0000000..ad4f217 --- /dev/null +++ b/deploy/openssh/mail-node-client.conf.example @@ -0,0 +1,13 @@ +Host coulobre-mail-node + HostName mail.example.org + Port 22 + User coulobre-mail-request + IdentityFile /etc/coulobre-remote/mail/id_ed25519 + IdentityAgent none + IdentitiesOnly yes + PreferredAuthentications publickey + UserKnownHostsFile /etc/coulobre-remote/mail/known_hosts + GlobalKnownHostsFile none + StrictHostKeyChecking yes + BatchMode yes + ConnectTimeout 5 diff --git a/deploy/panel.env.example b/deploy/panel.env.example index ff6d0f9..bec5d85 100644 --- a/deploy/panel.env.example +++ b/deploy/panel.env.example @@ -12,6 +12,7 @@ COULOBRE_BROKER_URL=amqp://coulobre:@127.0.0.1:5672/coulobre # COULOBRE_LOCAL_WEB_HTTPS=1 # COULOBRE_LOCAL_WEB_SFTP=1 # COULOBRE_LOCAL_DATABASE_PROVISIONING=1 +# These two switches also enable provisioners using the SSH service drop-ins. # COULOBRE_LOCAL_DNS_PUBLISHING=1 # COULOBRE_LOCAL_MAILBOX_PROVISIONING=1 # COULOBRE_LOCAL_DATABASE_CREDENTIALS=1 diff --git a/deploy/systemd/coulobre-dns-apply@.service.d/remote.conf b/deploy/systemd/coulobre-dns-apply@.service.d/remote.conf new file mode 100644 index 0000000..6b88901 --- /dev/null +++ b/deploy/systemd/coulobre-dns-apply@.service.d/remote.conf @@ -0,0 +1,11 @@ +[Unit] +Description=Coulobre remote BIND9 publishing request + +[Service] +User=coulobre-dns-publisher +Group=coulobre-dns-publisher +UMask=0077 +ReadWritePaths= +ExecStart= +ExecStart=/usr/bin/ssh -T -F /etc/coulobre-remote/dns/ssh_config coulobre-dns-node +RuntimeMaxSec=190s diff --git a/deploy/systemd/coulobre-dns-publisher.service b/deploy/systemd/coulobre-dns-publisher.service index 1c5d026..7a02709 100644 --- a/deploy/systemd/coulobre-dns-publisher.service +++ b/deploy/systemd/coulobre-dns-publisher.service @@ -1,5 +1,5 @@ [Unit] -Description=Coulobre Panel local BIND9 publishing worker +Description=Coulobre Panel BIND9 publishing worker Requires=coulobre-dns-apply.socket Wants=network-online.target After=network-online.target coulobre-dns-apply.socket mariadb.service rabbitmq-server.service diff --git a/deploy/systemd/coulobre-mail-apply@.service.d/remote.conf b/deploy/systemd/coulobre-mail-apply@.service.d/remote.conf new file mode 100644 index 0000000..f79f4e5 --- /dev/null +++ b/deploy/systemd/coulobre-mail-apply@.service.d/remote.conf @@ -0,0 +1,11 @@ +[Unit] +Description=Coulobre remote mailbox provisioning request + +[Service] +User=coulobre-mail-provisioner +Group=coulobre-mail-provisioner +UMask=0077 +StateDirectory= +ExecStart= +ExecStart=/usr/bin/ssh -T -F /etc/coulobre-remote/mail/ssh_config coulobre-mail-node +RuntimeMaxSec=190s diff --git a/deploy/systemd/coulobre-mailbox-provisioner.service b/deploy/systemd/coulobre-mailbox-provisioner.service index e99a84f..ed11986 100644 --- a/deploy/systemd/coulobre-mailbox-provisioner.service +++ b/deploy/systemd/coulobre-mailbox-provisioner.service @@ -1,5 +1,5 @@ [Unit] -Description=Coulobre Panel local mailbox provisioning worker +Description=Coulobre Panel mailbox provisioning worker Requires=coulobre-mail-apply.socket Wants=network-online.target After=network-online.target coulobre-mail-apply.socket mariadb.service rabbitmq-server.service diff --git a/src/coulobre/hosting/node_client.py b/src/coulobre/hosting/node_client.py index ae95235..5674708 100644 --- a/src/coulobre/hosting/node_client.py +++ b/src/coulobre/hosting/node_client.py @@ -212,6 +212,10 @@ def apply_on_local_node( if len(body) > RESPONSE_LIMIT: raise ValueError(f"The {node} returned an oversized response.") + if not body: + raise ValueError( + f"The {node} closed the connection without a response." + ) invalid_response = ( f"The {node} returned an invalid response for this {resource}." ) diff --git a/src/coulobre/hosting/test_dns_publication.py b/src/coulobre/hosting/test_dns_publication.py index 79b48cd..c65a775 100644 --- a/src/coulobre/hosting/test_dns_publication.py +++ b/src/coulobre/hosting/test_dns_publication.py @@ -149,6 +149,22 @@ class DnsPublicationTests(TestCase): class DnsPublicationSocketTests(SimpleTestCase): + def test_closed_connection_reports_a_missing_reply(self): + zone = DnsZone( + "site.example", + 1, + ("ns.provider.example",), + "hostmaster.site.example", + ) + with patch("coulobre.hosting.node_client.socket.socket") as socket: + connection = socket.return_value.__enter__.return_value + connection.makefile.return_value.__enter__.return_value = BytesIO() + with self.assertRaisesMessage( + ValueError, + "The BIND9 node closed the connection without a response.", + ): + publish_local_zone(zone) + def test_receipt_must_identify_the_exact_soa_serial(self): zone = DnsZone( "site.example", -- 2.43.0 From 066fbd9be370f10abc0c51d0a17a663b45f7380e Mon Sep 17 00:00:00 2001 From: Peter van Arkel Date: Sat, 21 Nov 2026 17:31:00 +0100 Subject: [PATCH 2/3] Document separate and shared DNS and mail nodes --- docs/deployment.md | 143 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) diff --git a/docs/deployment.md b/docs/deployment.md index 838bcb1..d4e9772 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -760,6 +760,9 @@ database. Sign out of phpMyAdmin to end its session. ## Publish local DNS zones from the panel +To publish to BIND9 on another host, use the +[separate-node setup](#provision-mail-and-dns-on-separate-servers). + Enable the [DNS publishing socket](development.md#enable-local-dns-publishing) on the panel host. Install the BIND9 publishing worker under a dedicated identity with access to that socket. @@ -791,6 +794,9 @@ finishes. Use **Retry publishing** if the current revision failed. ## Provision local mailboxes from the panel +To provision Postfix and Dovecot on another host, use the +[separate-node setup](#provision-mail-and-dns-on-separate-servers). + Set up [Postfix and Dovecot](development.md#apply-a-mailbox-manifest) on the Ubuntu 24.04 or 26.04 panel host and enable the [mailbox provisioning socket](development.md#enable-local-mailbox-provisioning). @@ -834,3 +840,140 @@ the node command for manually provisioned mailboxes. Back up mail on the node that hosts the mailbox. The archive can be used to recover messages and folders into a newly provisioned mailbox with the same address. [Mailbox backup and restore](development.md#back-up-and-restore-a-mailbox) + +## Provision mail and DNS on separate servers + +Choose one destination per service. For example, run mail locally and publish +DNS to a separate authoritative server. The panel uses the same worker and +job history for each deployment. On the panel server, install the SSH +drop-in only for a service that uses another host. + +Several Coulobre installations under the same administration can share a +destination. Generate a separate key per sending installation and service. +The receiver accepts each key separately, and removing its line revokes that +installation's access. Each receiver can manage any Coulobre resource on its +service. Assign each domain to one installation for changes to its zones and +mailboxes. + +Use the values for each service below when following the commands. + +| Value | DNS | Mail | +| --- | --- | --- | +| `node` | `dns` | `mail` | +| `request_group` | `coulobre-dns-provisioning` | `coulobre-mail-provisioning` | +| `receiver` | `coulobre-dns-request` | `coulobre-mail-request` | +| `worker` | `coulobre-dns-publisher` | `coulobre-mail-provisioner` | +| Worker unit | `coulobre-dns-publisher.service` | `coulobre-mailbox-provisioner.service` | +| Panel flag | `COULOBRE_LOCAL_DNS_PUBLISHING=1` | `COULOBRE_LOCAL_MAILBOX_PROVISIONING=1` | + +### Prepare the panel's SSH identity + +Start from the same Coulobre source release on both hosts. For DNS, set these +variables on the panel host. For mail, substitute the values in the table. + +```sh +node=dns +request_group=coulobre-dns-provisioning +worker=coulobre-dns-publisher + +sudo apt install openssh-client +getent group "$request_group" >/dev/null || sudo groupadd --system "$request_group" +id "$worker" >/dev/null 2>&1 || sudo useradd --system --user-group \ + --no-create-home --home-dir /nonexistent --shell /usr/sbin/nologin "$worker" +sudo install -d -o root -g root -m 0755 /etc/coulobre-remote +sudo install -d -o root -g "$worker" -m 0750 "/etc/coulobre-remote/$node" +sudo install -o root -g "$worker" -m 0640 \ + "deploy/openssh/$node-node-client.conf.example" "/etc/coulobre-remote/$node/ssh_config" +sudo sh -c 'umask 077; ssh-keygen -t ed25519 -N "" -f "$1/id_ed25519"' \ + sh "/etc/coulobre-remote/$node" +sudo chown "$worker:$worker" "/etc/coulobre-remote/$node/id_ed25519" +sudo cat "/etc/coulobre-remote/$node/id_ed25519.pub" +``` + +Set `HostName` and `Port` in the SSH client configuration. Obtain the +destination's SSH host public key through your existing administrative +connection. Put the hostname or IP address, key type, and public key on one +line in `/etc/coulobre-remote/` under the service's `known_hosts` file. For a +port other than 22, use `[hostname]:port` in that line. Make the file owned +by root and readable by the worker group. The worker checks this pinned host +key before sending a request. [OpenSSH client configuration](https://man.openbsd.org/ssh_config) + +### Install the node on the destination + +On the destination, unpack the source release and install the Coulobre node +commands in `/opt/coulobre`. + +```sh +sudo apt install python3-venv openssh-server socat +sudo python3 -m venv /opt/coulobre +sudo /opt/coulobre/bin/pip install . +``` + +Set up [BIND9](development.md#apply-a-zone-manifest) or +[Postfix and Dovecot](development.md#apply-a-mailbox-manifest), then enable +the corresponding [DNS socket](development.md#enable-local-dns-publishing) or +[mailbox socket](development.md#enable-local-mailbox-provisioning). The +destination runs the local socket service shipped with Coulobre. + +Save the panel's public key from the previous step as `panel-node.pub` on +the destination. Create a receiver with only the socket group for that +service. This example uses DNS. Substitute the values for a mail node. + +```sh +request_group=coulobre-dns-provisioning +receiver=coulobre-dns-request + +id "$receiver" >/dev/null 2>&1 || sudo useradd --system --user-group --groups "$request_group" \ + --no-create-home --home-dir / --shell /bin/sh "$receiver" +sudo install -d -o root -g root -m 0755 /etc/ssh/coulobre-node-keys +authorized_keys="/etc/ssh/coulobre-node-keys/$receiver" +sudo touch "$authorized_keys" +sudo chown root:root "$authorized_keys" +sudo chmod 0644 "$authorized_keys" +sudo tee -a "$authorized_keys" < panel-node.pub >/dev/null +sudo install -m 0644 deploy/openssh/coulobre-node-requests.conf.example \ + /etc/ssh/sshd_config.d/00-coulobre-node-requests.conf +sudo sshd -t +sudo systemctl reload-or-restart ssh.service +``` + +The receiver authenticates with the panel's key and runs a fixed relay to +the service socket. The socket's systemd service validates and applies the +request. [OpenSSH server configuration](https://man.openbsd.org/sshd_config) + +### Enable the remote destination on the panel + +Use the matching worker from the table. The commands below use DNS. + +```sh +node=dns +worker_unit=coulobre-dns-publisher.service +unit="coulobre-$node-apply" + +sudo install -m 0644 "deploy/systemd/$unit.socket" \ + "deploy/systemd/$unit@.service" "deploy/systemd/$worker_unit" /etc/systemd/system/ +sudo install -D -m 0644 "deploy/systemd/$unit@.service.d/remote.conf" \ + "/etc/systemd/system/$unit@.service.d/remote.conf" +sudo systemctl daemon-reload +``` + +Set the corresponding flag from the table in `/etc/coulobre/panel.env`. The +flag enables the existing panel actions and queue for that service. Restart +the panel and its general worker so they pick up the setting, then enable +the dedicated worker. + +```sh +sudo systemctl restart coulobre-panel coulobre-worker coulobre-beat +sudo systemctl enable --now "$worker_unit" +``` + +Use **Publish zone** or **Provision mailbox** and check the status on the +account page. After correcting a connection or host key problem, use the +corresponding retry action. Check the panel-side relay log with +`sudo journalctl -u 'coulobre-dns-apply@*.service'` for DNS or +`sudo journalctl -u 'coulobre-mail-apply@*.service'` for mail. + +When moving an existing service, migrate its data and provisioning state and +let outstanding jobs finish before switching destinations. +For mail on a separate server, retrieve logins on the mail node, and use the +[separate-node backup workflow](development.md#bundle-backups-from-separate-nodes). -- 2.43.0 From 8974b55f98679c6e9248dc24bdabc9eb4883cd5e Mon Sep 17 00:00:00 2001 From: Peter van Arkel Date: Sat, 21 Nov 2026 17:32:52 +0100 Subject: [PATCH 3/3] Use transport-neutral DNS and mailbox failure messages --- src/coulobre/hosting/tasks.py | 8 ++++---- src/coulobre/hosting/test_mailbox_provisioning.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/coulobre/hosting/tasks.py b/src/coulobre/hosting/tasks.py index e745aa7..5416eab 100644 --- a/src/coulobre/hosting/tasks.py +++ b/src/coulobre/hosting/tasks.py @@ -498,8 +498,8 @@ def publish_dns_zone(publication_id): DnsPublication.objects.all(), publication_id, apply_dns_publication, - "Could not complete the request to the local BIND9 node. " - "Check its socket and try again.", + "Could not complete the request to the BIND9 node. " + "Check the node connection and try again.", ) @@ -516,8 +516,8 @@ def provision_mailbox(provisioning_id): MailboxProvisioning.objects.select_related("mailbox__mail_domain"), provisioning_id, apply_mailbox_provisioning, - "Could not complete the request to the local mail node. " - "Check its socket and try again.", + "Could not complete the request to the mail node. " + "Check the node connection and try again.", ) diff --git a/src/coulobre/hosting/test_mailbox_provisioning.py b/src/coulobre/hosting/test_mailbox_provisioning.py index 6b4a6cf..81bb09c 100644 --- a/src/coulobre/hosting/test_mailbox_provisioning.py +++ b/src/coulobre/hosting/test_mailbox_provisioning.py @@ -116,7 +116,7 @@ class MailboxProvisioningTests(TestCase): detail = self.client.get(self.detail) self.assertContains(detail, "Retry provisioning") self.assertContains( - detail, "Could not complete the request to the local mail node" + detail, "Could not complete the request to the mail node" ) self.assertRedirects(self.client.post(self.url), self.detail) job.refresh_from_db() -- 2.43.0