Installazione di Dovecot e sieve su qmail + vpopmail

15 febbraio 2025 by Roberto Puzzanghera 7 commenti

Changelog

  • Feb 15, 2025
    - added support for vpopmail configured with --disable-many-domains
    - 90-sieve.conf: global script move-spam.sieve called correctly
  • Feb 8, 2025
    - dovecot_postlogin.sh: query changed in order to add new records as well (tx Bai Borko)
    - bug fix: pop3 service was executing imap instead of pop3 (tx Gabriel Torres)
  • Jan 29, 2025
    - dovecot upgraded to v 2.4.0. Old configuration files are not valid anymore and you have to install dovecot from scratch.
  • Nov 15, 2024
    - added a postlogin script to update the vpopmail.lastauth SQL table on login (see 10-master.conf, thanks kengheng)
  • Dec 29, 2023
    default_pass_scheme = SHA512-CRYPT (was MD5-CRYPT) in dovecot-sql.conf.ext, as vpopmail-5.6.x has now SHA512-CRYPT password by default
  • Feb 10, 2023
    - added a patch to restore the old vpopmail-auth driver (tx Ali Erturk TURKER)

Info

Dovecot è un mail server IMAP e POP3 open-source per sistemi Linux/UNIX, scritto con la sicurezza in mente come prima cosa. Dovecot è una scelta eccellente sia per piccole che per grandi installazioni. E' veloce, semplice da installare, non richiede particolari operazioni di amministrazione e usa molta poca memoria.

Dovecot è semplice da configurare, il progetto è vivo e la documentazione è ricca e ben organizzata.

Ho trovato Dovecot così amichevole che ho deciso di lasciare qmail-pop3d e usare Dovecot non solo come IMAP ma anche come un server POP3. Mostrerò anche come configurare una connessione sicura.

Installazione

DOVECOT_VER=2.4.0

cd /usr/local/src
wget https://www.dovecot.org/releases/2.4/dovecot-${DOVECOT_VER}.tar.gz
tar xzf dovecot-${DOVECOT_VER}.tar.gz
chown -R root:root dovecot-${DOVECOT_VER}
cd dovecot-${DOVECOT_VER}

./configure \ 
   --prefix=/usr/local/dovecot \ 
   --with-sql \ 
   --with-mysql \ 
   --with-ldap \ 
   --without-pam \ 
   --without-pgsql \ 
   --without-sqlite \ 
   --with-solr \ 
   --with-bzlib \ 
   --with-lz4

Install prefix . : /usr/local/dovecot 
File offsets ... : 64bit 
I/O polling .... : epoll 
I/O notifys .... : inotify 
SSL ............ : openssl 
GSSAPI ......... : no 
passdbs ........ : static passwd passwd-file ldap sql 
                : -pam -bsdauth 
userdbs ........ : static prefetch passwd passwd-file ldap sql 
CFLAGS ......... : -std=gnu11 -g -O2 -fstack-protector-strong -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -mfunction-return=keep -mindirect-b
ranch=keep -Wall -W -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wchar-subscripts -Wformat=2 -Wbad-function-cast -fno-b
uiltin-strftime -Wstrict-aliasing=2  
SYSTEMD ........ : simple - (no unit file) 
SQL drivers .... : mysql 
                : -pgsql -sqlite -cassandra 
Full text search : solr flatcurve

In caso di compilazione su ambienti systemd potrebbe essere necessario aggiungere l'opzione --with-systemd systemdsystemunitdir al configure (grazie a Bob Greco), per esempio:

--with-systemd
systemdsystemunitdir=/lib/systemd/system

E' bene controllare se SSL è stato rivelato e se il backend per l'autenticazione sql/mysql è supportato. Ora è possibile compilare:

make

Se la vecchia versione è ancora in esecuzione è necessario stopparla prima di installare e quindi sovrascrivere.

dovecotctl stop
rm /usr/local/dovecot
make install

cd /usr/local
mv dovecot dovecot-${DOVECOT_VER}
ln -s dovecot-${DOVECOT_VER} dovecot
Ciò installa dovecot in /usr/local/dovecot.

