From 570addf37a215c52979cbc10df4961354f90dd6d Mon Sep 17 00:00:00 2001
From: Peter van Arkel
Date: Sun, 22 Nov 2026 21:43:37 +0100
Subject: [PATCH] Configure panel mail and hosting defaults in the installer
---
deploy/panel_installer/cli.py | 29 ++++++++++++++-
deploy/panel_installer/config.py | 61 +++++++++++++++++++++++++++++---
deploy/panel_installer/engine.py | 47 ++++++++++++++++++++++++
deploy/panel_installer/roles.py | 1 +
deploy/panel_installer/web.py | 17 ++++++++-
5 files changed, 149 insertions(+), 6 deletions(-)
diff --git a/deploy/panel_installer/cli.py b/deploy/panel_installer/cli.py
index 2446a93..1db2c64 100644
--- a/deploy/panel_installer/cli.py
+++ b/deploy/panel_installer/cli.py
@@ -30,6 +30,10 @@ def number(value, label):
raise InstallError(f"Enter a numeric port for {label}.") from None
+def comma_separated(values):
+ return [value.strip() for value in values.split(",") if value.strip()]
+
+
def interactive_plan(previous=None):
if previous is None:
preset = prompt(
@@ -123,6 +127,25 @@ def interactive_plan(previous=None):
target["key"] = ask(
"Private key path on the mail host", name, "key"
)
+ hosting = data["hosting"] = {}
+ for name, label in (
+ ("public_addresses", "IP addresses for hosted websites"),
+ ("nameservers", "Nameservers for new DNS zones"),
+ ("mail_sending_addresses", "Public sending IPs for hosted email"),
+ ):
+ if name == "nameservers" and data["dns"]["mode"] == "off":
+ continue
+ if name == "mail_sending_addresses" and data["mail"]["mode"] not in {
+ "local",
+ "remote-install",
+ }:
+ continue
+ previous_values = defaults.get("hosting", {}).get(name, [])
+ value = prompt(
+ f"{label} (comma-separated, or none)",
+ ", ".join(previous_values) or "none",
+ )
+ hosting[name] = [] if value == "none" else comma_separated(value)
return parse_plan(data)
@@ -156,7 +179,11 @@ def export_parameters(plan, password_path):
admin = {"username": plan.admin_username, "email": plan.admin_email}
if password_path:
admin["password_file"] = password_path
- parameters = {"panel": panel, "admin": admin}
+ parameters = {
+ "panel": panel,
+ "admin": admin,
+ "hosting": plan.hosting.parameters(),
+ }
for name, role in (("dns", plan.dns), ("mail", plan.mail)):
fields = parameters[name] = {"mode": role.mode}
if role.mode in REMOTE_MODES:
diff --git a/deploy/panel_installer/config.py b/deploy/panel_installer/config.py
index 9fa39d4..6d84303 100644
--- a/deploy/panel_installer/config.py
+++ b/deploy/panel_installer/config.py
@@ -214,6 +214,41 @@ def role(table, name):
)
+@dataclass(frozen=True)
+class HostingDefaults:
+ public_addresses: tuple[str, ...] = ()
+ nameservers: tuple[str, ...] = ()
+ mail_sending_addresses: tuple[str, ...] = ()
+
+ def parameters(self):
+ return {name: list(value) for name, value in asdict(self).items()}
+
+
+def hosting_defaults(table):
+ keys(
+ table,
+ {"public_addresses", "nameservers", "mail_sending_addresses"},
+ "hosting",
+ )
+
+ def entries(name, validate):
+ values = table.get(name, [])
+ if not isinstance(values, list) or len(values) > 4:
+ raise InstallError(f"Enter up to four values for {name}.")
+ return tuple(dict.fromkeys(validate(value, name) for value in values))
+
+ public_addresses = entries("public_addresses", address)
+ nameservers = entries("nameservers", hostname)
+ mail_sending_addresses = entries("mail_sending_addresses", address)
+ if any(
+ not ip_address(value).is_global for value in mail_sending_addresses
+ ):
+ raise InstallError("Enter public IP addresses for outgoing mail.")
+ return HostingDefaults(
+ public_addresses, nameservers, mail_sending_addresses
+ )
+
+
@dataclass(frozen=True)
class Plan:
hostname: str
@@ -227,6 +262,7 @@ class Plan:
admin_email: str
dns: Role
mail: Role
+ hosting: HostingDefaults = HostingDefaults()
def description(self):
def target(role):
@@ -234,18 +270,27 @@ class Plan:
return f"{role.mode} ({role.host}, SSH port {role.port})"
return role.mode
- return (
+ summary = (
f"https://{self.hostname}/ · {self.access} · "
f"DNS {target(self.dns)} · mail {target(self.mail)} · "
f"Administrator {self.admin_username}"
)
+ if self.hosting.public_addresses:
+ summary += " · Web IPs " + ", ".join(self.hosting.public_addresses)
+ if self.hosting.nameservers:
+ summary += " · Nameservers " + ", ".join(self.hosting.nameservers)
+ if self.hosting.mail_sending_addresses:
+ summary += " · Mail sending IPs " + ", ".join(
+ self.hosting.mail_sending_addresses
+ )
+ return summary
def record(self):
- return asdict(self)
+ return {**asdict(self), "hosting": self.hosting.parameters()}
def parse_plan(data):
- keys(data, {"panel", "admin", "dns", "mail"}, "installation")
+ keys(data, {"panel", "admin", "dns", "mail", "hosting"}, "installation")
panel = data.get("panel")
admin = data.get("admin")
keys(admin, {"username", "email", "password_file"}, "admin")
@@ -288,6 +333,13 @@ def parse_plan(data):
)
else:
raise InstallError("Choose tls, acme, or proxy for panel access.")
+ mail = role(data.get("mail", {}), "mail")
+ 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."
+ )
return Plan(
host,
access,
@@ -299,7 +351,8 @@ def parse_plan(data):
username,
email,
role(data.get("dns", {}), "dns"),
- role(data.get("mail", {}), "mail"),
+ mail,
+ defaults,
)
diff --git a/deploy/panel_installer/engine.py b/deploy/panel_installer/engine.py
index 24e3e27..4211370 100644
--- a/deploy/panel_installer/engine.py
+++ b/deploy/panel_installer/engine.py
@@ -4,6 +4,7 @@ import json
import os
import pwd
import secrets
+import smtplib
import socket
import stat
import subprocess
@@ -551,6 +552,7 @@ class Installer:
"COULOBRE_ALLOWED_HOSTS": self.plan.hostname,
"COULOBRE_HTTPS_PROXY": "1",
"COULOBRE_REQUIRE_PRIVILEGED_MFA": "1",
+ "COULOBRE_PASSWORD_RESET_ORIGIN": f"https://{self.plan.hostname}",
"COULOBRE_TRUST_APACHE_CLIENT_IP": "1",
"COULOBRE_STATIC_ROOT": str(STATIC),
"COULOBRE_SECRET_KEY": self.state["secret_key"],
@@ -572,8 +574,49 @@ class Installer:
options["COULOBRE_LOCAL_MAILBOX_PROVISIONING"] = "1"
if self.plan.mail.mode in {"local", "remote-install"}:
options["COULOBRE_MAIL_NODE_DKIM"] = "1"
+ if self.plan.mail.mode == "local":
+ options.update(
+ COULOBRE_SMTP_HOST="127.0.0.1",
+ COULOBRE_SMTP_PORT="25",
+ COULOBRE_SMTP_STARTTLS="0",
+ COULOBRE_EMAIL_FROM=f"panel@{self.plan.mail.host}",
+ )
+ hosting = self.plan.hosting
+ if hosting.public_addresses:
+ options["COULOBRE_HOSTING_PUBLIC_ADDRESSES"] = ",".join(
+ hosting.public_addresses
+ )
+ if hosting.nameservers:
+ options["COULOBRE_HOSTING_NAMESERVERS"] = ",".join(
+ hosting.nameservers
+ )
+ if hosting.mail_sending_addresses:
+ options.update(
+ COULOBRE_MAIL_MX_HOST=self.plan.mail.mail_hostname,
+ COULOBRE_MAIL_SENDING_IPS=",".join(
+ hosting.mail_sending_addresses
+ ),
+ COULOBRE_MANAGE_MAIL_DNS="1",
+ )
return "".join(f"{key}={value}\n" for key, value in options.items())
+ def verify_notification_mail(self):
+ if self.plan.mail.mode != "local":
+ return
+ try:
+ with smtplib.SMTP("127.0.0.1", 25, timeout=8) as relay:
+ relay.ehlo_or_helo_if_needed()
+ mail_code, _ = relay.mail(f"panel@{self.plan.mail.host}")
+ recipient_code, _ = relay.rcpt("smtp-check@example.invalid")
+ relay.rset()
+ if mail_code != 250 or recipient_code not in (250, 251):
+ raise OSError("Loopback SMTP relay rejected the envelope.")
+ except OSError as error:
+ raise InstallError(
+ "Local Postfix did not accept outgoing panel mail over "
+ "loopback. Check journalctl -u postfix and the relay policy."
+ ) from error
+
def prepare_panel(self):
panel = identity("coulobre-panel")
root_directory(ETC, mode=0o750)
@@ -708,6 +751,7 @@ class Installer:
"Coulobre is already installed with these settings."
)
self.verify_panel()
+ self.verify_notification_mail()
return
self.progress(
"Installing system packages and the Coulobre release."
@@ -793,6 +837,9 @@ class Installer:
)
systemctl("reload", "apache2.service")
self.verify_panel()
+ if self.plan.mail.mode == "local":
+ with self.step("Checking Postfix for outgoing panel email"):
+ self.verify_notification_mail()
for key in ("secret_key", "database_password", "broker_password"):
self.state.pop(key, None)
self.state["complete"] = True
diff --git a/deploy/panel_installer/roles.py b/deploy/panel_installer/roles.py
index 9cbe672..3191865 100644
--- a/deploy/panel_installer/roles.py
+++ b/deploy/panel_installer/roles.py
@@ -132,6 +132,7 @@ def configure_mail(target, modern):
"myhostname": target.host,
"mydestination": "$myhostname, localhost",
"inet_interfaces": "all",
+ "mynetworks": "127.0.0.0/8 [::1]/128",
"virtual_mailbox_domains": (
"proxy:texthash:/etc/postfix/coulobre-domains"
),
diff --git a/deploy/panel_installer/web.py b/deploy/panel_installer/web.py
index 5f34a0a..aef6f0b 100644
--- a/deploy/panel_installer/web.py
+++ b/deploy/panel_installer/web.py
@@ -9,7 +9,7 @@ from http.server import BaseHTTPRequestHandler, HTTPServer
from threading import Thread
from urllib.parse import parse_qs
-from .cli import number
+from .cli import comma_separated, number
from .config import REMOTE_MODES, InstallError, parse_plan, port
from .engine import Installer
@@ -36,6 +36,13 @@ for a different deployment.
{dns}{mail}
+
"""
STYLE = """body{font:1rem system-ui,sans-serif;max-width:46rem;margin:auto;
padding:1rem;color:#14372e} fieldset{margin:1rem 0;border:1px solid #a9beb2;
@@ -100,6 +107,14 @@ def form_plan(fields):
)
data = {
"panel": panel,
+ "hosting": {
+ name: comma_separated(fields.get(name, ""))
+ for name in (
+ "public_addresses",
+ "nameservers",
+ "mail_sending_addresses",
+ )
+ },
"admin": {
"username": fields.get("username", ""),
"email": fields.get("email", ""),