Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen Revision Vorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
centos:mail_c7:dovecot_2 [10.08.2014 09:13. ] – [LMTP] djangocentos:mail_c7:dovecot_2 [22.07.2019 14:41. ] (aktuell) django
Zeile 307: Zeile 307:
  
 === automatische Pflege === === automatische Pflege ===
-<WRAP round important>Erreicht nun eine Kontaktanfrage von einem fremden Mailserver, also einem Server, der __**nicht**__ in **$mynetworks** definiert ist, kann man im Logfile des Mailservers sehr schön beobachten, wie Postfix die Adressen überprüft.</WRAP>+<WRAP round important>Erreicht nun eine Kontaktanfrage von einem fremden Mailserver, also einem Server, der **__nicht__** in **$mynetworks** definiert ist, kann man im Logfile des Mailservers sehr schön beobachten, wie Postfix die Adressen überprüft.</WRAP>
    # tail -f /var/log/maillog    # tail -f /var/log/maillog
 <code>... <code>...
Zeile 354: Zeile 354:
 Connected to 10.0.0.70. Connected to 10.0.0.70.
 Escape character is '^]'.</font> Escape character is '^]'.</font>
-<font style="color: rgb(66, 66, 66)">&nbsp;220 imap.nausch.org Dovecot ready.</font>+<font style="color: rgb(66, 66, 66)">220 imap.nausch.org Dovecot ready.</font>
 <font style="color: rgb(0, 0, 255)">LHLO vml000080.dmz.nausch.org</font> <font style="color: rgb(0, 0, 255)">LHLO vml000080.dmz.nausch.org</font>
-<font style="color: rgb(66, 66, 66)">&nbsp;250-imap.nausch.org +<font style="color: rgb(66, 66, 66)">250-imap.nausch.org 
-&nbsp;250-8BITMIME +250-8BITMIME 
-&nbsp;250-ENHANCEDSTATUSCODES +250-ENHANCEDSTATUSCODES 
-&nbsp;250 PIPELINING</font>+250 PIPELINING</font>
 <font style="color: rgb(0, 0, 255)">mail from:&lt;django@nausch.org&gt;</font> <font style="color: rgb(0, 0, 255)">mail from:&lt;django@nausch.org&gt;</font>
-<font style="color: rgb(66, 66, 66)">&nbsp;250 2.1.0 OK</font>+<font style="color: rgb(66, 66, 66)">250 2.1.0 OK</font>
 <font style="color: rgb(0, 0, 255)">rcpt to:&lt;michael@nausch.org&gt;</font> <font style="color: rgb(0, 0, 255)">rcpt to:&lt;michael@nausch.org&gt;</font>
-<font style="color: rgb(66, 66, 66)">&nbsp;250 2.1.0 OK</font>+<font style="color: rgb(66, 66, 66)">250 2.1.0 OK</font>
 <font style="color: rgb(0, 0, 255)">DATA</font> <font style="color: rgb(0, 0, 255)">DATA</font>
-<font style="color: rgb(66, 66, 66)">&nbsp;354 OK</font>+<font style="color: rgb(66, 66, 66)">354 OK</font>
 <font style="color: rgb(0, 0, 255)">From: django@nausch.org <font style="color: rgb(0, 0, 255)">From: django@nausch.org
 To: michael@nausch.org To: michael@nausch.org
Zeile 371: Zeile 371:
 Date: 2014-07-23 23:42 Date: 2014-07-23 23:42
  
- Ahoi, +Ahoi, 
- das ist eine Testmail, eingeliefert via telnet imap-server auf Port 24+das ist eine Testmail, eingeliefert via telnet imap-server auf Port 24
      
 .</font> .</font>
-<font style="color: rgb(66, 66, 66)">&nbsp;250 2.0.0 <michael@nausch.org> UYNyIuTM0FM+YgAAOs1BfA Saved</font>+<font style="color: rgb(66, 66, 66)">250 2.0.0 <michael@nausch.org> UYNyIuTM0FM+YgAAOs1BfA Saved</font>
 <font style="color: rgb(0, 0, 255)">quit</font> <font style="color: rgb(0, 0, 255)">quit</font>
-<font style="color: rgb(66, 66, 66)">&nbsp;221 2.0.0 OK</font>+<font style="color: rgb(66, 66, 66)">221 2.0.0 OK</font>
 <font style="color: rgb(0, 0, 0)">Connection closed by foreign host.</font> <font style="color: rgb(0, 0, 0)">Connection closed by foreign host.</font>
 </pre></html> </pre></html>
Zeile 443: Zeile 443:
 Date: 2014-07-23 23:42 Date: 2014-07-23 23:42
  
- Ahoi, +Ahoi, 
- das ist eine Testmail, eingeliefert via telnet imap-server auf Port 24+das ist eine Testmail, eingeliefert via telnet imap-server auf Port 24
      
  
Zeile 450: Zeile 450:
  
  
-====== SASL ====== +====== 2. SASL ====== 
-Damit unsere Mailbox-Inhaber auch von extern aus Ihre eMails bei unserem Postfix-Mailserver abliefern können, benötigen wir einen Mechanismus, der den Clients erlaub sich beim SMTP-Server anzumelden. Postfix bietet hierzu das Framework **[[http://de.wikipedia.org/wiki/Simple_Authentication_and_Security_Layer|SASL]]**((**S**imple **A**uthentication and **S**ecurity **L**ayer)) zur Authentifizierung an. +Damit unsere Mailbox-Inhaber auch von extern aus Ihre eMails bei unserem Postfix-Mailserver abliefern können, benötigen wir einen Mechanismus, der den Clients erlaub sich beim SMTP-Server anzumelden. Postfix bietet hierzu das Framework **[[http://de.wikipedia.org/wiki/Simple_Authentication_and_Security_Layer|SASL]]**((**S**imple **A**uthentication and **S**ecurity **L**ayer)) zur Authentifizierung an. Somit brauchen wir uns keine großen Gedanken machen, welche Authentifikationsmechanismen wir bei unserem Postfix-Server konfigurieren müssen.  
 + 
 +===== Dovecot ===== 
 +==== Konfiguration ==== 
 +Die Konfiguration auf Seiten des Dovecot-Servers ist denkbar einfach, ist die grundlegende Konfiguration ja schon in der Datei //**/etc/dovecot/conf.d/10-master.conf**// vorbereitet. 
 +   # vim /etc/dovecot/conf.d/10-master.conf 
 + 
 +<code bash>... 
 + 
 +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 = 0666 
 +    #user =  
 +    #group = 
 +  } 
 + 
 +  # Postfix smtp-auth 
 +  #unix_listener /var/spool/postfix/private/auth { 
 +  #  mode = 0666 
 +  #} 
 + 
 +  # Auth process is run as this user. 
 +  #user = $default_internal_user 
 + 
 +  # Django : 2014-05-23 
 +  # default: unset 
 +  # Authentifizierungsport 3659 für Postfix Frontend-Mailserver definiert 
 +    inet_listener { 
 +     address = 10.0.0.70 
 +     port = 3659 
 +  } 
 + 
 +
 + 
 +... 
 +</code> 
 + 
 +Zum Aktivieren unserer Einstellungsänderungen führen wir einen **Reload** unseres Dovecot-Daemon durch. 
 +   # systemctl reload dovecot 
 + 
 +Fragen wir nun die offenen Ports von Dovecot ab, finden wir auch unseren SASL-Port **3569**. 
 +   # netstat -tulpen | grep  dovecot 
 + 
 +   tcp        0      0 10.0.0.70:4190          0.0.0.0:              LISTEN      0          126663     13526/dovecot        
 +   tcp        0      0 10.0.0.70:993           0.0.0.0:              LISTEN      0          126726     13526/dovecot        
 +   tcp        0      0 10.0.0.70:995           0.0.0.0:              LISTEN      0          126689     13526/dovecot        
 +   tcp        0      0 10.0.0.70:3659          0.0.0.0:              LISTEN      0          129217     13526/dovecot        
 +   tcp        0      0 10.0.0.70:110           0.0.0.0:              LISTEN      0          126688     13526/dovecot        
 +   tcp        0      0 10.0.0.70:143           0.0.0.0:              LISTEN      0          126725     13526/dovecot        
 +   tcp        0      0 10.0.0.70:10000         0.0.0.0:              LISTEN      0          126788     13526/dovecot        
 +   tcp        0      0 10.0.0.70:24            0.0.0.0:              LISTEN      0          126698     13526/dovecot 
 + 
 +==== Paketfilter / Firewall ==== 
 +Damit nun nicht jeder fremde Host sich mit dem **SASL**-Port verbinden kann, regeln wir den Zugriff über eine Firewall-Regel so, dass __**nur**__ der vorgeschaltete **MTA** Postfix-Mailserver sich mit unserem **Dovecot-Server** auf Port **3569** verbinden kann.  
 + 
 +Unter **CentOS 7** wird als Standard-Firewall die dynamische **firewalld** verwendet. Ein großer Vorteil der dynamischen Paketfilterregeln ist unter anderem, dass zur Aktivierung der neuen Firewall-Regel(n) nicht der Daemon durchgestartet werden muss und somit alle aktiven Verbiundungen kurz getrennt werden. Sondern unsere Änderungen können **//on-the-fly//** aktiviert oder auch wieder deaktiviert werden. 
 + 
 +In unserem Konfigurationsbeispiel hat unser Postfix-Server die IP-Adresse 10.0.0.80 und unser Dovecot-Server die 10.0.0.70. Wir brauchen also eine Firewall-Definition, die ausschließlich Verbindungen von der **Source-IP** 10.0.0.80 auf die **Destination-IP** 10.0.0.70 auf Port **3569** gestattet. 
 + 
 +Mit Hilfe des Programms **firewall-cmd** legen wir nun eine **permanente** Regel in der Zone **public**, dies entspricht in unserem Beispiel das Netzwerk-Interface **eth0** mit der IP **10.0.0.70** an. Als Source-IP geben wir die IP-Adresse unseres Postfix-Servers also die **10.0.0.80** an. Genug der Vorrede, mit nachfolgendem Befehl wird diese restriktive Regel angelegt. 
 +   # firewall-cmd --permanent --zone=public --add-rich-rule="rule family="ipv4" source address="10.0.0.80/32" port protocol="tcp" port="3569" destination address="10.0.0.70/32" accept" 
 + 
 +Zum Aktivieren brauchen wir nun nur einen reload des Firewall-Daemon vornehmen. 
 +   # firewall-cmd --reload 
 + 
 +Fragen wir nun den Regelsatz unserer **iptables**-basieten Firewall ab, finden wir in der Chain **IN_public_allow** unsere aktive Regel. 
 +   # iptables -nvL IN_public_allow 
 + 
 +<code>Chain IN_public_allow (1 references) 
 + pkts bytes target     prot opt in     out     source               destination          
 +    0     0 ACCEPT     tcp  --  *      *       10.0.0.80            10.0.0.70            tcp dpt:3569 ctstate NEW 
 +    0     0 ACCEPT     tcp  --  *      *       10.0.0.80            10.0.0.70            tcp dpt:10000 ctstate NEW 
 +    0     0 ACCEPT     tcp  --  *      *       10.0.0.80            10.0.0.70            tcp dpt:24 ctstate NEW 
 +    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/           0.0.0.0/           tcp dpt:22 ctstate NEW 
 +    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/           0.0.0.0/           tcp dpt:110 ctstate NEW 
 +    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/           0.0.0.0/           tcp dpt:143 ctstate NEW 
 +    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/           0.0.0.0/           tcp dpt:995 ctstate NEW 
 +    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/           0.0.0.0/           tcp dpt:993 ctstate NEW 
 +</code> 
 +===== Postfix ===== 
 +Auch der Konfigurationsaufwand auf Seiten von Postfix hält sich in überschaubaren Grenzen. 
 +==== Konfiguration ==== 
 +Zum Aktivieren der SASL-Autentifikation gegen unseren Dovecot-Server tragen wir die folgenden Zeilen in der Postfix-konfigurationsdatei //**/etc/postfix/main.cf**// nach 
 +   # vim /etc/postfix/main.cf 
 +<code bash>... 
 + 
 +# Django : 2012-10-09 
 +# SMTP-Auth (SASL) 
 +# Enable SASL authentication in the Postfix SMTP server. By default, the Postfix SMTP server  
 +# does not use authentication.  
 +smtpd_sasl_auth_enable = yes 
 +# The SASL plug-in type that the Postfix SMTP server should use for authentication. The available  
 +# types are and dovecot.  
 +smtpd_sasl_type = dovecot 
 +# Implementation-specific information that the Postfix SMTP server passes through to the SASL  
 +# plug-in implementation that is selected with smtpd_sasl_type. Typically this specifies the  
 +# name of a configuration file or rendezvous point.  
 +smtpd_sasl_path = inet:10.0.0.70:3659 
 +# Postfix SMTP server SASL security options; as of Postfix 2.3 the list of available features  
 +# depends on the SASL server implementation that is selected with smtpd_sasl_type. The following  
 +# security features are defined for the cyrus server SASL implementation: 
 +# Restrict what authentication mechanisms the Postfix SMTP server will offer to the client.  
 +# The list of available authentication mechanisms is system dependent. Specify zero or more of  
 +# the following: 
 +#               noplaintext 
 +#                               Disallow methods that use plaintext passwords.  
 +#               noactive 
 +#                               Disallow methods subject to active (non-dictionary) attack.  
 +#               nodictionary 
 +#                               Disallow methods subject to passive (dictionary) attack.  
 +#               noanonymous 
 +#                               Disallow methods that allow anonymous authentication.  
 +#               forward_secrecy 
 +#                               Only allow methods that support forward secrecy (Dovecot only).  
 +#               mutual_auth 
 +#                               Only allow methods that provide mutual authentication  
 +#                               (not available with Cyrus SASL version 1).  
 +#  
 +# By default, the Postfix SMTP server accepts plaintext passwords but not anonymous logins. 
 +
 +# Warning: it appears that clients try authentication methods in the order as advertised by the  
 +# server (e.g., PLAIN ANONYMOUS CRAM-MD5) which means that if you disable plaintext passwords,  
 +# clients will log in anonymously, even when they should be able to use CRAM-MD5. So, if you  
 +# disable plaintext logins, disable anonymous logins too. Postfix treats anonymous login as no  
 +# authentication. 
 +smtpd_sasl_security_options = noanonymous 
 +# The name of the Postfix SMTP server's local SASL authentication realm. 
 +# By default, the local authentication realm name is the null string.  
 +smtpd_sasl_local_domain = $mydomain 
 +#  The SASL authentication security options that the Postfix SMTP server uses for TLS encrypted  
 +# SMTP sessions. 
 +smtpd_sasl_tls_security_options = $smtpd_sasl_security_options 
 +# Enable inter-operability with remote SMTP clients that implement an obsolete version of the  
 +# AUTH command (RFC 4954). Examples of such clients are MicroSoft Outlook Express version 4  
 +# and MicroSoft Exchange version 5.0.  
 +broken_sasl_auth_clients = yes 
 + 
 + 
 +... 
 +</code> 
 + 
 +Ein Restart unseres Postfix-Servers aktiviert unsere Konfigurationsanpassungen. 
 +   # systemctl restart postfix 
  
-===== Dovecot (SASL) ===== 
-FIXME 
-===== Postfix (SASL) ===== 
-FIXME 
 ===== SASL-Anmeldetest ===== ===== SASL-Anmeldetest =====
- FIXME+Melden wir uns nun via **telnet** auf Port **25** bei unserem Postfix-Server an werden uns nach Eingabe des **EHLO** die Authentifizierungsmöglichkeiten (gegen unseren Dovecot-SASL-Port 3569) angezeigt. 
 + 
 +Bei Test vsind die Eingaben am testenden Client in der Farbe <html><font style="color: rgb(0, 0, 255)"><b>blau</b></font></html> und die Rückmeldungen unseres Dovecot-Servers in der Farbe <html><font style="color: rgb(66, 66, 66)"><b>hellgrau</b></font></html> gekennzeichnet. Die Ausgaben des Befehls **telnet** sind in der Farbe <html><font style="color: rgb(0, 0, 0)"><b>schwarz</b></font></html> eingefärbt. 
 + 
 +Wir bauen also eine Verbindung zu unserem Postfix-Server zum **SMTP** **25** auf und setzen dann den Befehl **EHLO** ab, damit uns der SMTP-server seine Authentifizierungsoptionen anzeigt. 
 + 
 +<html><pre class="code"> 
 +<font style="color: rgb(0, 0, 0)">$ </font><font style="color: rgb(0, 0, 255)">telnet 10.0.0.80 25</font> 
 +<font style="color: rgb(0, 0, 0)">Trying 10.0.0.80... 
 +Connected to 10.0.0.80. 
 +Escape character is '^]'.</font> 
 +<font style="color: rgb(66, 66, 66)">220 mx01.nausch.org ESMTP Postfix</font> 
 +<font style="color: rgb(0, 0, 255)">EHLO test</font> 
 +<font style="color: rgb(66, 66, 66)">250-mx01.nausch.org 
 +250-PIPELINING 
 +250-SIZE 52428800 
 +250-ETRN 
 +250-STARTTLS 
 +250-AUTH PLAIN LOGIN DIGEST-MD5 CRAM-MD5 
 +250-AUTH=PLAIN LOGIN DIGEST-MD5 CRAM-MD5 
 +250-ENHANCEDSTATUSCODES 
 +250 8BITMIME</font> 
 +<font style="color: rgb(0, 0, 255)">quit</font> 
 +<font style="color: rgb(66, 66, 66)">221 2.0.0 Bye</font> 
 +<font style="color: rgb(0, 0, 0)">Connection closed by foreign host.</font> 
 +</pre></html> 
 + 
 +Melden wir uns nun über unseren Mailclient an, typischerweise passiert das jeweils vor dem Versand von ausgehenden Nachrichten, sehen wir diese Anmeldungen auch im Maillog unseres Postfix-Servers 
 +   # less /var/log/maillog 
 + 
 +   Aug 10 10:56:29 vml000080 postfix/smtpd[20787]: A46D975: client=vml000020.dmz.nausch.org[10.0.0.20], sasl_method=LOGIN, sasl_username=django@nausch.org 
 + 
 +Auf seiten unseres Dovecot-Servers passiert natürlich wesentlich mehr, da ja dort die Authentifizierungsanfrage des Postfix-Servers angenommen und bearbeitet wird. Im Detail bedeutet dies, dass der Dovecot-Server eine **passdb-Anfrage** gegen unsere MySQL-Datenbank macht und das Ergebnis **OK** an den postfix-Frontend-Server zurückmeldet. 
 +   # less /var/log/maillog 
 + 
 +<code bash>Aug 10 10:56:29 vml000070 dovecot: auth: Debug: auth client connected (pid=0) 
 +Aug 10 10:56:29 vml000070 dovecot: auth: Debug: client in: AUTH#0111#011LOGIN#011service=smtp#011nologin#011lip=10.0.0.80#011rip=10.0.0.20#011secured 
 +Aug 10 10:56:29 vml000070 dovecot: auth: Debug: client passdb out: CONT#0111#011VXNlcm5hbWU6 
 +Aug 10 10:56:29 vml000070 dovecot: auth: Debug: client in: CONT#0111#011bWljaGFlbEBuYXVzY2gub3Jn (previous base64 data may contain sensitive data) 
 +Aug 10 10:56:29 vml000070 dovecot: auth: Debug: client passdb out: CONT#0111#011UGFzc3dvcmQ6 
 +Aug 10 10:56:29 vml000070 dovecot: auth: Debug: client in: CONT#0111#011RGQ0bWRkMyE= (previous base64 data may contain sensitive data) 
 +Aug 10 10:56:29 vml000070 dovecot: auth: Debug: sql(michael@nausch.org,10.0.0.20): cache expired 
 +Aug 10 10:56:29 vml000070 dovecot: auth-worker(6830): Debug: Loading modules from directory: /usr/lib64/dovecot/auth 
 +Aug 10 10:56:29 vml000070 dovecot: auth-worker(6830): Debug: Module loaded: /usr/lib64/dovecot/auth/libdriver_mysql.so 
 +Aug 10 10:56:29 vml000070 dovecot: auth-worker(6830): Debug: Module loaded: /usr/lib64/dovecot/auth/libdriver_sqlite.so 
 +Aug 10 10:56:29 vml000070 dovecot: auth-worker(6830): Debug: sql(michael@nausch.org,10.0.0.20): query: SELECT username AS user, password FROM mailbox WHERE username = 'michael@nausch.org' AND active = '1' 
 +Aug 10 10:56:29 vml000070 dovecot: auth: Debug: client passdb out: OK#0111#011user=michael@nausch.org#011 
 +</code> 
 + 
 + 
  
-   Aug 10 10:56:30 vml000080 postfix/smtpd[20787]: A46D975: client=vml000020.dmz.nausch.org[10.0.0.20], sasl_method=LOGIN, sasl_username=django@nausch.org 
  
  
Zeile 468: Zeile 669:
   * **[[http://dokuwiki.nausch.org/doku.php/|Zurück zur Startseite]]**   * **[[http://dokuwiki.nausch.org/doku.php/|Zurück zur Startseite]]**
  
-~~DISCUSSION~~ 
  
  • centos/mail_c7/dovecot_2.1407662011.txt.gz
  • Zuletzt geändert: 10.08.2014 09:13.
  • von django