From dc19e4a59a5ea2b1d1b36e98b6516e815fa66d57 Mon Sep 17 00:00:00 2001 From: Peter van Arkel Date: Sat, 21 Nov 2026 17:31:00 +0100 Subject: [PATCH] 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",