2023-03-01 16:34:15 +01:00
|
|
|
{ config, pkgs, lib, ... }:
|
2022-12-17 21:33:45 +01:00
|
|
|
let
|
2023-01-06 16:57:26 +01:00
|
|
|
hostname = "mail.${config.fsr.domain}";
|
|
|
|
domain = config.fsr.domain;
|
2023-02-03 16:04:45 +01:00
|
|
|
rspamd-domain = "rspamd.${config.fsr.domain}";
|
2023-01-27 16:39:25 +01:00
|
|
|
dovecot-ldap-args = pkgs.writeText "ldap-args" ''
|
2023-02-03 15:37:56 +01:00
|
|
|
uris = ldap://localhost
|
|
|
|
dn = uid=search, ou=users, dc=ifsr, dc=de
|
2023-01-27 16:39:25 +01:00
|
|
|
auth_bind = yes
|
2023-02-15 14:47:14 +01:00
|
|
|
!include ${config.sops.secrets."dovecot_ldap_search".path}
|
2023-02-03 15:37:56 +01:00
|
|
|
|
2023-01-27 16:39:25 +01:00
|
|
|
ldap_version = 3
|
|
|
|
scope = subtree
|
2023-02-03 15:37:56 +01:00
|
|
|
base = dc=ifsr, dc=de
|
2023-06-13 20:17:20 +02:00
|
|
|
user_filter = (&(objectClass=posixAccount)(uid=%n))
|
|
|
|
pass_filter = (&(objectClass=posixAccount)(uid=%n))
|
2023-01-27 16:39:25 +01:00
|
|
|
'';
|
2022-12-17 21:33:45 +01:00
|
|
|
in
|
|
|
|
{
|
2023-01-09 18:14:32 +01:00
|
|
|
sops.secrets."rspamd-password".owner = config.users.users.rspamd.name;
|
2023-02-15 14:47:14 +01:00
|
|
|
sops.secrets."dovecot_ldap_search".owner = config.services.dovecot2.user;
|
2023-07-03 18:22:37 +02:00
|
|
|
sops.secrets."postfix_ldap_aliases".owner = config.services.postfix.user;
|
2023-01-06 16:57:26 +01:00
|
|
|
|
2023-07-03 18:22:37 +02:00
|
|
|
networking.firewall.allowedTCPPorts = [
|
|
|
|
25 # insecure SMTP
|
|
|
|
465
|
|
|
|
587 # SMTP
|
|
|
|
993 # IMAP
|
2023-07-04 14:00:06 +02:00
|
|
|
4190 # sieve
|
2023-07-03 18:22:37 +02:00
|
|
|
];
|
2023-03-01 15:44:04 +01:00
|
|
|
users.users.postfix.extraGroups = [ "opendkim" ];
|
2023-01-06 16:57:26 +01:00
|
|
|
|
2022-12-17 21:33:45 +01:00
|
|
|
services = {
|
|
|
|
postfix = {
|
|
|
|
enable = true;
|
2023-05-31 14:58:26 +02:00
|
|
|
enableSubmission = true;
|
2023-02-24 17:11:53 +01:00
|
|
|
enableSubmissions = true;
|
2022-12-17 21:33:45 +01:00
|
|
|
hostname = "${hostname}";
|
|
|
|
domain = "${domain}";
|
|
|
|
origin = "${domain}";
|
|
|
|
destination = [ "${hostname}" "${domain}" "localhost" ];
|
2023-07-06 01:10:47 +02:00
|
|
|
networksStyle = "host"; # localhost and own public IP
|
2023-01-06 16:57:26 +01:00
|
|
|
sslCert = "/var/lib/acme/${hostname}/fullchain.pem";
|
|
|
|
sslKey = "/var/lib/acme/${hostname}/key.pem";
|
2023-04-04 00:04:04 +02:00
|
|
|
relayDomains = [ "hash:/var/lib/mailman/data/postfix_domains" ];
|
|
|
|
|
2023-03-24 16:24:18 +01:00
|
|
|
extraAliases = ''
|
|
|
|
# Taken from kaki, maybe we can throw out some at some point
|
|
|
|
# General redirections for pseudo accounts
|
|
|
|
bin: root
|
|
|
|
daemon: root
|
|
|
|
named: root
|
|
|
|
nobody: root
|
|
|
|
uucp: root
|
|
|
|
www: root
|
|
|
|
ftp-bugs: root
|
|
|
|
postfix: root
|
|
|
|
|
|
|
|
# Well-known aliases
|
|
|
|
manager: root
|
|
|
|
dumper: root
|
|
|
|
operator: root
|
|
|
|
abuse: postmaster
|
2023-07-06 01:10:47 +02:00
|
|
|
postmaster: root
|
2023-03-24 16:24:18 +01:00
|
|
|
|
|
|
|
# trap decode to catch security attacks
|
|
|
|
decode: root
|
2023-07-06 01:10:47 +02:00
|
|
|
|
|
|
|
# yeet into the void
|
|
|
|
noreply: /dev/null
|
2023-03-24 16:24:18 +01:00
|
|
|
'';
|
2022-12-17 21:33:45 +01:00
|
|
|
config = {
|
2023-03-22 11:19:15 +01:00
|
|
|
home_mailbox = "Maildir/";
|
2023-03-01 15:44:04 +01:00
|
|
|
smtp_use_tls = true;
|
2023-07-03 18:22:37 +02:00
|
|
|
# smtp_tls_security_level = "encrypt";
|
2023-03-01 15:44:04 +01:00
|
|
|
smtpd_use_tls = true;
|
2023-07-03 18:22:37 +02:00
|
|
|
# smtpd_tls_security_level = lib.mkForce "encrypt";
|
|
|
|
# smtpd_tls_auth_only = true;
|
2023-03-01 15:44:04 +01:00
|
|
|
smtpd_tls_protocols = [
|
|
|
|
"!SSLv2"
|
|
|
|
"!SSLv3"
|
|
|
|
"!TLSv1"
|
|
|
|
"!TLSv1.1"
|
|
|
|
];
|
2023-07-03 18:22:37 +02:00
|
|
|
# "reject_non_fqdn_hostname"
|
2022-12-17 21:33:45 +01:00
|
|
|
smtpd_recipient_restrictions = [
|
2023-02-24 17:11:53 +01:00
|
|
|
"permit_sasl_authenticated"
|
|
|
|
"permit_mynetworks"
|
2022-12-17 21:33:45 +01:00
|
|
|
"reject_unauth_destination"
|
2023-03-01 15:44:04 +01:00
|
|
|
"reject_non_fqdn_sender"
|
|
|
|
"reject_non_fqdn_recipient"
|
|
|
|
"reject_unknown_sender_domain"
|
|
|
|
"reject_unknown_recipient_domain"
|
|
|
|
"reject_unauth_destination"
|
|
|
|
"reject_unauth_pipelining"
|
|
|
|
"reject_invalid_hostname"
|
2023-02-24 17:11:53 +01:00
|
|
|
];
|
|
|
|
smtpd_relay_restrictions = [
|
2022-12-17 21:33:45 +01:00
|
|
|
"permit_sasl_authenticated"
|
|
|
|
"permit_mynetworks"
|
2023-02-24 17:11:53 +01:00
|
|
|
"reject_unauth_destination"
|
2022-12-17 21:33:45 +01:00
|
|
|
];
|
2023-07-03 18:22:37 +02:00
|
|
|
# smtpd_sender_login_maps = [ "ldap:${ldap-senders}" ];
|
|
|
|
alias_maps = [ "hash:/etc/aliases" ];
|
|
|
|
# alias_maps = [ "hash:/etc/aliases" "ldap:${ldap-aliases}" ];
|
2023-03-01 15:44:04 +01:00
|
|
|
smtpd_milters = [ "local:/run/opendkim/opendkim.sock" ];
|
2023-03-01 15:23:07 +01:00
|
|
|
non_smtpd_milters = [ "local:/var/run/opendkim/opendkim.sock" ];
|
2022-12-17 21:33:45 +01:00
|
|
|
smtpd_sasl_auth_enable = true;
|
|
|
|
smtpd_sasl_path = "/var/lib/postfix/auth";
|
2023-02-24 17:11:53 +01:00
|
|
|
smtpd_sasl_type = "dovecot";
|
2023-04-04 00:04:04 +02:00
|
|
|
#mailman stuff
|
2023-07-04 14:00:06 +02:00
|
|
|
local_transport = "lmtp:unix:/run/dovecot2/dovecot-lmtp";
|
|
|
|
|
2023-04-04 00:04:04 +02:00
|
|
|
transport_maps = [ "hash:/var/lib/mailman/data/postfix_lmtp" ];
|
2023-07-03 18:22:37 +02:00
|
|
|
local_recipient_maps = [ "hash:/var/lib/mailman/data/postfix_lmtp" "ldap:${config.sops.secrets."postfix_ldap_aliases".path}" ];
|
2022-12-17 21:33:45 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
dovecot2 = {
|
|
|
|
enable = true;
|
|
|
|
enableImap = true;
|
|
|
|
enableQuota = false;
|
2023-07-04 14:00:06 +02:00
|
|
|
enableLmtp = true;
|
2023-03-24 15:51:57 +01:00
|
|
|
mailLocation = "maildir:~/Maildir";
|
2023-01-06 16:57:26 +01:00
|
|
|
sslServerCert = "/var/lib/acme/${hostname}/fullchain.pem";
|
|
|
|
sslServerKey = "/var/lib/acme/${hostname}/key.pem";
|
2023-07-04 14:00:06 +02:00
|
|
|
protocols = [ "imap" "sieve" ];
|
|
|
|
mailPlugins = {
|
|
|
|
perProtocol = {
|
|
|
|
imap = {
|
|
|
|
enable = [ ];
|
|
|
|
};
|
|
|
|
lmtp = {
|
|
|
|
enable = [ "sieve" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2022-12-17 21:33:45 +01:00
|
|
|
mailboxes = {
|
|
|
|
Spam = {
|
|
|
|
auto = "create";
|
|
|
|
specialUse = "Junk";
|
|
|
|
};
|
|
|
|
Sent = {
|
|
|
|
auto = "create";
|
|
|
|
specialUse = "Sent";
|
|
|
|
};
|
|
|
|
Drafts = {
|
|
|
|
auto = "create";
|
|
|
|
specialUse = "Drafts";
|
|
|
|
};
|
|
|
|
Trash = {
|
|
|
|
auto = "create";
|
|
|
|
specialUse = "Trash";
|
|
|
|
};
|
|
|
|
};
|
2023-07-04 14:00:06 +02:00
|
|
|
modules = [
|
|
|
|
pkgs.dovecot_pigeonhole
|
|
|
|
];
|
2022-12-17 21:33:45 +01:00
|
|
|
extraConfig = ''
|
2023-07-06 01:10:47 +02:00
|
|
|
auth_username_format = %Ln
|
|
|
|
passdb {
|
|
|
|
driver = ldap
|
|
|
|
args = ${dovecot-ldap-args}
|
|
|
|
}
|
|
|
|
userdb {
|
|
|
|
driver = ldap
|
|
|
|
args = ${dovecot-ldap-args}
|
|
|
|
}
|
|
|
|
service auth {
|
|
|
|
unix_listener /var/lib/postfix/auth {
|
|
|
|
group = postfix
|
|
|
|
mode = 0660
|
|
|
|
user = postfix
|
2023-07-04 14:00:06 +02:00
|
|
|
}
|
2023-07-06 01:10:47 +02:00
|
|
|
}
|
|
|
|
service managesieve-login {
|
|
|
|
inet_listener sieve {
|
|
|
|
port = 4190
|
2023-07-04 14:00:06 +02:00
|
|
|
}
|
2023-07-06 01:10:47 +02:00
|
|
|
service_count = 1
|
|
|
|
}
|
|
|
|
service lmtp {
|
|
|
|
unix_listener dovecot-lmtp {
|
|
|
|
group = postfix
|
|
|
|
mode = 0600
|
|
|
|
user = postfix
|
2023-07-04 14:00:06 +02:00
|
|
|
}
|
2023-07-06 01:10:47 +02:00
|
|
|
client_limit = 1
|
|
|
|
}
|
2023-03-01 15:23:07 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
opendkim = {
|
|
|
|
enable = true;
|
|
|
|
domains = "csl:${config.fsr.domain}";
|
|
|
|
selector = config.networking.hostName;
|
|
|
|
configFile = pkgs.writeText "opendkim-config" ''
|
2023-07-06 01:10:47 +02:00
|
|
|
UMask 0117
|
2022-12-17 21:33:45 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
rspamd = {
|
|
|
|
enable = true;
|
2023-01-06 16:57:26 +01:00
|
|
|
postfix.enable = true;
|
|
|
|
locals = {
|
|
|
|
"worker-controller.inc".source = config.sops.secrets."rspamd-password".path;
|
2023-01-09 18:14:32 +01:00
|
|
|
"redis.conf".text = ''
|
|
|
|
read_servers = "127.0.0.1";
|
|
|
|
write_servers = "127.0.0.1";
|
|
|
|
'';
|
2023-02-03 15:50:36 +01:00
|
|
|
};
|
2023-01-09 18:14:32 +01:00
|
|
|
};
|
|
|
|
redis = {
|
|
|
|
vmOverCommit = true;
|
|
|
|
servers.rspamd = {
|
|
|
|
enable = true;
|
|
|
|
port = 6379;
|
2022-12-17 21:33:45 +01:00
|
|
|
};
|
|
|
|
};
|
2023-01-06 16:57:26 +01:00
|
|
|
nginx = {
|
2022-12-17 21:33:45 +01:00
|
|
|
enable = true;
|
2023-01-09 18:14:32 +01:00
|
|
|
recommendedGzipSettings = true;
|
|
|
|
recommendedOptimisation = true;
|
|
|
|
recommendedProxySettings = true;
|
|
|
|
recommendedTlsSettings = true;
|
|
|
|
|
2023-01-06 16:57:26 +01:00
|
|
|
virtualHosts."${hostname}" = {
|
|
|
|
forceSSL = true;
|
|
|
|
enableACME = true;
|
2023-02-03 16:04:45 +01:00
|
|
|
};
|
|
|
|
virtualHosts."${rspamd-domain}" = {
|
|
|
|
forceSSL = true;
|
|
|
|
enableACME = true;
|
2023-01-09 18:14:32 +01:00
|
|
|
locations = {
|
2023-02-03 16:04:45 +01:00
|
|
|
"/" = {
|
|
|
|
proxyPass = "http://127.0.0.1:11334";
|
2023-01-09 18:14:32 +01:00
|
|
|
proxyWebsockets = true;
|
|
|
|
};
|
|
|
|
};
|
2023-01-06 16:57:26 +01:00
|
|
|
};
|
2022-12-17 21:33:45 +01:00
|
|
|
};
|
|
|
|
};
|
2023-05-25 22:43:16 +02:00
|
|
|
security.acme.certs."${domain}" = {
|
|
|
|
reloadServices = [
|
|
|
|
"postfix.service"
|
|
|
|
"dovecot2.service"
|
|
|
|
];
|
|
|
|
};
|
2022-12-17 21:33:45 +01:00
|
|
|
}
|