diff --git a/cmdeploy/src/cmdeploy/deployers.py b/cmdeploy/src/cmdeploy/deployers.py index 0314528e..95f366a9 100644 --- a/cmdeploy/src/cmdeploy/deployers.py +++ b/cmdeploy/src/cmdeploy/deployers.py @@ -141,6 +141,10 @@ def _configure_remote_venv_with_chatmaild(config) -> None: class UnboundDeployer(Deployer): + def __init__(self, config): + self.config = config + self.need_restart = False + def install(self): # Run local DNS resolver `unbound`. # `resolvconf` takes care of setting up /etc/resolv.conf @@ -177,6 +181,27 @@ class UnboundDeployer(Deployer): "unbound-anchor -a /var/lib/unbound/root.key || true", ], ) + if self.config.disable_ipv6: + files.directory( + path="/etc/unbound/unbound.conf.d", + present=True, + user="root", + group="root", + mode="755", + ) + conf = files.put( + src=get_resource("unbound/unbound.conf.j2"), + dest="/etc/unbound/unbound.conf.d/chatmail.conf", + user="root", + group="root", + mode="644", + ) + else: + conf = files.file( + path="/etc/unbound/unbound.conf.d/chatmail.conf", + present=False, + ) + self.need_restart |= conf.changed def activate(self): server.shell( @@ -191,6 +216,7 @@ class UnboundDeployer(Deployer): service="unbound.service", running=True, enabled=True, + restarted=self.need_restart, ) @@ -565,7 +591,7 @@ def deploy_chatmail(config_path: Path, disable_mail: bool, website_only: bool) - LegacyRemoveDeployer(), FiltermailDeployer(), JournaldDeployer(), - UnboundDeployer(), + UnboundDeployer(config), TurnDeployer(mail_domain), IrohDeployer(config.enable_iroh_relay), AcmetoolDeployer(config.acme_email, tls_domains), diff --git a/cmdeploy/src/cmdeploy/dovecot/dovecot.conf.j2 b/cmdeploy/src/cmdeploy/dovecot/dovecot.conf.j2 index 69d76c5b..8ab2de56 100644 --- a/cmdeploy/src/cmdeploy/dovecot/dovecot.conf.j2 +++ b/cmdeploy/src/cmdeploy/dovecot/dovecot.conf.j2 @@ -1,7 +1,7 @@ ## Dovecot configuration file {% if disable_ipv6 %} -listen = * +listen = 0.0.0.0 {% endif %} protocols = imap lmtp diff --git a/cmdeploy/src/cmdeploy/postfix/main.cf.j2 b/cmdeploy/src/cmdeploy/postfix/main.cf.j2 index 8fee07f2..5c624362 100644 --- a/cmdeploy/src/cmdeploy/postfix/main.cf.j2 +++ b/cmdeploy/src/cmdeploy/postfix/main.cf.j2 @@ -64,7 +64,11 @@ alias_database = hash:/etc/aliases mydestination = relayhost = +{% if disable_ipv6 %} +mynetworks = 127.0.0.0/8 +{% else %} mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 +{% endif %} mailbox_size_limit = 0 message_size_limit = {{config.max_message_size}} recipient_delimiter = + diff --git a/cmdeploy/src/cmdeploy/unbound/unbound.conf.j2 b/cmdeploy/src/cmdeploy/unbound/unbound.conf.j2 new file mode 100644 index 00000000..8fff4c71 --- /dev/null +++ b/cmdeploy/src/cmdeploy/unbound/unbound.conf.j2 @@ -0,0 +1,4 @@ +# Managed by cmdeploy: disable IPv6 in unbound. +server: + interface: 127.0.0.1 + do-ip6: no