server:postfix

Dies ist eine alte Version des Dokuments!


Postfix

Postfix ist ein Mail Transfer Agent für Unix und Unix-Derivate. Es wurde erschaffen, um eine kompatible Alternative zu Sendmail zu bieten. Bei der Entwicklung wurde insbesondere auf Sicherheitsaspekte geachtet. Postfix ist aber nicht nur sicher, sondern auch schnell und einfach zu administrieren. Zur Außenwelt verhält es sich wie Sendmail, aber im Inneren ist es komplett anders aufgebaut. Der Quellcode von Postfix steht unter der IBM Public License zur Verfügung.

FIXME

Bestandteil Aufgabe oft benutzte Aufrufe
postalias erzeugt die Alias-Datenbank
postconf zeigt oder verändert die Postfix-Konfiguration
postfix-add-policy
postmap für Lookup-Tables neue hash/btree-DB einer Klartextdatei erzeugen: postmap DATEI
postcat liest mails aus der mailqueue Mail ausgeben: postcat -q ID
postdrop
postfix-add-filter
postkick
postlog Möglichkeit für Scripts Lognachrichten zu erzeugen
postqueue Verwaltet die Mail-Queue Mails in Queue anzeigen: postqueue -p (flush mit -f)
postsuper Manipulation an der Mail-Queue einzelne Mail aus der queue löschen: postsuper -d ID oder alle postsuper -d ALL

für user@domain.tld:

while true; do for i in $(mailq | grep user@domain.tld | grep -v \! | grep ^[a-zA-Z0-9] | awk {'print $1'} |sed s/*//g);do postsuper -h $i; done ; done

und löschen:

find /var/spool/postfix/hold/ -print0 | xargs -0 -r -P10 -n10 fgrep -l 'user@domain.tld' | xargs -P10 -r -n1 basename | xargs -P10 -r -n1 postsuper -d
  • Versandprozesse limitieren (Beispiel: Auf 2 Prozess) * in der /etc/postfix/master.cf:
        # service type  private unpriv  chroot  wakeup  maxproc command + args
        smtp      unix  -       -       -       -       2       smtp
  • concurrency limits
    postconf  | grep '^\(default\|smtp\|relay\)[^ ]*concurrency[^ ]*'
    default_destination_concurrency_failed_cohort_limit = 1
    default_destination_concurrency_limit = 20
    default_destination_concurrency_negative_feedback = 1
    default_destination_concurrency_positive_feedback = 1
    relay_destination_concurrency_failed_cohort_limit = $default_destination_concurrency_failed_cohort_limit
    relay_destination_concurrency_limit = $default_destination_concurrency_limit
    relay_destination_concurrency_negative_feedback = $default_destination_concurrency_negative_feedback
    relay_destination_concurrency_positive_feedback = $default_destination_concurrency_positive_feedback
    relay_initial_destination_concurrency = $initial_destination_concurrency
    smtp_destination_concurrency_failed_cohort_limit = $default_destination_concurrency_failed_cohort_limit
    smtp_destination_concurrency_limit = $default_destination_concurrency_limit
    smtp_destination_concurrency_negative_feedback = $default_destination_concurrency_negative_feedback
    smtp_destination_concurrency_positive_feedback = $default_destination_concurrency_positive_feedback
    smtp_initial_destination_concurrency = $initial_destination_concurrency
  • nach postmap kommt dieser Fehler (Postfix Error “fatal: open database /etc/postfix/transport.db: Invalid argument”) Mails werden nicht mehr angenommen. Lösung: In der Konfiguration wird btree als Datenbankformat angegeben, postmap erstellt aber standardmäpßig hash-Datenbanken. Diser Eintrag in der /etc/postfix/main.cf behebt dies:
    default_database_type = btree
  • postfix start schlägt fehl:
    "Starting Postfix Mail Transport Agent: postfixfailure copying certificates ... failed!"

    aus $Gründen kommt Postfix nicht mehr mit diesen Angaben klar (nun auskommentiert)

    # smtpd_tls_CApath = /etc/ssl/certs
    # smtp_tls_CApath = /etc/ssl/certs

/etc/postfix/main.cf

smtpd_tls_received_header = yes
smtpd_tls_loglevel = 3  # 0 (none) to 4 (full data)
warning: SASL authentication problem: unable to open Berkeley db /etc/sasldb2: No such file or directory 
warning: unknown[x.x.x.x]: SASL LOGIN authentication failed: authentication failure

Eine leere Datei legt dieser Befehl an:

saslpasswd2 sasldb2

Wir brauchen als Vorraussetzung eine CA, diese stellt dann ein Zertifikat für den Client-MTA aus (MY-CERT.key und MY-CERT.key) aus. Man kopiert die beiden Zertifikatsdateien und dazu das Zertifikat (CA.crt) auf das Relay.

= TLS Auth start = 

# ask clients for certs:
smtpd_tls_ask_ccert=yes
permit_tls_all_clientcerts = yes

# SSL-Debug:
# smtpd_tls_loglevel = 1

# Fingerprints of SSL-Certs i trust and relay for (i am the relay for these hosts and they auth via their ssl-Cert)
relay_clientcerts = btree:/etc/postfix/relay_clientcerts

# TLS parameters (certs/keys in pem-format)
smtpd_tls_cert_file= /etc/postfix/MY-CERT.crt
smtpd_tls_key_file= /etc/postfix/MY-CERT.key
smtpd_tls_CAfile= /etc/postfix/CA.crt

# enable STARTTLS outgoing:
smtp_tls_security_level=may
# enable STARTTLS incoming:
smtpd_tls_security_level=may

= TLS Auth end =

Außerdem wird eine weitere Zeile zu den „smtpd_recipient_restrictions“ hinzugefügt:

smtpd_recipient_restrictions =
   ...
   permit_tls_clientcerts,
   ...

Die Datei /etc/postfix/relay_clientcerts enthält den Fingerabdruck der Clients die sich am Relay damit authentifizieren wollen.

# List all client-certs that are allowed to srelay mail over me
# only MD5-Fingerprints (not SHA-1) seems to work, the comment is unimportant.
# you get the fingerprint with: "openssl x509 -md5 -noout -fingerprint -in FILENAME-OF-CRT"
#
EA:0E:CD:21:19:0A:DE:DC:66:49:89:7B:E4:DF:7E:A3		Client XY

…um E-Mail anzunehmen: minimaler Platz queue_minfree (in Byte)

Die meisten Clients benutzen Port 25 und aktivieren SSL/TLS wenn angeboten (über STARTTLS), manche alte Client brauchen aber den Port 465 (SSMTP = SMTP + SSL). Außerdem blockieren einige Provider Port 25 ausgehend (um Spam einzudämmen), in diesem Fall brauchen diese Kunden auf dem Server Port 587 (submission) aktiviert.

Beides lässt sich über die beiden folgenden Zeilen in der /etc/postfix/master.cf aktivieren:

# some providers block Port 25 outgoing, so Port 587 (submission) in advised
submission inet n       -       -       -       -       smtpd
  -o smtpd_tls_security_level=encrypt
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
  -o milter_macro_daemon_name=ORIGINATING

# SMTP+SSL (SSMTP) on Port 465
smtps     inet  n       -       -       -       -       smtpd
  -o smtpd_tls_wrappermode=yes
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
  -o milter_macro_daemon_name=ORIGINATING

Postfix kann für Domains oder einzelne Empfänger Kopien erzeugen, damit kann ein Mailarchiv erreicht werden.

In /etc/postfix/main.cf1):

sender_bcc_maps = btree:/etc/postfix/sender_bcc
recipient_bcc_maps = btree:/etc/postfix/recipient_bcc

Ganze Domains:

@domain.tld archiv@example.com
@domain.eu archiv@example.com

Einzelne Benutzer:

info@domain.com chef@example.com
kotakt@domain.eu archiv@example.com

1)
statt btree geht auch hash