Dovecot est un serveur IMAP et POP3 open-source pour Linux et autres systèmes dérivés d'Unix qui gère les formats de messagerie mbox et Maildir. L'objectif principal de Dovecot est de satisfaire un haut niveau de sécurité. De ce fait, il supporte de nombreux schémas d'authentifications.
On commence par installer le paquet :
sudo yum -y install dovecot
Ensuite on s'occupe du lancement du service :
sudo systemctl enable dovecot.service sudo systemctl start dovecot.service
On ajoute un mot de passe à nos utilisateurs de test :
sudo passwd user1 sudo passwd user2
On configure le pare-feu :
sudo firewall-cmd --permanent --zone=public --add-service=pop3 sudo firewall-cmd --permanent --zone=public --add-service=imap sudo firewall-cmd --reload
Installation d'un certifical Let's Encrypt
On commence par cloner le repo de Let's Encrypt :
sudo cd /root sudo git clone https://github.com/letsencrypt/letsencrypt sudo cd letsencrypt
En préparation du processus de génération d'un certificat par l'utilitaire de Let's Encrypt, nous allons arrêter notre pare-feu.
sudo systemctl stop firewalld.service
Puis on génère le certificat (attention de bien remplacer les valeurs avant de soumettre) :
sudo ./letsencrypt-auto certonly --rsa-key-size 4096 -d <mail.domain.com> --email <Cette adresse e-mail est protégée contre les robots spammeurs. Vous devez activer le JavaScript pour la visualiser. > --agree-tos
Le script Let's Encrypt va installer les paquets nécessaire, le cas échéant. Il va ensuite vous demander quelle méthode utiliser pour la vérification du nom de domaine.
How would you like to authenticate with the ACME CA? ------------------------------------------------------------------------------- 1: Spin up a temporary webserver (standalone) 2: Place files in webroot directory (webroot) ------------------------------------------------------------------------------- Select the appropriate number [1-2] then [enter] (press 'c' to cancel):
Si vous n'avez pas configuré de serveur web, sélectionnez la réponse 1.
Si tout se déroule correctement, vous devriez obtenir la sortie suivante :
Plugins selected: Authenticator standalone, Installer None Obtaining a new certificate Performing the following challenges: tls-sni-01 challenge for mail.comain.com Waiting for verification... Cleaning up challenges IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/mail.domain.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/mail.domain.com/privkey.pem Your cert will expire on 2018-01-06. To obtain a new or tweaked version of this certificate in the future, simply run letsencrypt-auto again. To non-interactively renew *all* of your certificates, run "letsencrypt-auto renew" - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le
Une fois le certificat généré, nous allons pouvoir relancer le pare-feu :
sudo systemctl start firewalld.service
On crée un fichier dans /etc/cron.weekly afin de renouveller automatiquement le certificat :
#!/bin/sh /bin/date >> /var/log/letsencrypt.log /root/letsencrypt/letsencrypt-auto renew >> /var/log/letsencrypt.log
On oublie pas de rendre le fichier exécutable :
sudo chmod a+x /etc/cron.weekly/LetsEncryptRenew
Installation du certificat dans Postfix
Nous allons ajouter les lignes suivantes à la configuration de postfix afin de sécuriser les connexions /etc/postfix/main.cf :
smtp_use_tls = yes smtpd_use_tls = yes smtpd_tls_security_level = encrypt smtpd_tls_auth_only = yes smtp_tls_note_starttls_offer = yes smtp_tls_CAfile = /etc/letsencrypt/live/mail.domain.com/chain.pem smtpd_tls_cert_file = /etc/letsencrypt/live/mail.domain.com/cert.pem smtpd_tls_key_file = /etc/letsencrypt/live/mail.domain.com/privkey.pem smtpd_tls_loglevel = 1 smtpd_tls_session_cache_timeout = 3600s smtpd_tls_session_cache_database = btree:/var/lib/postfix/smtpd_tls_cache tls_random_source = dev:/dev/urandom smtpd_tls_mandatory_protocols = !SSLv2, !SSLv3 smtpd_tls_protocols = !SSLv2, !SSLv3 smtp_tls_mandatory_protocols = !SSLv2, !SSLv3 smtp_tls_protocols = !SSLv2, !SSLv3 smtp_tls_exclude_ciphers = EXP, MEDIUM, LOW, DES, 3DES, SSLv2 smtpd_tls_exclude_ciphers = EXP, MEDIUM, LOW, DES, 3DES, SSLv2 tls_high_cipherlist = kEECDH:+kEECDH+SHA:kEDH:+kEDH+SHA:+kEDH+CAMELLIA:kECDH:+kECDH+SHA:kRSA:+kRSA+SHA:+kRSA+CAMELLIA:!aNULL:!eNULL:!SSLv2:!RC4:!MD5:!DES:!EXP:!SEED:!IDEA:!3DES tls_medium_cipherlist = kEECDH:+kEECDH+SHA:kEDH:+kEDH+SHA:+kEDH+CAMELLIA:kECDH:+kECDH+SHA:kRSA:+kRSA+SHA:+kRSA+CAMELLIA:!aNULL:!eNULL:!SSLv2:!MD5:!DES:!EXP:!SEED:!IDEA:!3DES smtp_tls_ciphers = high smtpd_tls_ciphers = high
Installation du certificat dans Dovecot
/etc/dovecot/conf.d/10-ssl.conf
ssl = required disable_plaintext_auth = yes ssl_cert = </etc/letsencrypt/live/mail.domain.com/fullchain.pem ssl_key = </etc/letsencrypt/live/mail.domain.com/privkey.pem
On relance
Pour finir, on relance postfix et dovecot :
sudo systemctl restart postfix.service sudo systemctl restart dovecot.service
Implémentation de SASL
Nous allons commencer par modifier le fichier /etc/dovecot/conf.d/10-master.conf. Il faut rechercher la section smtp-auth et la modifier comme suit :
# unix_listener auth-userdb { #mode = 0666 #user = #group = #} # Postfix smtp-auth unix_listener /var/spool/postfix/private/auth { mode = 0660 user = postfix group = postfix }
On modifie ensuite le fichier /etc/devecot/conf.d/10-auth.conf. Nous recherchons auth_mechanisms :
# Space separated list of wanted authentication mechanisms: # plain login digest-md5 cram-md5 ntlm rpa apop anonymous gssapi otp skey # gss-spnego # NOTE: See also disable_plaintext_auth setting. auth_mechanisms = plain login
Nous allons maintenant configurer postfix afin qu'il utilise le système d'authentification mis en place grace à devecot. Editons le fichier /etc/postfix/main.cf :
smtpd_sasl_type = dovecot smtpd_sasl_path = private/auth smtpd_sasl_auth_enable = yes
Nous relançons les deux services :
sudo systemctl restart dovecot.service sudo systemctl restart postfix.service
Il faut également modifier le fichier /etc/postfix/master.cf afin d'autoriser l'authentification depuis l'extérieur.
# ========================================================================== # service type private unpriv chroot wakeup maxproc command + args # (yes) (yes) (yes) (never) (100) # ========================================================================== smtp inet n - n - - smtpd #smtp inet n - n - 1 postscreen #smtpd pass - - n - - smtpd #dnsblog unix - - n - 0 dnsblog #tlsproxy unix - - n - 0 tlsproxy submission inet n - n - - smtpd -o syslog_name=postfix/submission -o smtpd_tls_security_level=encrypt -o smtpd_sasl_auth_enable=yes -o smtpd_reject_unlisted_recipient=no # -o smtpd_client_restrictions=$mua_client_restrictions # -o smtpd_helo_restrictions=$mua_helo_restrictions # -o smtpd_sender_restrictions=$mua_sender_restrictions -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject -o milter_macro_daemon_name=ORIGINATING