Use the public service hostname for existing mail nodes
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-24 13:43:58 +01:00
1 parent d81e716ff5
commit e2489aaa1c
8 files changed
+107 -13

No files matched your search

+2
View File
@@ -21,6 +21,8 @@ mode = "off"
# A local mail role requires host, certificate, and key.
# A remote DNS or mail role requires mode = "remote", host, and host_key.
# Use port = 22 or the separate node's configured SSH port.
# For an existing mail node, mail_hostname can specify the public service
# name from its mail certificate. The host field is used for SSH.
# For Let's Encrypt on the panel, use access = "acme" in [panel] and omit
# certificate and key. For new local mail, add tls = "acme" to request
+13 -5
View File
@@ -138,6 +138,13 @@ def interactive_plan(previous=None):
"ssh_identity",
hint=guidance.SSH_IDENTITY,
)
if name == "mail" and mode == "remote":
target["mail_hostname"] = ask(
"Public mail hostname (Enter to skip)",
name,
"mail_hostname",
hint=guidance.MAIL_HOSTNAME,
)
if name == "mail" and mode in {"local", "remote-install"}:
field = "host" if mode == "local" else "mail_hostname"
target[field] = ask(
@@ -165,10 +172,10 @@ def interactive_plan(previous=None):
for name, label, hint in guidance.HOSTING_FIELDS:
if name == "nameservers" and data["dns"]["mode"] == "off":
continue
if name == "mail_sending_addresses" and data["mail"]["mode"] not in {
"local",
"remote-install",
}:
if name == "mail_sending_addresses" and not (
data["mail"].get("mail_hostname")
or data["mail"]["mode"] == "local"
):
continue
previous_values = defaults.get("hosting", {}).get(name, [])
value = prompt(
@@ -225,9 +232,10 @@ def export_parameters(plan, password_path):
fields.update(
ssh_user=role.ssh_user, ssh_identity=role.ssh_identity
)
if name == "mail" and role.mode in {"local", "remote-install"}:
if name == "mail" and role.mail_hostname:
host_key = "host" if role.mode == "local" else "mail_hostname"
fields[host_key] = role.mail_hostname
if name == "mail" and role.mode in {"local", "remote-install"}:
fields["tls"] = role.tls
if role.tls == "provided":
fields.update(certificate=role.certificate, key=role.key)
+9 -3
View File
@@ -156,10 +156,12 @@ def role(table, name):
)
if mode in REMOTE_MODES:
allowed = {"mode", "host", "host_key", "port"}
if name == "mail":
allowed.add("mail_hostname")
if mode == "remote-install":
allowed |= {"ssh_user", "ssh_identity"}
if name == "mail":
allowed |= {"mail_hostname", "tls", "certificate", "key"}
allowed |= {"tls", "certificate", "key"}
keys(table, allowed, name)
host = table.get("host")
try:
@@ -179,6 +181,10 @@ def role(table, name):
f"Read the pinned {name} SSH public key."
) from None
options = {}
if mode == "remote" and name == "mail":
mail_host = table.get("mail_hostname", "")
if mail_host != "":
options["mail_hostname"] = hostname(mail_host, "mail")
if mode == "remote-install":
user = table.get("ssh_user")
if not isinstance(user, str) or not SSH_USERNAME.fullmatch(user):
@@ -337,8 +343,8 @@ def parse_plan(data):
defaults = hosting_defaults(data.get("hosting", {}))
if defaults.mail_sending_addresses and not mail.mail_hostname:
raise InstallError(
"Provide a local or installer-managed mail hostname when setting "
"mail sending addresses."
"Provide the public mail hostname when setting mail sending "
"addresses."
)
return Plan(
host,
+4 -3
View File
@@ -626,9 +626,10 @@ class Installer:
options["COULOBRE_LOCAL_MAILBOX_PROVISIONING"] = "1"
if self.plan.mail.mode in {"local", "remote-install"}:
options["COULOBRE_MAIL_NODE_DKIM"] = "1"
options["COULOBRE_MAIL_IMAP_HOST"] = self.plan.mail.mail_hostname
options["COULOBRE_MAIL_SUBMISSION_HOST"] = (
self.plan.mail.mail_hostname
if self.plan.mail.mail_hostname:
options.update(
COULOBRE_MAIL_IMAP_HOST=self.plan.mail.mail_hostname,
COULOBRE_MAIL_SUBMISSION_HOST=self.plan.mail.mail_hostname,
)
if self.plan.mail.mode == "local":
options.update(
+2 -1
View File
@@ -31,7 +31,8 @@ MAIL_ROLE = (
)
MAIL_HOSTNAME = (
"The public name mail clients and other mail servers use to reach "
"this mail service."
"this mail service. For an existing remote node, enter the name on "
"its mail certificate or leave it unset."
)
MAIL_TLS = (
"Use acme for Let's Encrypt or provided for certificate and key files "
+2
View File
@@ -166,6 +166,8 @@ def form_plan(fields):
ssh_user=fields.get(f"{name}_ssh_user", ""),
ssh_identity=fields.get(f"{name}_ssh_identity", ""),
)
if name == "mail" and mode == "remote":
target["mail_hostname"] = fields.get("mail_local_host", "")
if name == "mail" and mode in {"local", "remote-install"}:
field = "host" if mode == "local" else "mail_hostname"
target[field] = fields.get("mail_local_host") or (
+4
View File
@@ -2284,6 +2284,10 @@ CNAME from **Check mail DNS**. Use the configured service hostname until
public DNS resolves and the mail service presents a certificate valid for
the alias. Welcome emails list the configured IMAP and submission hostnames
as the defaults.
When connecting an existing remote mail node in the installer, set
`mail_hostname` to its public service name. The SSH host may be private.
An already installed panel uses the client-facing names configured in
`COULOBRE_MAIL_IMAP_HOST` and `COULOBRE_MAIL_SUBMISSION_HOST`.
### Set up signing on a Coulobre mail node
+71 -1
View File
@@ -9,7 +9,11 @@ from pathlib import Path
from types import SimpleNamespace
from unittest.mock import Mock, patch
from deploy.panel_installer.cli import interactive_plan, save_interactive_plan
from deploy.panel_installer.cli import (
export_parameters,
interactive_plan,
save_interactive_plan,
)
from deploy.panel_installer.config import (
InstallError,
parse_plan,
@@ -229,6 +233,72 @@ class InstallerParametersTests(unittest.TestCase):
self.assertEqual(plan.mail.host, "192.0.2.41")
self.assertEqual(plan.mail.host_key, str(path))
self.assertEqual(plan.mail.port, 2222)
self.assertEqual(plan.mail.mail_hostname, "")
def test_existing_mail_node_has_a_separate_public_hostname(self):
with tempfile.TemporaryDirectory() as folder:
path = Path(folder) / "receiver.pub"
path.write_text("ssh-ed25519 fixture-public-host-key\n")
web = form_plan(
PROXY
| ADMIN
| {
"origin_port": "8080",
"mail_mode": "remote",
"mail_host": "192.0.2.41",
"mail_host_key": str(path),
"mail_local_host": "mail.example.net",
"mail_sending_addresses": "93.184.215.14",
}
)
inputs = (
"custom",
"panel.example.net",
"acme",
ADMIN["username"],
ADMIN["email"],
"off",
"remote",
"192.0.2.41",
"",
str(path),
"mail.example.net",
"",
"93.184.215.14",
)
with (
patch("builtins.input", side_effect=inputs),
redirect_stdout(StringIO()),
):
cli = interactive_plan()
for plan in (cli, web):
self.assertEqual(plan.mail.host, "192.0.2.41")
self.assertEqual(plan.mail.mail_hostname, "mail.example.net")
self.assertEqual(
parse_plan(export_parameters(plan, None)), plan
)
with patch(
"deploy.panel_installer.engine.platform_settings",
return_value=(None, True),
):
installer = Installer(plan, "test-only", Mock())
installer.state = dict.fromkeys(
("secret_key", "database_password", "broker_password"),
"test-only",
)
env = dict(
line.split("=", 1)
for line in installer.environment().splitlines()
)
self.assertEqual(
env["COULOBRE_MAIL_IMAP_HOST"], "mail.example.net"
)
self.assertEqual(
env["COULOBRE_MAIL_SUBMISSION_HOST"], "mail.example.net"
)
self.assertEqual(
env["COULOBRE_MAIL_MX_HOST"], "mail.example.net"
)
def test_remote_bootstrap_shares_a_host_between_roles(self):
with tempfile.TemporaryDirectory() as folder: