Etape 9 – Le serveur de MAIL : Postfix / Dovecot / Rspamd
- Introduction
- Etape 1 (V1) – Installation – Boot EFI & ZFS on Debian Bullseye avec Proxmox (sans cryptage / serveur local)
- Prochainement: Etape 1 (V2) – Installation – Disque crypté LUKS RAID & Debian Bullseye avec Proxmox
- Etape 1 (V1) – Installation – ZFS Native Encryption & Debian Bullseye avec Proxmox
- Etape 2 – Le firewall IPv4 : Shorewall
- Etape 3 – Le firewall IPv6 : Shorewall6
- Etape 4 – Le serveur DHCP : isc-dhcp-server
- Etape 5 – Le serveur DNS : Bind9
- Etape 6 – La base de données : MariaDB
- Etape 7 – Le serveur WEB : Nginx & SSL (Let’s Encrypt)
- Etape 8 – Le partage de fichier : SAMBA (Compatible Time Machine Monterey)
- Etape 9 – Le serveur de MAIL : Postfix / Dovecot / Rspamd
1. Principe général
Un serveur de courrier est en réalité composé de 2 types de serveur :
– Un serveur qui va servir à envoyer/recevoir les mails, c’est ce que l’on appelle un MTA (Mail Transfer Agent) ici Postfix
– Un serveur qui stocke les mails et les mets à dispositions des utilisateurs (en IMAP/POP), c’est à dire un MDA (Mail Delivery Agent) ici Dovecot
La mise en place est assez complexe car il existe de nombreuses possibilités d’optimisation (ce que l’on va faire ici) :
– Mettre un système de filtre anti-spam (Rspamd)
– Mettre un anti-virus (intégré à Rspamd)
2. Postfix
2.1 Installation
2.1.1 Le programme
apt update
apt upgrade
apt install --yes postfix postfix-mysql
On vous demande votre type de configuration : vous choisissez « Pas de configuration ».
2.1.2 La base de données
Après avoir installé une base de donnée (cf article sur MariaDB).
- Créez un utilisateur dédié pour cette base en lui donnant tous les droits sur la base.
- Puis créez la base de donnée :
CREATE DATABASE IF NOT EXISTS `maildatabase` CHARACTER SET utf8 COLLATE utf8_general_ci;
USE `maildatabase`;
CREATE TABLE `alias` (
`source` VarChar( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`regalias` TinyInt( 1 ) NOT NULL DEFAULT '0',
`active` TinyInt( 1 ) NOT NULL DEFAULT '1',
`destination` VarChar( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
PRIMARY KEY ( `source` ) )
CHARACTER SET = utf8
COLLATE = utf8_general_ci
ENGINE = MyISAM;
CREATE TABLE `blacklist` (
`source` VarChar( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`message` VarChar( 128 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`active` TinyInt( 1 ) NOT NULL DEFAULT '0',
`type` Enum( 'recipient', 'sender' ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
PRIMARY KEY ( `source` ) )
CHARACTER SET = utf8
COLLATE = utf8_general_ci
ENGINE = MyISAM;
CREATE TABLE `domains` (
`domain` VarChar( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`active` TinyInt( 1 ) NOT NULL DEFAULT '1',
PRIMARY KEY ( `domain` ) )
CHARACTER SET = utf8
COLLATE = utf8_general_ci
ENGINE = MyISAM;
CREATE TABLE `quotadict` (
`username` VarChar( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`bytes` BigInt( 20 ) NOT NULL DEFAULT '0',
`messages` Int( 11 ) NOT NULL DEFAULT '0',
PRIMARY KEY ( `username` ) )
CHARACTER SET = utf8
COLLATE = utf8_general_ci
ENGINE = MyISAM;
CREATE TABLE `relay` (
`domain` VarChar( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`active` TinyInt( 1 ) NOT NULL DEFAULT '1',
PRIMARY KEY ( `domain` ) )
CHARACTER SET = utf8
COLLATE = utf8_general_ci
ENGINE = MyISAM;
CREATE TABLE `senders` (
`sender` VarChar( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`active` TinyInt( 1 ) NOT NULL DEFAULT '1',
`origine` VarChar( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`regsender` TinyInt( 1 ) NOT NULL DEFAULT '0' )
CHARACTER SET = utf8
COLLATE = utf8_general_ci
ENGINE = MyISAM;
CREATE TABLE `transport` (
`domain` VarChar( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`transport` VarChar( 128 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`active` TinyInt( 1 ) NOT NULL,
PRIMARY KEY ( `domain` ) )
CHARACTER SET = utf8
COLLATE = utf8_general_ci
ENGINE = MyISAM;
CREATE TABLE `users` (
`email` VarChar( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`password` VarChar( 40 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`quota` VarChar( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0',
`active` TinyInt( 1 ) NOT NULL DEFAULT '0',
PRIMARY KEY ( `email` ) )
CHARACTER SET = utf8
COLLATE = utf8_general_ci
ENGINE = MyISAM;
2.2 Configuration
2.2.1 Editez le fichier /etc/postfix/main.cf
## Configuration de postfix
# Identification de la machine
myhostname = mail.mondomaine.net
smtpd_banner = $myhostname ESMTP server ready
biff = no
# Securisation
# Mode de comptabilité
compatibility_level = 2
# On empeche tout utilistateur d'envoyer des mails
authorized_submit_users =
# On rejete les mails locaux non connus par une erreur 550 (valeur par défaut)
unknown_local_recipient_reject_code = 550
# On interdit les noms incomplets (valeur par défaut)
append_dot_mydomain = no
# Specification de l'interface
inet_protocols = ipv4, ipv6
inet_interfaces = 127.0.0.1, MON.IP.V.4, [::1], [MON::IP::V6]
smtp_bind_address = MON.IP.V.4
smtp_bind_address6 = MON::IP::V6
mynetworks = 127.0.0.1, MON.IP.V.4, [::1], [MON::IP::V6]
relayhost =
# Taille des messages (25Mo)
message_size_limit = 25360000
# Configuration des domaines pris en charges :
alias_maps =
alias_database =
virtual_minimum_uid = 5000
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
virtual_mailbox_base = /var/mails
virtual_mailbox_domains = mysql:/etc/postfix/sql/virtual_domains_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/sql/virtual_mailbox_maps.cf
virtual_alias_maps = mysql:/etc/postfix/sql/virtual_alias_maps.cf mysql:/etc/postfix/sql/virtual_alias_mail2mail.cf mysql:/etc/postfix/sql/virtual_alias_regexp.cf
virtual_transport = lmtp:unix:private/dovecot-lmtp
# On specifie les domaines relayés
relay_domains = mysql:/etc/postfix/sql/virtual_relay.cf
# Regles SMTP
disable_vrfy_command = yes
smtpd_discard_ehlo_keywords = ETRN
smtpd_etrn_restrictions = permit_mynetworks, reject
fast_flush_domains =
smtpd_relay_restrictions =
permit_mynetworks,
permit_sasl_authenticated,
reject_unauth_destination
# Dans l'ordre postfix filtre :
# Client -> HELO -> Sender (MAIL FROM) -> Recipient (RCPT TO)
# Filtrage selon le CLIENT
smtpd_client_restrictions =
permit_mynetworks,
sleep 1,
reject_unauth_pipelining,
permit
# Filtrage selon le HELO
# Desactivé car il existe malheureusement encore des serveurs mal configurés
#smtpd_helo_restrictions = reject_invalid_helo_hostname, reject_unknown_helo_hostname
# Filtrage selon le MAIL FROM
smtpd_sender_restrictions =
permit_mynetworks,
reject_non_fqdn_sender,
reject_unknown_sender_domain,
check_sender_access mysql:/etc/postfix/sql/virtual_blacklist_sender.cf,
permit
# Filtrage selon le RCPT TO
smtpd_recipient_restrictions =
permit_mynetworks,
check_recipient_access mysql:/etc/postfix/sql/virtual_blacklist_recipient.cf,
reject_invalid_hostname,
reject_non_fqdn_hostname,
reject_non_fqdn_recipient,
reject_unauth_destination,
reject_unknown_recipient_domain,
reject_rbl_client zen.spamhaus.org,
check_policy_service unix:private/quota-status,
permit
# Reglage specifique qui ralentie la cadence d'envoi de mail
# Utile pour les serveurs d'orange/wanadoo
slow_destination_recipient_limit = 20
slow_destination_concurrency_limit = 2
transport_maps = mysql:/etc/postfix/sql/virtual_transport.cf
# Antispam
smtpd_milters = inet:localhost:11332
non_smtpd_milters = $smtpd_milters
milter_default_action = accept
milter_mail_macros = i {mail_addr} {client_addr} {client_name} {auth_authen}
2.2.2 Editez le fichier /etc/postfix/master.cf
#
# Do not forget to execute "postfix reload" after editing this file.
#
# ==========================================================================
# service type private unpriv chroot wakeup maxproc command + args
# (yes) (yes) (no) (never) (100)
# ==========================================================================
smtp inet n - y - - smtpd
pickup unix n - y 60 1 pickup
cleanup unix n - y - 0 cleanup
qmgr unix n - n 300 1 qmgr
tlsmgr unix - - y 1000? 1 tlsmgr
rewrite unix - - y - - trivial-rewrite
bounce unix - - y - 0 bounce
defer unix - - y - 0 bounce
trace unix - - y - 0 bounce
verify unix - - y - 1 verify
flush unix n - y 1000? 0 flush
proxymap unix - - n - - proxymap
proxywrite unix - - n - 1 proxymap
smtp unix - - y - - smtp
relay unix - - y - - smtp
showq unix n - y - - showq
error unix - - y - - error
retry unix - - y - - error
discard unix - - y - - discard
local unix - n n - - local
virtual unix - n n - - virtual
lmtp unix - - y - - lmtp
anvil unix - - y - 1 anvil
scache unix - - y - 1 scache
# Transport slow pour orange/wanadoo & co.
slow unix - - n - 5 smtp
-o syslog_name=postfix-slow
-o smtp_destination_concurrency_limit=3
-o slow_destination_rate_delay=1
# Port submission (587) pour authentification
submission inet n - - - - smtpd
-o smtpd_tls_security_level=encrypt
-o smtpd_sasl_auth_enable=yes
-o smtp_enforce_tls=yes
-o smtp_tls_enforce_peername=no
-o smtpd_tls_auth_only=yes
-o smtpd_sasl_type=dovecot
-o smtpd_sasl_path=private/auth
-o smtpd_sasl_authenticated_header=no
-o broken_sasl_auth_clients=yes
-o smtpd_sasl_security_options=noanonymous
-o smtpd_sasl_local_domain=
-o smtpd_client_restrictions=permit_sasl_authenticated,reject
-o smtpd_tls_cert_file=/etc/letsencrypt/live/mondomaine.net/fullchain.pem
-o smtpd_tls_key_file=/etc/letsencrypt/live/mondomaine.net/privkey.pem
-o smtpd_sender_login_maps=mysql:/etc/postfix/sql/virtual_senders_maps.cf,mysql:/etc/postfix/sql/virtual_senders_regexp.cf
-o smtpd_sender_restrictions=reject_sender_login_mismatch
-o smtpd_recipient_restrictions=reject_non_fqdn_recipient,reject_non_fqdn_sender,reject_invalid_hostname,reject_non_fqdn_hostname,reject_unknown_recipient_domain,permit_sasl_authenticated,reject
2.2.3 Fichiers SQL
- Commencez par créer le repertoire
/etc/postfix/sql
mkdir /etc/postfix/sql
chmod 700 /etc/postfix/sql
- Puis créez tous ces fichiers (en modifiant le login / mot de passe en fonction de votre installation) :
/etc/postfix/sql/virtual_alias_mail2mail.cf
user = mailadmin
password = mot2passe
hosts = 127.0.0.1
dbname = maildatabase
query = SELECT email FROM users WHERE email = '%s' AND active = '1'
/etc/postfix/sql/virtual_alias_regexp.cf
user = mailadmin
password = mot2passe
hosts = 127.0.0.1
dbname = maildatabase
query = SELECT destination FROM alias WHERE '%s' REGEXP CONCAT('^',source,'$') AND SUBSTRING(source,1,1) != '@' AND regalias = '1' AND active = '1
/etc/postfix/sql/virtual_blacklist_recipient.cf
user = mailadmin
password = mot2passe
hosts = 127.0.0.1
dbname = maildatabase
query = SELECT message FROM blacklist WHERE source = '%s' AND type = 'recipient' AND active = '1'
/etc/postfix/sql/virtual_blacklist_sender.cf
user = mailadmin
password = mot2passe
hosts = 127.0.0.1
dbname = maildatabase
query = SELECT message FROM blacklist WHERE source = '%s' AND type = 'sender' AND active = '1'
/etc/postfix/sql/virtual_domains_maps.cf
user = mailadmin
password = mot2passe
hosts = 127.0.0.1
dbname = maildatabase
query = SELECT domain FROM domains WHERE domain = '%s' AND active = '1'
/etc/postfix/sql/virtual_mailbox_maps.cf
user = mailadmin
password = mot2passe
hosts = 127.0.0.1
dbname = maildatabase
query = SELECT CONCAT(SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1),'/') FROM users WHERE email = '%s' AND active = '1'
/etc/postfix/sql/virtual_relay.cf
user = mailadmin
password = mot2passe
hosts = 127.0.0.1
dbname = maildatabase
query = SELECT domain FROM relay WHERE domain = '%s' AND active = '1'
/etc/postfix/sql/virtual_senders_maps.cf
user = mailadmin
password = mot2passe
hosts = 127.0.0.1
dbname = maildatabase
query = SELECT origine FROM senders WHERE sender = '%s' AND regsender = '0' AND active = '1'
/etc/postfix/sql/virtual_senders_regexp.cf
user = mailadmin
password = mot2passe
hosts = 127.0.0.1
dbname = maildatabase
query = SELECT origine FROM senders WHERE '%s' REGEXP CONCAT('^',sender,'$') AND regsender = '1' AND active = '1'
/etc/postfix/sql/virtual_transport.cf
user = mailadmin
password = mot2passe
hosts = 127.0.0.1
dbname = maildatabase
query = SELECT transport FROM transport WHERE domain='%s' AND active ='1'
2.2.4 Fichier /etc/aliases
- D’abord éditez le fichier
/etc/aliases
# See man 5 aliases for format
postmaster: root
root: root@mondomaine.net
- Et lancez la commande suivante
newaliases
3. Dovecot
3.1 Installation
Pour dovecot, on peut directement obtenir la dernière version depuis leur serveur (on va donc pas se priver) !
On ajoute cette petite ligne à /etc/apt/sources.list
:
[...]
# Dovecot
deb https://repo.dovecot.org/ce-2.3-latest/debian/stretch stretch main
wget -qO - https://repo.dovecot.org/DOVECOT-REPO-GPG | apt-key add -
apt update
apt upgrade
apt install --yes dovecot-imapd dovecot-mysql dovecot-pop3d dovecot-managesieved dovecot-lmtpd
systemctl enable dovecot
3.2 Création du répertoire et de l’utilisateur dédié
Il est recommandé d’isolé l’utilisateur du mail et son répertoire :
groupadd -g 5000 vmail
useradd -g vmail -u 5000 vmail -d /var/vmail -m
3.3 Configuration
Par défaut, sur Debian, la configuration est subdivisé en fichier localisé dans le répértoire /etc/dovecot/conf.d
. Personnellement je trouve ça, peu pratique et rends difficile la compréhension de notre ficher de configuration. Ici je regroupe tout dans un seul fichier.
Donc on commence par se débarrasser de l’excedent :
rm -rf /etc/dovecot/conf.d
3.3.1 Editez le fichier /etc/dovecot/dovecot.conf
# Liste des protocoles actifs
protocols = imap pop3 lmtp sieve
# SSL
ssl = required
ssl_cert =</etc/letsencrypt/live/xchange.zegroupe.io/fullchain.pem
ssl_key =</etc/letsencrypt/live/xchange.zegroupe.io/privkey.pem
# Utilisateur dédié
mail_uid = 5000
mail_gid = 5000
# Identification
disable_plaintext_auth = yes
auth_mechanisms = plain login
# On active les quotas & le push
mail_plugins = quota
mailbox_list_index = yes
mail_vsize_bg_after_count = 100
service pop3-login {
# On desactive le pop3
inet_listener pop3 {
port = 0
}
# On active le pop3s sur le port et les adresses specifiees
inet_listener pop3s {
port = 995
address = MON.IP.V.4, MON::IP::V6
}
}
service imap-login {
# On ouvre l'imap qu'en local (pour le webmail)
inet_listener imap {
port = 143
address = 127.0.0.1, ::1
}
# On active le imaps sur le port et les adresses specifiees
inet_listener imaps {
port = 993
address = MON.IP.V.4, MON::IP::V6
}
}
service managesieve-login {
inet_listener sieve {
port = 4190
address = MON.IP.V.4, MON::IP::V6
}
service_count = 1
}
# On active un socket pour lmtp (communication avec postfix)
service lmtp {
unix_listener /var/spool/postfix/private/dovecot-lmtp {
group = postfix
mode = 0660
user = postfix
}
}
plugin {
# On specifie comment va etre compte l'usage des utilisateurs
quota = count:User quota
# Quota par defaut (remplacer par la valeur de la base SQL)
quota_rule = *:storage=2G
quota_grace = 50M
quota_status_success = DUNNO
quota_status_nouser = DUNNO
quota_status_overquota = "552 5.2.2 Mailbox is full"
quota_warning = storage=95%% quota-warning 95 %u
quota_vsizes = yes
sieve_plugins = sieve_imapsieve sieve_extprograms
# Quand on deplace VERS le dossier spam (ou que l'on Flag un spam)
imapsieve_mailbox1_name = Junk
imapsieve_mailbox1_causes = COPY
imapsieve_mailbox1_before = file:/etc/dovecot/sieve/report-spam.sieve
# Quand on deplace DEPUIS le dossier spam
imapsieve_mailbox2_name = *
imapsieve_mailbox2_from = Junk
imapsieve_mailbox2_causes = COPY
imapsieve_mailbox2_before = file:/etc/dovecot/sieve/report-ham.sieve
sieve_pipe_bin_dir = /etc/dovecot/sieve
sieve_global_extensions = +vnd.dovecot.pipe +vnd.dovecot.environment
sieve_after = /etc/dovecot/sieve-after
}
service quota-warning {
executable = script /etc/dovecot/quota-warning.sh
user = dovecot
unix_listener quota-warning {
}
}
service quota-status {
executable = quota-status -p postfix
unix_listener /var/spool/postfix/private/quota-status {
group = postfix
mode = 0660
user = postfix
}
client_limit = 1
}
# On utilise une base SQL pour l'authentification
passdb {
driver = sql
args = /etc/dovecot/dovecot-sql.conf
}
userdb {
driver = sql
args = /etc/dovecot/dovecot-sql.conf
}
protocol imap {
mail_plugins = $mail_plugins imap_quota imap_sieve
}
protocol lmtp {
mail_plugins = $mail_plugins sieve
postmaster_address = postmaster@mondomaine.net
}
namespace inbox {
inbox = yes
mailbox Drafts {
auto = subscribe
special_use = \Drafts
}
mailbox Junk {
auto = subscribe
special_use = \Junk
autoexpunge = 90d
}
mailbox Spam {
auto = no
special_use = \Junk
}
mailbox Archive {
auto = subscribe
special_use = \Archive
}
mailbox Trash {
auto = subscribe
special_use = \Trash
autoexpunge = 90d
}
mailbox Sent {
auto = subscribe
special_use = \Sent
}
mailbox "Sent Messages" {
auto = no
special_use = \Sent
}
}
service auth {
unix_listener /var/spool/postfix/private/auth {
mode = 0660
user = postfix
group = postfix
}
unix_listener auth-userdb {
mode = 0660
user = dovecot
group = root
}
}
service auth-worker {
user = vmail
}
3.3.2 Editez le fichier /etc/dovecot/dovecot-sql.conf
driver = mysql
connect = host=/var/run/mysqld/mysqld.sock dbname=maildatabase user=mailadmin password= mot2passe
# Mode d'encodage des mots de passe
default_pass_scheme = BLF-CRYPT
# Pour authdb
password_query = SELECT email as user, password FROM users WHERE email='%u' AND active = '1';
# Pour userdb
user_query = SELECT CONCAT('/var/mail/',SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1)) AS home, CONCAT('maildir:/var/mail/',SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1),'/:LAYOUT=fs') AS mail, CONCAT('*:storage=',quota) AS quota_rule FROM users WHERE email='%u' AND active = '1';
# Pour doveadm -A:
iterate_query = SELECT email AS user FROM users WHERE active = '1';
chmod 640 dovecot-sql.conf
chgrp dovecot dovecot-sql.conf
3.3.3 Editez le fichier /etc/dovecot/quota-warning.sh
#!/bin/sh
PERCENT=$1
USER=$2
cat << EOF | /usr/lib/dovecot/dovecot-lda -d $USER -o "plugin/quota=maildir:User quota:noenforcing"
From: no-reply@mondomaine.com
Subject: Boite mail pleine à $PERCENT%
Votre boite mail est pleine à $PERCENT%, il faut faire le ménage 😉
--
Votre administrateur réseaux
EOF
chmod 755 quota-warning.sh
chgrp dovecot quota-warning.sh
3.3.4 Configuration pour l'antispam (Sieve)
- Commencez par créer les répertoires
/etc/dovecot/sieve
et/etc/dovecot/sieve-after
:
mkdir /etc/dovecot/sieve /etc/dovecot/sieve-after
- Puis créer ces 5 fichiers :
require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment", "variables"];
if environment :matches "imap.mailbox" "*" {
set "mailbox" "${1}";
}
if string "${mailbox}" [ "Trash", "train_ham", "train_prob", "train_spam" ] {
stop;
}
pipe :copy "rspamd-learn-ham.sh";
require ["vnd.dovecot.pipe", "copy", "imapsieve", "environment"];
pipe :copy "rspamd-learn-spam.sh";
#!/bin/sh
exec /usr/bin/rspamc learn_ham
#!/bin/sh
exec /usr/bin/rspamc learn_spam
require ["fileinto","mailbox"];
if header :contains "X-Spam" "Yes" {
fileinto :create "Junk";
stop;
}
- Et exécutez les lignes suivantes :
sievec /etc/dovecot/sieve/report-spam.sieve
sievec /etc/dovecot/sieve/report-ham.sieve
sievec /etc/dovecot/sieve-after/spam2folder.sieve
chmod 600 /etc/dovecot/sieve/* /etc/dovecot/sieve-after/*
chmod u+x /etc/dovecot/sieve/*.sh
chown vmail:vmail /etc/dovecot/sieve/* /etc/dovecot/sieve-after/*
4. Rspamd
Il faut maintenant mettre en place le filtrage antispam avec Rspamd.
4.1 Installation
On modifie de nouveau /etc/apt/sources.list
:
[...]
# Rspamd
deb [arch=amd64] http://rspamd.com/apt-stable/ main
deb-src [arch=amd64] http://rspamd.com/apt-stable/ main
wget -qO - https://rspamd.com/apt-stable/gpg.key | apt-key add -
apt update
apt upgrade
apt install --yes rspamd redis-server
4.2 Configuration
4.2.1 Choix du mot de passe
Afin de pouvoir accéder à l'interface web il faut mettre en place un mot de passe en lecture seule (password) et un autre pour le contrôle total (enable_password).
Tout d'abord on définit ces mots de passe (en lançant 2 fois de suite cette commande) :
rspamadm pw
PU doesn't have SSSE3 instructions set required for hyperscan, disable it
Enter passphrase:
$2$yfmko5i6eowy1yn6aauzsy9bofaxemg8$yhmqhersor8dpchj1i4k5d3e8j8hiicc9sy5ig3thjaxcx5nnkgy
Puis on crée le fichier /etc/rspamd/local.d/worker-controller.inc
:
password = "$2$yfmko5i6eowy1yn6aauzsy9bofaxemg8$yhmqhersor8dpchj1i4k5d3e8j8hiicc9sy5ig3thjaxcx5nnkgy";
enable_password = "$2$nki7u6h7nsizxi5fcrdffqfx48gpigjq$3uqas5ot9dj4pzzwjqo7zg8o6w61m9biqkhjxu5x137rtxy9swbb"
4.2.2 Activation du protocol milter
Afin de discuter avec postfix, il faut mettre en place le proxy de rspamd. Normalement ceci est la configuration par défaut. Si vous souhaitez forcer les choses vous pouvez créer un fichier /etc/rspamd/local.d/worker-proxy.inc
:
milter = yes; # Enable milter mode
timeout = 120s; # Needed for Milter usually
upstream "local" {
default = yes;
hosts = "localhost";
}
count = 1; # Do not spawn too many processes of this type
max_retries = 5; # How many times master is queried in case of failure
discard_on_reject = false; # Discard message instead of rejection
quarantine_on_reject = false; # Tell MTA to quarantine rejected messages
spam_header = "X-Spam"; # Use the specific spam header
reject_message = "Spam message rejected"; # Use custom rejection message
4.2.3 Activation du serveur redis
Créez le fichier /etc/rspamd/local.d/classifier-bayes.conf
:
servers = "localhost";
backend = "redis";
autolearn = true;
4.2.4 Ajustement des paramètres de filtrage
C'est tout à fait personnel, mais personnellement je trouve que le greylisting est une très bonne solution contre le SPAM (on rejette temporairement tous les mails, les spammeurs configurant la plupart du temps leur serveur pour ne faire qu'un seul essai) :
Créez le fichier /etc/rspamd/override.d/metrics.conf
:
servers = "localhost";
backend = "redis";
autolearn = true;
4.2.5 Activation des signatures DKIM
DKIM (DomainKeys Identified Mail) est un système d'authentification créée afin de lutter contre le SPAM. Si vous voulez utiliser votre serveur pour envoyer des mails aux serveurs de gmail / hotmail & co il faudra donc montrer patte blanche.
- On crée d'abord un répertoire
/etc/rspamd/dkim
:
mkdir /etc/rspamd/dkim
- Créez le fichier
/etc/rspamd/local.d/dkim_signing.conf
:
path = "/etc/rspamd/dkim/$domain.$selector.key";
selector_map = "/etc/rspamd/dkim/dkim_selectors.map";
- Créez le fichier
/etc/rspamd/dkim/dkim_selectors.map
(vide pour le moment)
5. Configuration du domaine
5.1 Pré-requis : Création des clés DKIM
- Editez le fichier
/etc/rspamd/dkim/dkim_selectors.map
:
mondomaine.fr 2018102601
autredomaine.net 2018102601
- Puis exécutez cette commande autant de fois que vous avez de domaines en adaptant :
rspamadm dkim_keygen -k /etc/rspamd/dkim/mondomaine.fr.2018102601.key -b 2048 -s 2018102601 -d mondomaine.fr
5.2 Fichier zones du domaine
5.3 Ajout du domaine dans la base de données
5.3.1 Création du mot de passe
doveadm pw -s BLF-CRYPT
6. Serveur CardDAV & CalDAV
S'assurer d'avoir les backport
apt install --yes davical
On edit
/etc/postgresql/9.6/main/pg_hba.conf
# PostgreSQL Client Authentication Configuration File
# ===================================================
# DO NOT DISABLE!
#
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
systemctl restart postgresql
su postgres -c /usr/share/davical/dba/create-database.sh
on edite : /etc/php/7.0/fpm/pool.d/www.conf
on ajoute
php_value[include_path] = /www/php_include/awl/inc
php_value[magic_quotes_gpc] = 0
php_value[register_globals] = 0
php_value[error_reporting] = "E_ALL & ~E_NOTICE"
php_value[default_charset] = "utf-8"
Supported locales updated.
Updated view: dav_principal.sql applied.
CalDAV functions updated.
RRULE functions updated.
Database permissions updated.
NOTE
====
* You will need to edit the PostgreSQL pg_hba.conf to allow the
'davical_dba' database user access to the 'davical' database.
* You will need to edit the PostgreSQL pg_hba.conf to allow the
'davical_app' database user access to the 'davical' database.
* The password for the 'admin' user has been set to 'Df2ab/k0'
Thanks for trying DAViCal! Check the configuration in /etc/davical/config.php.
For help, look at our website and wiki, or visit #davical on irc.oftc.net.
cd /var/www
mkdir /var/composer /var/sabre
cd /var/composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '93b54496392c062774670ac18b134c3b3a95e5a5e5c8f1a9f115f203b75bf9a129d5daa8ba6a13e2cc8a1da0806388a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
./composer.phar require sabre/dav ~3.2.3
cat /var/www/composer/vendor/sabre/dav/examples/sql/mysql.* | mysql -u userdav -p sabredavdb -h 127.0.0.1
php -r "echo md5('lenomdutilisateur:SabreDAV:lemotdepasse');"
edition /var/www/sabrev/server.php
fichier nginx conf
7. Webmail - Roundcube (facultatif)
Vous n'êtes pas obligé de mettre en place un webmail mais ça peut vous tirez d'affaire le jour où vous avez besoin d'envoyer un mail et rien à dispo (oui avec les portables ça devient rare ce genre de situation)...
Roundcube 1.4 est sur le starting block, deplus ce super webmail qui était veillissant vient de subir une cure de rajeunissement avec le skin elastik
Pour l'installer on se rends sur github
apt install php-json php-pear php-auth-sasl php-net-idna2 php-mail-mime php-net-smtp php-net-sieve php-imagick php-intl php-zip node-less
chmod +x bin/install-jsdeps.sh
./bin/install-jsdeps.sh
$ cd skins/elastic
$ lessc -x styles/styles.less > styles/styles.css
$ lessc -x styles/print.less > styles/print.css
$ lessc -x styles/embed.less > styles/embed.css
$config['smtp_server'] = 'tls://mail.mondomaine.com';
// SMTP port (default is 587)
$config['smtp_port'] = 587;
// SMTP username (if required) if you use %u as the username Roundcube
// will use the current username for login
$config['smtp_user'] = '%u';
// SMTP password (if required) if you use %p as the password Roundcube
// will use the current user's password for login
$config['smtp_pass'] = '%p';
// SMTP AUTH type (DIGEST-MD5, CRAM-MD5, LOGIN, PLAIN or empty to use
// best server supported one)
$config['smtp_auth_type'] = 'PLAIN';
// Optional SMTP authentication identifier to be used as authorization proxy
$config['smtp_auth_cid'] = null;
// Optional SMTP authentication password to be used for smtp_auth_cid
$config['smtp_auth_pw'] = null;
https://github.com/blind-coder/rcmcarddav/releases
dans plugin et renommer en carddav
7. Divers
Si serveur blacklisté par microsoft :
https://support.microsoft.com/en-us/getsupport?oaspworkflow=start_1.0.0.0&wfname=capsub&productkey=edfsmsbl3&forceorigin=esmc&ccsid=636695388785313957
https://postmaster.live.com/snds/ipStatus.aspx
Bien choisir son adresse ip : https://mxtoolbox.com/
Checker sa configuration : https://www.mail-tester.com
S'envoyer des spams : http://domino-118a.maysoft.com/selfserve3.nsf/dl?OpenForm
8. Migration IMAP
(tiré de https://jesuisadmin.fr/migrer-emails-facilement-imapsync/)
apt install libauthen-ntlm-perl libclass-load-perl libcrypt-ssleay-perl libdata-uniqid-perl libdigest-hmac-perl libdist-checkconflicts-perl libfile-copy-recursive-perl libio-compress-perl libio-socket-inet6-perl libio-socket-ssl-perl libio-tee-perl libmail-imapclient-perl libmodule-scandeps-perl libnet-ssleay-perl libpar-packer-perl libreadonly-perl libregexp-common-perl libsys-meminfo-perl libterm-readkey-perl libtest-fatal-perl libtest-mock-guard-perl libtest-pod-perl libtest-requires-perl libtest-simple-perl libunicode-string-perl liburi-perl libtest-nowarnings-perl libtest-deep-perl libtest-warn-perl make cpanminus
cpanm Mail::IMAPClient
cpanm JSON::WebToken
wget https://imapsync.lamiral.info/dist/imapsync -O /usr/bin/imapsync
chmod +x /usr/bin/imapsync
installer postfix-pcre
sed -i 's/add_smtp_user = true/add_smtp_user = false/g' /usr/share/rspamd/lualib/lua_auth_results.lua
imapsync --host1 IP.SERVEUR.1 --user1 COMPTE@SERVEUR.1 --password1 MDPSERVEUR1 --host2 IP.SERVEUR.2 --user2 COMPTE@SERVEUR.2 --password2 MDPSERVEUR2 --f1f2 "Sent Messages=Sent"
apt install clamav-daemon clamav-unofficial-sigs
systemctl stop clamav-freshclam
freshclam
systemctl start clamav-freshclam
https://www.securiteinfo.com/
on ajoute toutes les lignes dans le fichier /etc/clamav/freshclam.conf (cf site securiteinfo.com)
et voilà le travail.
/etc/rspamd/override.d/antivirus.conf
clamav {
attachments_only = false;
symbol = "CLAM_VIRUS";
type = "clamav";
action = "reject";
servers = "/var/run/clamav/clamd.ctl";
}
openssl dhparam 4096 > dh.pem
sudo killall -HUP mDNSResponder & rndc flush
Exemple de configuration de la base.