Configurazione

Creiamo un utente e un gruppo dovecot e le cartella log e dovecot/run.

groupadd dovecot
useradd -g dovecot dovecot
useradd -g dovecot dovenull

mkdir -p /usr/local/dovecot/var/run/dovecot
# vpopmail user must have access here
chmod -R o+rx /usr/local/dovecot/var/run/dovecot

mkdir -p /var/log/dovecot 
touch /var/log/dovecot/dovecot.log
chgrp vchkpw /var/log/dovecot/dovecot.log
chmod 660 /var/log/dovecot/dovecot.log

mkdir -p /usr/local/dovecot/var/run/dovecot
chown dovenull:dovecot /usr/local/dovecot/var/run/dovecot

A partire dalla versione 2.4.0 non sono più disponibili gli esempi di file di configurazione, ma almeno sono stati pubblicati nella mailing list di dovecot. Li ho salvati nel mio spazion github ed è possibile salvarli come segue:

git clone -b example-config-2.4.0 https://github.com/sagredo-dev/dovecot-conf.git

Assicurarsi che le variabili PATH e MANPATH contengano i riferimenti a dovecot in /etc/profile.d/qmail.sh

export PATH=$PATH:/usr/local/dovecot/bin
export MANPATH=$MANPATH:/usr/local/dovecot/share/manexport PATH=$PATH:/usr/local/dovecot/bin

Scarica i file di configurazione

  • Scarica da qui

Suggerisco fortemente di usare i miei file di configurazione, che sono pronti all'uso, e di personalizzare il solo file local.conf.

DOVECOT_CONFIG_VER=2025.02.15

cd /usr/local/dovecot
mv etc etc-bak
wget https://github.com/sagredo-dev/dovecot-conf/archive/refs/tags/v${DOVECOT_CONFIG_VER}.tar.gz
tar xzf v${DOVECOT_CONFIG_VER}.tar.gz
ln -s dovecot-conf-${DOVECOT_CONFIG_VER} etc
cd etc/dovecot
chown -R root:root .

Rinominare il file local.conf.template e modificarlo secondo le proprie necessità:

mv local.conf.template local.conf

dovecot.conf

# Default values are shown for each setting, it's not required to uncomment 
# those. These are exceptions to this though: No sections (e.g. namespace {}) 
# or plugin settings are added by default, they're listed only as examples. 
# Paths are also just examples with the real defaults being based on configure 
# options. The paths listed here are for configure --prefix=/usr/local 
# --sysconfdir=/usr/local/etc --localstatedir=/var 
dovecot_config_version = 2.4.0 
dovecot_storage_version = 2.4.0

# Protocols we want to be serving. 
protocols { 
 imap = yes 
 pop3 = yes 
} 

# A comma separated list of IPs or hosts where to listen in for connections. 
# "*" listens in all IPv4 interfaces, "::" listens in all IPv6 interfaces. 
# If you want to specify non-default ports or anything more complex, 
# edit conf.d/master.conf. 
listen { 
* = yes 
:: = no 
}

