Ir al contenido

Servidor de Correo – Casillas y usuarios virtuales

Introducción

Este artículo cubre el soporte de múltiples dominios y usuarios virtuales, gestión de alias y correo electrónico mediante interfaces web.

Nombre del Servidor: servidor.midominio.edu.ar
Sistema Operativo: Debian 10 “Buster”

Instalar paquetes

# apt install postfix postfix-mysql dovecot-core dovecot-imapd dovecot-pop3d dovecot-lmtpd dovecot-mysql mariadb-server dovecot-sieve dovecot-managesieved

Si estás agregando un servidor de correo a un sistema existente algunos paquetes pueden ya estar presentes. Dependiendo de la lista de paquetes previamente instalada, puede que veas o no los avisos para configurar mariadb, postfix, etc. Escoge los valores predeterminados siempre que sea posible.

Configuración de Postfix

Esta guía fue creada usando Postfix 3.4.14. Se puede verificar la versión de postfix instalada usando:

# postconf mail_version

La configuración de Postfix tiene 2 archivos importantes: main.cf y master.cf

Vamos a agregar también algunos otros archivos para el sistema virtual de dominio/correo.

Postfix – master.cf

Para que smtp ‘escuche’ en el puerto 465 (con SSL) y en el puerto 587 (con TLS), es necesario descomentar las siguientes lineas en

master.cf:
submission inet n - - - - smtpd
smtps inet n - - - - smtpd

Se recomienda hacer esto ya que la mayoría de los ISP bloquea el puerto 25 para prevenir spam.

Diffie – Hellman

El intercambio de claves Diffie-Hellman es un método de intercambio seguro de claves criptográficas a través de un canal público. Su objetivo principal es desarrollar de forma segura secretos compartidos que puedan utilizarse para derivar claves. Estas claves pueden utilizarse con algoritmos de clave simétrica para transmitir información de forma protegida.

Generación de un grupo DH único

Primero hay que generar un nuevo y único grupo Diffie-Hellman, la recomendación es que sea de 2048 bits. La forma más sencilla de hacerlo es utilizar OpenSSL:

# openssl dhparam -out dhparams.pem 2048

Esto puede representar una carga significativa en el servidor mientras se generan los parámetros – siempre se puede evitar este problema potencial mediante la generación de los parámetros en otra máquina y el uso de scp o similar para transferirlos al servidor en cuestión para su uso.

Postfix – main.cf

Agregar al main.cf las siguientes lineas hacia el final del archivo:
Agregamos y ajustamos los demás parámetros:

# other destination domains should be handled using virtual domains
mydestination = localhost
smtp_host_lookup = dns
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
smtpd_tls_dh1024_param_file = /etc/ssl/private/dhparams.pem
smtpd_helo_required=yes
#Secure Client-Initiated Renegotiation
# postfix 3.4 and openssl >1.1.1
tls_ssl_options = NO_RENEGOTIATION
#Enable TLS Encryption when Postfix receives incoming emails
smtpd_tls_cert_file=/etc/apache2/md/domains/midominio.edu.ar/pubcert.pem
smtpd_tls_key_file=/etc/apache2/md/domains/midominio.edu.ar/privkey.pem
# Enforce encryption during authentication
smtpd_tls_auth_only=yes
smtpd_tls_loglevel = 1
# Add information about the ciphers used during transfer to the
# message headers
smtpd_tls_received_header = yes
# Encryption is optional. Changing this to encrypt will enforce
# the use of TLS but has the side effect that MTAs without TLS
# capability won't be able to deliver mail to our server.
smtpd_tls_security_level = may
# Disallow any methods that do allow anonymous authentication
smtpd_sasl_security_options = noanonymous, noplaintext
smtpd_sasl_tls_security_options = noanonymous
smtpd_tls_loglevel = 1
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
#Enable TLS Encryption when Postfix sends outgoing emails
# Enforce the use of TLS
smtp_tls_security_level = may
smtp_tls_loglevel = $smtpd_tls_loglevel
smtp_tls_mandatory_protocols = $smtpd_tls_mandatory_protocols
smtp_tls_mandatory_ciphers = $smtpd_tls_mandatory_ciphers
smtp_tls_exclude_ciphers = $smtpd_tls_exclude_ciphers
smtp_tls_mandatory_exclude_ciphers = $smtpd_tls_mandatory_exclude_ciphers
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
# Negotiate the strongest available cipher available with the remote server.
smtpd_tls_protocols = TLSv1.2, !TLSv1.1, !TLSv1, !SSLv2, !SSLv3
smtp_tls_protocols = $smtpd_tls_protocols
smtp_tls_ciphers = high
smtpd_tls_ciphers = high
smtpd_tls_mandatory_protocols = $smtpd_tls_protocols
smtp_tls_mandatory_protocols = $smtpd_tls_protocols
smtp_tls_mandatory_ciphers = high
smtpd_tls_mandatory_ciphers = high
# Exclude some deprecated not so secure ciphers.
smtpd_tls_mandatory_exclude_ciphers = MD5, DES, ADH, RC4, PSD, SRP, 3DES, eNULL, aNULL
smtpd_tls_exclude_ciphers = $smtpd_tls_mandatory_exclude_ciphers
smtp_tls_mandatory_exclude_ciphers = $smtpd_tls_mandatory_exclude_ciphers
smtp_tls_exclude_ciphers = $smtpd_tls_mandatory_exclude_ciphers
# Postfix will select the cipher used for communication.
tls_preempt_cipherlist = yes
# Disable all OpenSSL bug work-arounds on a 64 bit system
tls_disable_workarounds = 0xFFFFFFFFFFFFFFFF
#Handle SMTP authentication using Dovecot
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
# Don't talk to mail systems that don't know their own hostname.
smtpd_recipient_restrictions =
 reject_unknown_sender_domain,
 permit_mynetworks,
 permit_sasl_authenticated,
