From 0ab0eebfc633f1273e7a82bd159770b55c1bc626 Mon Sep 17 00:00:00 2001 From: Peter van Arkel Date: Sat, 21 Nov 2026 19:23:01 +0100 Subject: [PATCH] Deploy remote mailbox credentials over a dedicated SSH relay --- .../coulobre-mail-credentials.conf.example | 15 +++ .../mail-credential-client.conf.example | 13 +++ deploy/panel.env.example | 4 + .../systemd/coulobre-mail-credentials.socket | 11 ++ .../coulobre-mail-credentials@.service | 20 ++++ .../remote.conf | 9 ++ .../rotation.conf | 4 + .../credentials-remote-mail.conf | 6 + .../database-rotation.conf | 4 + .../mailbox-rotation.conf | 4 + docs/deployment.md | 105 +++++++++++++++++- 11 files changed, 192 insertions(+), 3 deletions(-) create mode 100644 deploy/openssh/coulobre-mail-credentials.conf.example create mode 100644 deploy/openssh/mail-credential-client.conf.example create mode 100644 deploy/systemd/coulobre-mail-credentials.socket create mode 100644 deploy/systemd/coulobre-mail-credentials@.service create mode 100644 deploy/systemd/coulobre-mail-credentials@.service.d/remote.conf create mode 100644 deploy/systemd/coulobre-mail-credentials@.service.d/rotation.conf create mode 100644 deploy/systemd/coulobre-panel.service.d/credentials-remote-mail.conf create mode 100644 deploy/systemd/coulobre-service-credentials@.service.d/database-rotation.conf create mode 100644 deploy/systemd/coulobre-service-credentials@.service.d/mailbox-rotation.conf diff --git a/deploy/openssh/coulobre-mail-credentials.conf.example b/deploy/openssh/coulobre-mail-credentials.conf.example new file mode 100644 index 0000000..6ab7ef4 --- /dev/null +++ b/deploy/openssh/coulobre-mail-credentials.conf.example @@ -0,0 +1,15 @@ +Match User coulobre-mail-credential-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 + ForceCommand /usr/bin/socat -t 92 STDIO UNIX-CONNECT:/run/coulobre-mail-credentials.sock + +Match all diff --git a/deploy/openssh/mail-credential-client.conf.example b/deploy/openssh/mail-credential-client.conf.example new file mode 100644 index 0000000..8482cf2 --- /dev/null +++ b/deploy/openssh/mail-credential-client.conf.example @@ -0,0 +1,13 @@ +Host coulobre-mail-credentials + HostName mail.example.org + Port 22 + User coulobre-mail-credential-request + IdentityFile /etc/coulobre-remote/mail-credentials/id_ed25519 + IdentityAgent none + IdentitiesOnly yes + PreferredAuthentications publickey + UserKnownHostsFile /etc/coulobre-remote/mail-credentials/known_hosts + GlobalKnownHostsFile none + StrictHostKeyChecking yes + BatchMode yes + ConnectTimeout 5 diff --git a/deploy/panel.env.example b/deploy/panel.env.example index 0d04764..a97b656 100644 --- a/deploy/panel.env.example +++ b/deploy/panel.env.example @@ -18,6 +18,10 @@ COULOBRE_BROKER_URL=amqp://coulobre:@127.0.0.1:5672/coulobre # COULOBRE_LOCAL_MAILBOX_PROVISIONING=1 # COULOBRE_LOCAL_DATABASE_CREDENTIALS=1 # COULOBRE_LOCAL_MAILBOX_CREDENTIALS=1 +# COULOBRE_REMOTE_MAILBOX_CREDENTIALS=1 +# COULOBRE_LOCAL_DATABASE_CREDENTIALS_ROTATION=1 +# COULOBRE_LOCAL_MAILBOX_CREDENTIALS_ROTATION=1 +# COULOBRE_REMOTE_MAILBOX_CREDENTIALS_ROTATION=1 # COULOBRE_MAIL_IMAP_HOST=mail.example.org # COULOBRE_PHPMYADMIN_URL=https://tools.example.org/phpmyadmin # COULOBRE_PHPMYADMIN_BRIDGE_KEY= diff --git a/deploy/systemd/coulobre-mail-credentials.socket b/deploy/systemd/coulobre-mail-credentials.socket new file mode 100644 index 0000000..ba1e779 --- /dev/null +++ b/deploy/systemd/coulobre-mail-credentials.socket @@ -0,0 +1,11 @@ +[Unit] +Description=Coulobre mailbox credential socket + +[Socket] +ListenStream=/run/coulobre-mail-credentials.sock +SocketUser=root +SocketGroup=coulobre-credential-requests +SocketMode=0660 +Accept=yes +MaxConnections=4 +RemoveOnStop=true diff --git a/deploy/systemd/coulobre-mail-credentials@.service b/deploy/systemd/coulobre-mail-credentials@.service new file mode 100644 index 0000000..d137167 --- /dev/null +++ b/deploy/systemd/coulobre-mail-credentials@.service @@ -0,0 +1,20 @@ +[Unit] +Description=Coulobre mailbox credential request +After=postfix.service dovecot.service +CollectMode=inactive-or-failed + +[Service] +Type=exec +User=root +WorkingDirectory=/opt/coulobre +UMask=0077 +Environment=COULOBRE_LOCAL_MAILBOX_CREDENTIALS=1 +ExecStart=/opt/coulobre/bin/coulobre-service-credentials --mailbox-only +StandardInput=socket +StandardOutput=socket +StandardError=journal +RuntimeMaxSec=90s +NoNewPrivileges=true +PrivateTmp=true +ProtectHome=true +ProtectSystem=strict diff --git a/deploy/systemd/coulobre-mail-credentials@.service.d/remote.conf b/deploy/systemd/coulobre-mail-credentials@.service.d/remote.conf new file mode 100644 index 0000000..4288c1c --- /dev/null +++ b/deploy/systemd/coulobre-mail-credentials@.service.d/remote.conf @@ -0,0 +1,9 @@ +[Unit] +After=network-online.target +Wants=network-online.target + +[Service] +User=coulobre-mail-credential-relay +ExecStart= +ExecStart=/usr/bin/ssh -T -F /etc/coulobre-remote/mail-credentials/ssh_config coulobre-mail-credentials +RuntimeMaxSec=95s diff --git a/deploy/systemd/coulobre-mail-credentials@.service.d/rotation.conf b/deploy/systemd/coulobre-mail-credentials@.service.d/rotation.conf new file mode 100644 index 0000000..0f9b9d2 --- /dev/null +++ b/deploy/systemd/coulobre-mail-credentials@.service.d/rotation.conf @@ -0,0 +1,4 @@ +[Service] +Environment=COULOBRE_LOCAL_MAILBOX_CREDENTIALS_ROTATION=1 +ReadWritePaths=-/var/lib/coulobre/mail-node /etc/dovecot +RuntimeMaxSec=90s diff --git a/deploy/systemd/coulobre-panel.service.d/credentials-remote-mail.conf b/deploy/systemd/coulobre-panel.service.d/credentials-remote-mail.conf new file mode 100644 index 0000000..e82bc18 --- /dev/null +++ b/deploy/systemd/coulobre-panel.service.d/credentials-remote-mail.conf @@ -0,0 +1,6 @@ +[Unit] +Requires=coulobre-mail-credentials.socket +After=coulobre-mail-credentials.socket + +[Service] +SupplementaryGroups=coulobre-credential-requests diff --git a/deploy/systemd/coulobre-service-credentials@.service.d/database-rotation.conf b/deploy/systemd/coulobre-service-credentials@.service.d/database-rotation.conf new file mode 100644 index 0000000..2a4e375 --- /dev/null +++ b/deploy/systemd/coulobre-service-credentials@.service.d/database-rotation.conf @@ -0,0 +1,4 @@ +[Service] +Environment=COULOBRE_LOCAL_DATABASE_CREDENTIALS_ROTATION=1 +ReadWritePaths=-/var/lib/coulobre/database-node +RuntimeMaxSec=90s diff --git a/deploy/systemd/coulobre-service-credentials@.service.d/mailbox-rotation.conf b/deploy/systemd/coulobre-service-credentials@.service.d/mailbox-rotation.conf new file mode 100644 index 0000000..0f9b9d2 --- /dev/null +++ b/deploy/systemd/coulobre-service-credentials@.service.d/mailbox-rotation.conf @@ -0,0 +1,4 @@ +[Service] +Environment=COULOBRE_LOCAL_MAILBOX_CREDENTIALS_ROTATION=1 +ReadWritePaths=-/var/lib/coulobre/mail-node /etc/dovecot +RuntimeMaxSec=90s diff --git a/docs/deployment.md b/docs/deployment.md index 63a7d20..316a713 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -730,12 +730,45 @@ assigned accounts. Operators need permission to view the account and resource and the relevant **Can reveal database credentials** or **Can reveal mailbox credentials** permission. -Passwords are read directly from the local service and rendered on the -confirmation response. The panel stores access events and outcomes in Django +Passwords are read from the service node and rendered on the confirmation +response. The panel stores access events and outcomes in Django admin under **Service credential accesses**. The audit log includes the actor and resource identifiers. After five incorrect confirmations within five minutes, the panel temporarily stops accepting new attempts for that user. +### Rotate a database or mailbox password + +Enable the corresponding local credential service first. For each local +service that should allow password rotation, install its rotation drop-in +and enable the matching flag in `/etc/coulobre/panel.env`. + +```sh +# COULOBRE_LOCAL_DATABASE_CREDENTIALS_ROTATION=1 +sudo install -D -m 0644 deploy/systemd/coulobre-service-credentials@.service.d/database-rotation.conf \ + /etc/systemd/system/coulobre-service-credentials@.service.d/database-rotation.conf +# COULOBRE_LOCAL_MAILBOX_CREDENTIALS_ROTATION=1 +sudo install -D -m 0644 deploy/systemd/coulobre-service-credentials@.service.d/mailbox-rotation.conf \ + /etc/systemd/system/coulobre-service-credentials@.service.d/mailbox-rotation.conf +sudo systemctl daemon-reload +sudo systemctl restart coulobre-panel +``` + +Open **Connection details**, choose **Rotate password**, and confirm the +current panel password. A customer can rotate a login on their own account. +An operator needs the reveal permission and the corresponding **Can rotate +database credentials** or **Can rotate mailbox credentials** permission. +The service node generates the replacement. Copy it into any application +configuration or mail client using that login before its next connection. +A new phpMyAdmin sign-in reads the current database password. + +If the panel cannot confirm the change, retry from the same form or reopen +it to resume the pending request. MariaDB data and grants, and mailbox +messages and quotas, are retained. Existing sessions can stay connected +until they close. The audit trail records the attempt and outcome. The +password stays in the node's root-only registry and is returned only on an +authorized confirmation. Resolve an unconfirmed rotation before suspending +the account or changing the affected mailbox's quota. + ### Open phpMyAdmin from the panel Enable database credential access first. Install phpMyAdmin with PHP's MySQL @@ -1013,9 +1046,75 @@ corresponding retry action. Check the panel-side relay log with 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 +For mail on a separate server, use the [separate-node backup workflow](development.md#bundle-backups-from-separate-nodes). +### Enable connection details for remote mailboxes + +Use a separate SSH identity for credential access. Install the same Coulobre +version on both ends. The key grants access to Coulobre-managed mailbox +logins on that receiver. Keep it with the relay account on the panel and +assign each mailbox domain to one sending installation. + +On the panel node, create the relay user and its SSH directory. Generate a +dedicated key pair, copy the public half to the mail node, and install the +verified SSH host key for the destination as `known_hosts` in the relay +directory. + +```sh +relay=coulobre-mail-credential-relay +dir=/etc/coulobre-remote/mail-credentials +getent group coulobre-credential-requests >/dev/null || sudo groupadd --system coulobre-credential-requests +sudo useradd --system --user-group --no-create-home --home-dir /nonexistent \ + --shell /usr/sbin/nologin "$relay" +sudo install -d -o root -g "$relay" -m 0750 "$dir" +sudo install -o root -g "$relay" -m 0640 deploy/openssh/mail-credential-client.conf.example "$dir/ssh_config" +sudoedit "$dir/ssh_config" +# Install id_ed25519 with owner $relay and mode 0600. +# Install known_hosts with group $relay and mode 0640. +sudo install -m 0644 deploy/systemd/coulobre-mail-credentials.socket \ + deploy/systemd/coulobre-mail-credentials@.service /etc/systemd/system/ +sudo install -D -m 0644 deploy/systemd/coulobre-mail-credentials@.service.d/remote.conf \ + /etc/systemd/system/coulobre-mail-credentials@.service.d/remote.conf +sudo install -D -m 0644 deploy/systemd/coulobre-panel.service.d/credentials-remote-mail.conf \ + /etc/systemd/system/coulobre-panel.service.d/credentials-remote-mail.conf +``` + +On the mail node, save the panel's public key as `mail-credential.pub` and +install the credential receiver and local socket. + +```sh +receiver=coulobre-mail-credential-request +getent group coulobre-credential-requests >/dev/null || sudo groupadd --system coulobre-credential-requests +sudo useradd --system --user-group --groups coulobre-credential-requests \ + --no-create-home --home-dir / --shell /bin/sh "$receiver" +sudo install -d -m 0755 /etc/ssh/coulobre-node-keys +sudo install -m 0644 mail-credential.pub "/etc/ssh/coulobre-node-keys/$receiver" +sudo install -m 0644 deploy/openssh/coulobre-mail-credentials.conf.example \ + /etc/ssh/sshd_config.d/01-coulobre-mail-credentials.conf +sudo install -m 0644 deploy/systemd/coulobre-mail-credentials.socket \ + deploy/systemd/coulobre-mail-credentials@.service /etc/systemd/system/ +sudo sshd -t +sudo systemctl daemon-reload +sudo systemctl reload-or-restart ssh.service +sudo systemctl enable --now coulobre-mail-credentials.socket +``` + +For rotation, also install the receiver's rotation drop-in on the **mail +node** and run `sudo systemctl daemon-reload` there. + +```sh +sudo install -D -m 0644 deploy/systemd/coulobre-mail-credentials@.service.d/rotation.conf \ + /etc/systemd/system/coulobre-mail-credentials@.service.d/rotation.conf +``` + +On the panel, set `COULOBRE_REMOTE_MAILBOX_CREDENTIALS=1` and, for password +changes, `COULOBRE_REMOTE_MAILBOX_CREDENTIALS_ROTATION=1`. Set +`COULOBRE_MAIL_IMAP_HOST` to the mail server's client-facing hostname. Run +`panel_manage migrate --noinput`, reload systemd, and restart +`coulobre-panel`. These flags route mailbox credential requests to the +remote receiver, while databases still use the local credential service. + ## Manage resellers Open **Resellers** to add a reseller login or change an existing reseller's