# Most of the actual configuration gets included below. The filenames are 
# first sorted by their ASCII value and parsed in that order. The 00-prefixes 
# in filenames are intended to make it easier to understand the ordering.
!include conf.d/*.conf 

# A config file can also tried to be included without giving an error if 
# it's not found: 
!include_try local.conf

Notare che tutti i file conf.d/*.conf saranno inclusi, quindi è necessario rinominare ciò che non si vuole caricare.

10-auth.conf

# if the roundcube connection is from the local net this is secure provided that the 143 port is firewalled for the outnet
# put yes if you have rounducube on localhost
disable_plaintext_auth = no
# To append @domain to username in plaintext logins
auth_default_realm = defaultdomain.net
auth_mechanisms = plain login # the sql drivers requires that the pwd is transmitted with no encryption

# !include auth-system.conf.ext # now commented
# !include auth-vpopmail.conf.ext # commented
!include auth-sql.conf.ext

A partire dalla versione 2.3.13 il driver vpopmail-auth è stato rimosso da Dovecot. Colro che volessero rimanere con il vecchio driver per vpopmail possono fare riferimento alla patch mantenuta da Ali Erturk TURKER, che riporta in vita in driver originario per vpopmail. Questi driver non sono ancora disponibili per la versione 2.4.0.

Quanto segue invece riguarda la configurazione del driver sql. Il motivo per cui sql secondo me è migliore è che vpopmail manca della possibilità di fare iterazioni con dovadm, cosa necessaria per l'expunge dello spam e dei vecchi messaggi del cestino.

Il driver sql (almeno per come l'ho settato io) richiede la trasmissione plain delle password. Questo non è un problema se chiudiamo le porte 110 e 143 non sicure. Piuttosto ricordarsi di settare dovecot per non passare la password in MD5.

auth-sql.conf.ext

NB: la password_query richiede ora che si sia creata la tabella aliasdomains su mysql come spiegato qui.

# https://doc.dovecot.org/latest/core/config/auth/databases/sql.html#mysql 
sql_driver = mysql 
# Default password scheme. 
# List of supported schemes is in 
# https://doc.dovecot.org/latest/core/config/auth/schemes.html 
# This is important if you have old MD5-CRYPT passwords accepted
auth_allow_weak_schemes = yes 
passdb_default_password_scheme = SHA512-CRYPT 

# The mysqld.sock socket may be in different locations in different systems. 
#mysql /var/run/mysqld/mysqld.sock { 
# overwritten by local.conf 
#mysql localhost { 
#  user = vpopmail 
#  password = xxxxxxxxxxxxxxxxxxx 
#  dbname = vpopmail 
#}

# grab the sql queries for the specific situation 

# auth-sql --enable-many-domains --enable--sql-aliasdomain --enable-mysql-limits 
!include sql-query-default.conf.ext 

# auth-sql --disable-many-domains --enable--sql-aliasdomain --enable-mysql-limits 
#!include sql-query--disable-many-domains.conf.ext

La query sql cambia a seconda che si sia configurato vpopmail con --disable-many-domains (default suggerito in questa guida) o meno.

sql-query-default.conf.ext

Questo è il file di default per l'opzione --disable-many-domains.

passdb sql { 
 # passdb query to retrieve the password. It can return fields: 
 #   password - The user's password. This field must be returned. 
 #   user - user@domain from the database. Needed with case-insensitive lookups. 
 #   username and domain - An alternative way to represent the "user" field. 
 # 
 # The "user" field is often necessary with case-insensitive lookups to avoid 
 # e.g. "name" and "nAme" logins creating two different mail directories. If 
 # your user and domain names are in separate fields, you can return "username" 
 # and "domain" fields instead of "user". 

 # (Thanks to Arturo Blanco for his hints concerning vpopmail limits 
 #  and to Alexandre Fonceca for the quota_rule addition) 

 # NB: This query requires the sql-aliasdomains feature 
 #     and that you have added the aliasdomains db table 
 #     More info here More info here https://notes.sagredo.eu/en/qmail-notes-185/dovecot-vpopmail-auth-driver-removal-migrating-to-the-sql-driver-241.html 

 query = \ 
       SELECT \ 
               CONCAT(vpopmail.pw_name, '@', vpopmail.pw_domain) AS user, \ 
               vpopmail.pw_passwd AS password, \ 
               vpopmail.pw_dir AS userdb_home, \ 
               89 AS userdb_uid, \ 
               89 AS userdb_gid, \ 
               CONCAT('*:bytes=', REPLACE(SUBSTRING_INDEX(vpopmail.pw_shell, 'S', 1), 'NOQUOTA', '0')) AS userdb_quota_rule \ 
       FROM vpopmail \ 
               LEFT JOIN aliasdomains ON aliasdomains.alias='%{user | domain}' \ 
               LEFT JOIN limits ON limits.domain='%{user | domain}' \ 
       WHERE \ 
               vpopmail.pw_name='%{user | username}' \ 
               AND \ 
               (vpopmail.pw_domain='%{user | domain}' OR vpopmail.pw_domain=aliasdomains.domain) \ 
               AND \ 
               ('%{local_port}'!='995' OR !(vpopmail.pw_gid & 2)) \ 
               AND \ 
               ('%{remote_ip}'!='127.0.0.1' OR !(vpopmail.pw_gid & 4)) \ 
               AND \ 
               ('%{remote_ip}'='127.0.0.1' OR '%{local_port}'!='993' OR !(vpopmail.pw_gid & 8)) \ 
               AND \ 
               ('%{remote_ip}'!='127.0.0.1' OR COALESCE(disable_webmail,0)!=1) \ 
               AND \ 
               ('%{remote_ip}'='127.0.0.1' OR COALESCE(disable_imap,0)!=1) 

 # 127.0.0.1 is the IP of your webmail  
 # I'm assuming that the imap connection is only on port 993 and the pop3 connection is on port 995.  
 # Adjust to your needs  

 # logically this means:  
 #  
 # ************************** USER LIMITS via vpopmail.pw_gid filed  
 # SELECT user  
 # WHEN POP is not disabled for that user connecting on port 995 (995 is the pop3s port allowed from remote in my configuration)  
 # AND WHEN webmail access is not disabled for that user when connecting from 127.0.0.1  
 # AND WHEN IMAP is not disabled for that user connecting on port 993 (993 is the imap port allowed from remote  
 # in my configuration) unless his remote ip the one belonging to the webmail  
 #  
 # ************************* DOMAIN LIMITS via limits table  
 # AND WHEN WEBMAIL access for the domain is not disabled  
 # AND WHEN IMAP access for the domain is not disabled when not connecting from 127.0.0.1 
} 

# "prefetch" user database means that the passdb already provided the 
# needed information and there's no need to do a separate userdb lookup. 
# https://doc.dovecot.org/configuration_manual/authentication/prefetch_userdb/ 
userdb prefetch { 
 driver = prefetch 
} 

# This is needed for LDA and for the iteration feature. They both need a userdb sql query. 
# The order of the declared drivers is important. Leave this at the end, otherwise 
# it will be used also for the login instead of the prefetch, which is faster. 
userdb sql { 
 userdb_sql_query = \ 
   SELECT \ 
       vpopmail.pw_dir AS home, \ 
       89 AS uid, \ 
       89 AS gid \ 
   FROM vpopmail \ 
   WHERE \ 
       vpopmail.pw_name='%{user | username}' \ 
       AND \ 
       vpopmail.pw_domain='%{user | domain}' 

 # Query to get a list of all usernames. 
 userdb_sql_iterate_query = SELECT CONCAT(pw_name,'@',pw_domain) AS user FROM vpopmail 
}

 

"One table per domain" query

La soluzione precedente deve essere migliorata quando si salvano gli account in una tabella separata per ogni dominio (--disable-many-domains), perchè è necessario recuparare il dominio reale in caso di alias, calcolare la tabella del database di conseguenza e quindi eseguire la password_query e la user_query. Per eseguire questo compito è necessario far uso delle "stored procedures" del linguaggio sql (ringrazio Pablo Murillo per avermi passato un suo esempio iniziale che mi ha messo sulla buona strada).

Ho dunque creato una procedura chiamata "dovecot_password_query_disable_many_domains" che si occupa di eseguire in backgriound tutto ciò che è il lavoro sporco in linguaggio sql restituendo in uscita le nostre query con il dominio reale cercato e la tabella utenti corretta.

Nel file auth-sql.conf.ext è necessario includere sql-query--disable-many-domains.conf.ext in auth-sql.conf.ext:

# auth-sql --enable-many-domains --enable--sql-aliasdomain --enable-mysql-limits 
#!include sql-query-default.conf.ext 

# auth-sql --disable-many-domains --enable--sql-aliasdomain --enable-mysql-limits 
!include sql-query--disable-many-domains.conf.ext

Nel file sql-query--disable-many-domains.conf.ext vengono chiamate le procedure menzionate sopra:

passdb sql {
 # passdb query to retrieve the password

 # Thanks to Pablo Murillo for sharing his sql example
 query = CALL dovecot_password_query_disable_many_domains('%{user | username}','%{user | domain}','127.0.0.1','%{remote_ip}','%{local_port}')
} 

userdb prefetch { 
 driver = prefetch 
} 

# This is needed for LDA and for the iteration feature. They both need a userdb sql query. 
# The order of the declared drivers is important. Leave this at the end, otherwise 
# it will be used also for the login instead of the prefetch, which is faster. 
userdb sql { 
 userdb_sql_query = CALL dovecot_user_query_disable_many_domains('%{user | username}','%{user | domain}')
}

Per installare le procedure è necessario scaricarle ed eseguire il codice qui sotto come segue:

wget https://notes.sagredo.eu/files/qmail/patches/vpopmail/disable-many-domains_procedures.txt
mysql < dovecot-pwd-query_disable-many-domains.txt -u root -p

10-logging.conf

Impostare il file log. Personalmente preferisco avere un logfile dedicato per dovecot (per default è syslog)

log_path = /var/log/dovecot/dovecot.log
# Log file to use for debug messages. Defaults to info_log_path. 
debug_log_path = /var/log/dovecot/dovecot.log

Per abilitare il debug è sufficiente rimuovere il commento alla seguente riga nel proprio file local.conf:

log_debug = (category=imap AND category=mail AND category=auth AND category=ssl)

Logrotate

Salvare lo script qui sotto come /etc/logrotate.d/dovecot:

cat > /etc/logrotate.d/dovecot << __EOF__
/var/log/dovecot/*.log {
missingok
notifempty
delaycompress
sharedscripts
postrotate
/usr/local/dovecot/bin/doveadm log reopen
endscript
}
__EOF__

10-mail.conf

Dobbiamo dire a Dovecot qual è la locazione delle mailbox. Dovecot cercherà la cartella Maildir nella home directory (%h):

# Mailbox format 
mail_driver = maildir 
# Path to a directory where the mail is stored. 
# Mail User Variables are commonly used here. 
# Specific to mail_driver setting 
mail_path = ~/Maildir 

# this is to allow special characters like '.' in mailboxes like in Junk.TeachSpam 
# https://doc.dovecot.org/latest/core/config/mailbox/mail_location.html#mailbox_list_validate_fs_names 
mailbox_list_validate_fs_names = no

namespace inbox {
 # There can be only one INBOX, and this setting defines which namespace 
 # has it. 
 inbox = yes
}

Impostare a 89 (userid dell'utente vpopmail) mail_uid e mail_gid. Lo stesso per quanto riguarda first/last id dal momento che vogliamo gestire solo utenti vpopmail:

mail_uid = 89
mail_gid = 89

mail_privileged_group = 89
mail_access_groups = 89

first_valid_uid = 89
last_valid_uid = 89

first_valid_gid = 89
last_valid_gid = 89

Impostare il socket:

auth_socket_path = /usr/local/dovecot/var/run/dovecot/auth-userdb
mail_plugin_dir = /usr/local/dovecot/lib/dovecot
mail_plugins = $mail_plugins quota

Impostare i plugin di default

# Space separated list of plugins to load for all services. Plugins specific to 
# IMAP, LDA, etc. are added to this list in their own .conf files. 
mail_plugins { 
 fts = yes 
 fts_solr = yes 
 notify = yes 
 quota = yes 
}

Infine è necessario abilitare questa opzione a causa dei problemi dovuti al bug (ora riparato) nella patch maildir++ per qmail patch (grazie a MG)

##
## Maildir-specific settings
##

# If enabled, Dovecot doesn't use the S=<size> in the Maildir filenames for
# getting the mail's physical size, except when recalculating Maildir++ quota.
# This can be useful in systems where a lot of the Maildir filenames have a
# broken size. The performance hit for enabling this is very small.
maildir_broken_filename_sizes = yes

Altre opzioni (maggiori info qui):

# Mailbox list indexes can be used to optimize IMAP STATUS commands. They are 
# also required for IMAP NOTIFY extension to be enabled. 
mailbox_list_index = yes

# The fields specified here are always added to cache when saving mails, 
# even if the client never accesses these fields. 
mail_always_cache_fields = date.save

File 10-master.conf

Prima di continuare legge questo con cura.

# Login user is internally used by login processes. This is the most untrusted
# user in Dovecot system. It shouldn't have access to anything at all.
# default_login_user = vpopmail # not working here

# Internal user is used by unprivileged processes. It should be separate from
# login user, so that login processes can't disturb other processes.
default_internal_user = dovecot

service imap-login {
  inet_listener imap {
    #port = 143
  }
  inet_listener imaps {
    #port = 993
    #ssl = yes
  }
}

service pop3-login {
  inet_listener pop3 {
    #port = 110
  }
  inet_listener pop3s {
    #port = 995
    #ssl = yes
  }
}

service imap {
  # executable = imap postlogin
}

service pop3 {
  # executable = pop3 postlogin
}

# Updates the vpopmail.lastauth table on login. Uncomment the executable on imap and pop3 
service postlogin {
 # path is relative to /usr/local/dovecot/libexec/dovecot/ 
 executable = script-login ../../etc/scripts/dovecot_postlogin.sh
 user = vpopmail
 unix_listener postlogin { 
   user = vpopmail
   group = vchkpw 
   mode = 0660 
 } 
}

service auth {
 # auth_socket_path points to this userdb socket by default. It's typically 
 # used by dovecot-lda, doveadm, possibly imap process, etc. Users that have 
 # full permissions to this socket are able to get a list of all usernames and 
 # get the results of everyone's userdb lookups. 
 # 
 # The default 0666 mode allows anyone to connect to the socket, but the 
 # userdb lookups will succeed only if the userdb returns an "uid" field that 
 # matches the caller process's UID. Also if caller's uid or gid matches the 
 # socket's uid or gid the lookup succeeds. Anything else causes a failure. 
 # 
 # To give the caller full permissions to lookup all users, set the mode to 
 # something else than 0666 and Dovecot lets the kernel enforce the 
 # permissions (e.g. 0777 allows everyone full permissions). 
 unix_listener auth-userdb { 
   mode = 0660 
   user = vpopmail
   group = vchkpw
 }

  # Auth process is run as this user.
  user = $SET:default_internal_user
}

service auth-worker {
 # Auth worker process is run as root by default, so that it can access 
 # /etc/shadow. If this isn't necessary, the user should be changed to 
 # $SET:default_internal_user. 
 user = $SET:default_internal_user
}

E' possibile lanciare l'esecuzione di uno script postlogin /usr/local/dovecot/etc/scripts/dovecot_postlogin.sh per aggiornare la tabella SQL vpopmail.lastauth dopo il login. In questo caso è necessario decommentare la riga "executable" nei servizi imap e pop3 e fornire il flag x allo script:

chmod +x /usr/local/dovecot/etc/scripts/dovecot_postlogin.sh

10-metrics.conf

service stats { 
   unix_listener stats-reader { 
   user = vpopmail 
   group = vchkpw 
   mode = 0660 
 } 
 unix_listener stats-writer { 
   user = vpopmail 
   group = vchkpw 
   mode = 0660 
 } 
}

10-ssl.conf

Naturalmente vogliamo abilitare il supporto SSL. Prima di tutto creiamo un certificato SSL auto-firmato. Dovecot include uno script per generare il certificato SSL usando  OpenSSL. Nella directory sorgente questo file esiste in  doc/mkcert.sh:

cd /usr/local/src/dovecot/doc

mkcert.sh creerà il certificato SSL. Prima di lanciare mkcert.sh bisogna personalizzare il certificato modificando il file dovecot-openssl.cnf (nella stessa cartella):

> nano dovecot-openssl.cnf

[ req ]
default_bits = 4096
encrypt_key = yes
distinguished_name = req_dn
x509_extensions = cert_type
prompt = no

[ req_dn ]
# country (2 letter code)
C=IT

# State or Province Name (full name)
ST=Italy

# Locality Name (eg. city)
L=MyLocality

# Organization (eg. company)
O=My Organization Name

# Organizational Unit Name (eg. section)
OU=IMAP server

# Common Name (*.example.com is also possible)
CN=mymailserver.net

# E-mail contact
emailAddress=postmaster@mymailserver.net

[ cert_type ]
nsCertType = server

Ora siamo pronti a creare il certificato SSL:

# sh mkcert.sh

e i file  /etc/ssl/private/dovecot.pem e /etc/ssl/certs/dovecot.pem sono stati creati. Si ricordino le loro locazioni perchè poi bisogna inserirle in 10-ssl.conf:

ssl_cert = </etc/ssl/certs/dovecot.pem
ssl_key = </etc/ssl/private/dovecot.pem

Ricordare di disabilitare SSLv3 perchè ormai obsoleto:

ssl_min_protocol = TLSv1

Installare un certificato SSL valido

Una volta che il server è stato testato, prima di andare in produzione, sarà il caso di rimpiazzare il certificato provvisorio creato con uno valido fornito da Let's Encrypt. Per maggiori dettagli si veda la pagina apposita.

Una volta ottenuto il certificato sarà sufficiente modificare come segue le seguenti du linee del file 10-ssl.conf o meglio io proprio file local.conf:

ssl_server_cert_file = /etc/dehydrated/certs/mx.mydomain.tld/fullchain.pem
ssl_server_cert_file  = /etc/dehydrated/certs/mx.mydomain.tld/privkey.pem

Notare come dalla versione 2.4 non c'è più il prefisso "<" nel nome del certificato.

15-lda.conf

Come già detto dovecot agirà anche come una LDA dato che vogliamo gestire le sieve rules e i filtri delle email in arrivo.

# These two can be overwritten in your local.conf
postmaster_address = postmaster@yourdomain.net
hostname = mail.yourdomain.net

protocol lda { 
 # Boolean list of plugins to load 
 mail_plugins { 
   # to be overwrited in local.conf
   # sieve = yes 
 } 
}

15-mailboxes.conf

La variabile autoexpunge assicura la cancellazione dei vecchi messaggi dalle cartelle Trash e Junk dopo un certo numero di giorni.

##
## Mailbox definitions
##

# NOTE: Assumes "namespace inbox" has been defined in 10-mail.conf.
namespace inbox {
  # These mailboxes are widely used and could perhaps be created automatically: 
 mailbox Drafts { 
   special_use = \Drafts 
   auto = subscribe 
 } 
 mailbox Junk { 
   special_use = \Junk 
   autoexpunge = 30d 
 } 
 mailbox Junk.TeachSpam { 
   auto = subscribe 
   autoexpunge = 30d 
 } 
 mailbox Junk.TeachNotSpam { 
   auto = subscribe 
   autoexpunge = 30d 
 } 
 mailbox Trash { 
   special_use = \Trash 
   autoexpunge = 60d 
 }

 # For \Sent mailboxes there are two widely used names. We'll mark both of 
 # them as \Sent. User typically deletes one of them if duplicates are created. 
 mailbox Sent { 
   special_use = \Sent 
 } 
 mailbox "Sent Messages" { 
   special_use = \Sent 
 }
}

20-imap.conf

protocol imap {
 # Space separated list of plugins to load (default is global mail_plugins). 
 mail_plugins { 
    notify = yes 
    mail_log = yes 
    imap_sieve = yes 
    imap_quota = yes 
 }
}

20-pop3.conf

protocol pop3 {
 # Space separated list of plugins to load (default is global mail_plugins). 
 mail_plugins { 
   notify = yes 
   mail_log = yes 
 }
}

90-quota.conf

Abilitare la funzionalità maildir++

quota "User quota" { 
 driver = maildir 
 enforce = no 
}

Commenti

Certificato SSL e virtual domain

Ciao Roberto grazie della tua ottima guida. Come faccio a gestire il certificato di dovecot su un server che ha molti domini di posta? Anche usando un certificato acquistato e non auto generato i client di posta indicano come non valido.

Grazie

Rispondi |

Certificato SSL e virtual domain

con letsencrypt non dovrebbero esserci problemi. Stavo studiando la cosa anche io questi giorni, ma purtroppo causa un bug di security letsencrypt in questi gg non sta rilasciando nuovi certificati.. a breve (quando rilasciano la nuova versione) dovrei scrivere qui qualcosa al riguardo... se tu riesci prima per favore manda un appunto su eventuali problemi

Rispondi |

Certificato SSL e virtual domain

Grazie della cortese risposta,
Ti confermo che con letsencrypt funziona e il client non da nessun messaggio di certificato non valido, il problema di usare letsencrypt  è che scade ogni 90 gg. Ora sto lavorando su un modo per rinnovare il SAN automaticamente partendo dall'ottimo lavoro fatto da lukas2511 (https://dehydrated.de).
Grazie

Rispondi |

Certificato SSL e virtual domain

Con letsencrypt puoii rinnovare mensilmente il certificato via cronjob ed evitare cosi il problema dei 90 gg

Rispondi |

Certificato SSL e virtual domain

Ciao Roberto, ho dovuto abbandonare l'uso dello script fatto lukas2511 perché non adatto ai server di posta ora uso acme.sh https://acme.sh, con diverse difficoltà legata soprattutto alla verifca del DNS tramite record TXT. Ma il mio ritorno a scriverti è più legato alla modalità di configurazione di qmail e dovecot. Nel mio primo post ti chiedevo dettagli sulla configurazione dei certificati di un server con decine di domini di posta gestiti vpopmail e dovecot. Seguendo la tua guida, Dovecot ha la possibilità di gestire solo una coppia di file (certificato e chiave) per il certificato SSL (Le altre configurazioni proposte dalla documentazione ufficiale non sono adattabili alle mie esigenze). Allora ho fatto con letsencrypt un SAN ma non sono sicuro che questa soluzione sia corretta dato che i SAN hanno un dominio principale mail.esempio.com e gli altri sono "alternativi". In più ti chiedo se è corretto usare la chiave del SAN e il certificato per generare il file servercert.pem che va in control di qmail?
Infine secondo te visto che nel tempo avrò la necessità di aggiungere domini al SAN cosa succede ai client che hanno già configurata la mail e acquisito il certificato quando lo trovano cambiato?

Grazie

Rispondi |

Certificato SSL e virtual domain

Ciao Gabriele, credo che l'esempio di uso di cerbot nella pagina che ho scritto di recente qui risponda già a quanto mi chiedi..

> Seguendo la tua guida, Dovecot ha la possibilità di gestire solo una coppia di file (certificato e chiave) per il certificato SSL
> (Le altre configurazioni proposte dalla documentazione ufficiale non sono adattabili alle mie esigenze). Allora ho fatto con
> letsencrypt un SAN ma non sono sicuro che questa soluzione sia corretta dato che i SAN hanno un dominio principale
> mail.esempio.com e gli altri sono "alternativi".

il primo dominio dichiarato mi pare che serva solo a dare un nome al certificato e che gli altri domini "alternativi" siano altrettanto validi. Io ce l'ho in produzione con più domini e va...

> In più ti chiedo se è corretto usare la chiave del SAN e il certificato
> per generare il file servercert.pem che va in control di qmail?

si, basta appendere i due nel file control/servercert.pem, come già ho scritto nella pagina di cui sopra

> Infine secondo te visto che nel tempo avrò la necessità di aggiungere domini al SAN cosa succede ai client che hanno
> già configurata la mail e acquisito il certificato quando lo trovano cambiato?

credo proprio che dovrebbero sotituirla in modo indolore, a meno che il client non sia settato per dare comunque una notifica (claws-mail ad es. ha una opzione del genere). La mia esperienza è che da quando ho risolto il problema dormo felice e nessuno mi ha più scritto messaggi dicendo che il client protesta :-)

Rispondi |

Certificato SSL e virtual domain

Ciao Roberto, grazie delle tue conferme.
Ho perfezionato la procedura per generare e rinnovare il SAN adattandola alle mie esigenze avendo scelto di non installare il webserver sulla macchina dove ho installato qmail.
Grazie

Gabriele

Rispondi |

Ultimi commenti
Vedi anche...
Articoli recenti

RSS feeds