# DNSBL (DNS Based Blacklist/Blocklist)
 reject_rbl_client zen.spamhaus.org,
 reject_rhsbl_reverse_client dbl.spamhaus.org,
 reject_rhsbl_helo dbl.spamhaus.org,
 reject_rhsbl_sender dbl.spamhaus.org,
# Don't accept mail from domains that don't exist.
smtpd_sender_restrictions =
 reject_unknown_sender_domain
# Allow connections from trusted networks and authenticated users.
smtpd_client_restrictions =
 permit_mynetworks,
 permit_sasl_authenticated
# Relay control: local clients and
# authenticated clients may specify any destination domain.
smtpd_relay_restrictions =
 permit_mynetworks,
 permit_sasl_authenticated,
 reject_unauth_destination
#The size is in Bytes...
mailbox_size_limit = 0 # Ilimitado
message_size_limit = 20971520 # 20 Mb
# using Dovecot's LMTP for mail delivery and giving it path to store mail
virtual_transport = lmtp:unix:private/dovecot-lmtp
# virtual mailbox setups
virtual_alias_maps = mysql:/etc/postfix/mysql/virtual_alias_maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql/virtual_domains_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql/virtual_mailbox_maps.cf

Deshabilitamos el chroot (predeterminado en Debian) modificando /etc/postfix/master.cf. Debería verse así

# ==========================================================================
# service type private unpriv chroot wakeup maxproc command + args
# (yes) (yes) (yes) (never) (100)
# ==========================================================================
smtp unix - - - - - smtp

Verificar certificados

Ninguna configuración está exenta de eventuales problemas. Llegado el caso, estos comandos pueden resultar de utilidad a la hora de enfrentarlos.
Para los certificados públicos

openssl x509 -in /etc/apache2/md/domains/midominio.edu.ar/pubcert.pem -text -noout

Si no está dañado el resultado de este comando debería mostrar, entre otras cosas, los (sub)dominios para los cuales fue creado:

DNS:campus.midominio.edu.ar, DNS:eventos.midominio.edu.ar, DNS:mapa.midominio.edu.ar, DNS:nube.midominio.edu.ar, DNS:pad.midominio.edu.ar, DNS:reuniones.midominio.edu.ar, DNS:www.midominio.edu.ar

En tanto que, para los certificados privados verificamos que contengan una llave válida

openssl rsa -in /etc/apache2/md/domains/midominio.edu.ar/privkey.pem -text -noout

El resultado de este comando debería mostrar algo así:

RSA key ok
Etiquetas: