HOWTO: Postfix Policy-Server für Plesk und qmail

Postfix, QMail, Sendmail, Dovecot, Cyrus, Courier, Anti-Spam
Roger Wilco
Posts: 5923
Joined: 2004-05-23 12:53
 

HOWTO: Postfix Policy-Server für Plesk und qmail

Post by Roger Wilco »

Dieser Text steht unter einer Creative Commons-Lizenz: Image

Diese Anleitung beschreibt die Einrichtung und Nutzung von Postfix Policy-Servern (wie policyd-weight oder postgrey, welche auch in diesem HOWTO genutzt werden) mit der qmail-Installation, die von Plesk genutzt wird. Dazu wird das Skript PolicyHQ genutzt.

Installation
Zunächst wird PolicyHQ heruntergeladen und installiert. Zusätzlich sollte die beigelegte README-Datei gelesen werden.

Code: Select all

# wget http://files.schalanda.name/policyhq/policyhq-0.1.tar.bz2
# tar -xjf policyhq-0.1.tar.bz2
# cp policyhq-0.1/policyhq /usr/local/bin/
Danach wird policyd-weight installiert

Code: Select all

# wget -O /usr/local/bin/policyd-weight http://policyd-weight.org/policyd-weight
# chmod +x /usr/local/bin/policyd-weight
# groupadd polw
# useradd -d /var/lib/empty/ -g polw -s /bin/false polw
...und anschließend gestartet.

Code: Select all

# policyd-weight start
Der policyd-weight ist dann über 127.0.0.1:12525 erreichbar.

Ebenso wird postgrey heruntergeladen, installiert

Code: Select all

# wget http://postgrey.schweikert.ch/pub/postgrey-1.32.tar.gz
# tar -xzf postgrey-1.32.tar.gz
# cp postgrey-1.32/postgrey /usr/local/bin/
# useradd -d /var/lib/empty/ -g nogroup -s /bin/false postgrey
# mkdir -p /var/lib/postgrey
# chown postgrey /var/lib/postgrey
# touch /var/qmail/control/postgrey_whitelist_clients /var/qmail/control/postgrey_whitelist_recipients
# chown postgrey /var/qmail/control/postgrey_whitelist_clients /var/qmail/control/postgrey_whitelist_recipients
...und anschließend gestartet.

Code: Select all

# postgrey -d -i 60000 --dbdir=/var/lib/postgrey --whitelist-clients=/var/qmail/control/postgrey_whitelist_clients --whitelist-recipients=/var/qmail/control/postgrey_whitelist_recipients
Postgrey ist danach über 127.0.0.1:60000 erreichbar.

Konfiguration
Beide Policy-Server müssen am Anfang der Datei /usr/local/bin/policyhq eingetragen werden. Eine Erweiterung mit weiteren Policy-Servern ist dabei jederzeit möglich.

Code: Select all

$policy_servers['policyd-weight'] = array(
                'address' => '127.0.0.1',
                'port' => 12525,
                'timeout' => 10
        );
$policy_servers['postgrey']       = array(
                'address' => '127.0.0.1',
                'port' => 60000,
                'timeout' => 10
        );
Im letzten Schritt werden die Handler bei qmail registriert.

Beispiel: policyd-weight wird für alle Domains und postgrey für 2 spezielle Domains domain1.tld und domain2.tld (die vielleicht besonders viele Spam-Mails erhalten) registriert:

Code: Select all

# /usr/local/psa/admin/sbin/mailmng --add-handler --handler-name=2policy_1 --global --context policyd-weight --executable=/usr/local/bin/policyhq --hook=before-queue

Code: Select all

# /usr/local/psa/admin/sbin/mailmng --add-handler --handler-name=1postgrey_1 --recipient-domain=domain1.tld --context postgrey --executable=/usr/local/bin/policyhq --hook=before-queue

Code: Select all

# /usr/local/psa/admin/sbin/mailmng --add-handler --handler-name=1postgrey_2 --recipient-domain=domain2.tld --context postgrey --executable=/usr/local/bin/policyhq --hook=before-queue
Der mit --context übergebene Wert muss mit den Einstellungen in /usr/local/bin/policyhq übereinstimmen, um den richtigen Policy-Server auszuwählen. Der mit --handler-name übergebene Wert muss ein eindeutiger Bezeichner sein.

Überprüfung des Setups
Wenn die Einrichtung erfolgreich war, werden entsprechende Einträge im Mail Log unter /usr/local/psa/var/log/maillog erstellt.
In diesem Auszug wird eine E-Mail von localpart@example.com an recipient@domain1.tld zunächst temporär auf Grund der Entscheidung von postgrey abgewiesen (Greylisting).

Code: Select all

Aug 27 22:19:43 hostname qmail-queue-handlers[20722]: Handlers Filter before-queue for qmail started ...
Aug 27 22:19:43 hostname qmail-queue-handlers[20722]: from=localpart@example.com
Aug 27 22:19:43 hostname qmail-queue-handlers[20722]: to=recipient@domain1.tld
Aug 27 22:19:43 hostname qmail-queue-handlers[20722]: hook_dir = '/var/qmail//handlers/before-queue'
Aug 27 22:19:43 hostname qmail-queue-handlers[20722]: recipient[3] = 'recipient@domain1.tld'
Aug 27 22:19:43 hostname qmail-queue-handlers[20722]: handlers dir = '/var/qmail//handlers/before-queue/recipient/recipient@domain1.tld'
Aug 27 22:19:43 hostname qmail-queue-handlers[20722]: found handlers entry = '/var/qmail//handlers/before-queue/recipient-domain/domain1.tld/1postgrey_1'
Aug 27 22:19:43 hostname qmail-queue-handlers[20722]: call_handlers: call executable = '/var/qmail//handlers/info/1postgrey_1/executable'
Aug 27 22:19:43 hostname postgrey[20414]: 07612e03fca68ca0fedb4650d36559cc: action=greylist, reason=new, client_name=example.com, client_address=XX.XX.XXX.XX, sender=localpart@example.com, recipient=recipient@domain1.tld
Aug 27 22:19:43 hostname qmail-queue-handlers[20722]: handlers_stderr: DEFER
Aug 27 22:19:43 hostname qmail-queue-handlers[20722]: call_handlers: DEFER during call '/var/qmail//handlers/info/1postgrey_1/executable' handler
Aug 27 22:19:43 hostname qmail-queue-handlers[20722]: call_handlers: stop call handlers because handler '1postgrey_1' not PASS (61)
Aug 27 22:19:43 hostname qmail-queue-handlers[20722]: call_handlers: stop call handlers from dir '/var/qmail//handlers/before-queue/recipient-domain/domain1.tld'
Beim zweiten Einlieferungsversuch ist der einliefernde Host schon bekannt und postgrey gibt sein OK für die Mailzustellung. Danach wird der policyd-weight befragt, welcher ebenfalls sein OK gibt.

Code: Select all

Aug 27 22:39:56 hostname qmail-queue-handlers[20835]: Handlers Filter before-queue for qmail started ...
Aug 27 22:39:56 hostname qmail-queue-handlers[20835]: from=localpart@example.com
Aug 27 22:39:56 hostname qmail-queue-handlers[20835]: to=recipient@domain1.tld
Aug 27 22:39:56 hostname qmail-queue-handlers[20835]: hook_dir = '/var/qmail//handlers/before-queue'
Aug 27 22:39:56 hostname qmail-queue-handlers[20835]: recipient[3] = 'recipient@domain1.tld'
Aug 27 22:39:56 hostname qmail-queue-handlers[20835]: handlers dir = '/var/qmail//handlers/before-queue/recipient/recipient@domain1.tld'
Aug 27 22:39:56 hostname qmail-queue-handlers[20835]: found handlers entry = '/var/qmail//handlers/before-queue/recipient-domain/domain1.tld/1postgrey_1'
Aug 27 22:39:56 hostname qmail-queue-handlers[20835]: call_handlers: call executable = '/var/qmail//handlers/info/1postgrey_1/executable'
Aug 27 22:39:57 hostname postgrey[20414]: 9048c3ed2cc94db32652663cf4b2a251: action=pass, reason=triplet found, delay=1201, client_name=example.com, client_address=XX.XX.XXX.XX, sender=localpart@example.com, recipient=recipient@domain1.tld
Aug 27 22:39:57 hostname qmail-queue-handlers[20835]: handlers_stderr: PASS
Aug 27 22:39:57 hostname qmail-queue-handlers[20835]: found handlers entry = '/var/qmail//handlers/before-queue/global/2policy_1'
Aug 27 22:39:57 hostname qmail-queue-handlers[20835]: call_handlers: call executable = '/var/qmail//handlers/info/2policy_1/executable'
Aug 27 22:39:58 hostname postfix/policyd-weight[20640]: weighted check:  NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 HELO_IP_IN_CL_SUBNET=-1.2 (check f
rom: .example. - helo: .. - helo-domain: ..)  FROM/MX_MATCHES_NOT_HELO(DOMAIN)=1; <client=XX.XX.XXX.XX> <helo=> <from=localpart@example.com> <to=recipient@domain1.tld>; rate: -4.7
Aug 27 22:39:58 hostname postfix/policyd-weight[20640]: decided action=PREPEND X-policyd-weight:  NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 HELO_IP_I
N_CL_SUBNET=-1.2 (check from: .example. - helo: .. - helo-domain: ..)  FROM/MX_MATCHES_NOT_HELO(DOMAIN)=1; rate: -4.7; <client=XX.XX.XXX.XX> <helo=> <from=localpart@example.com> <to=recipient@domain1.tld>; delay: 1s
Aug 27 22:39:58 hostname qmail-queue-handlers[20835]: handlers_stderr: PASS
Bei diesem Auszug wird einem Mail von localpart@example.com an recipient@domain.tld geschickt. postgrey wurde für domain.tld nicht eingerichtet, weshalb hier nur policyd-weight befragt wird.

Code: Select all

Aug 27 22:22:45 hostname qmail-queue-handlers[20758]: Handlers Filter before-queue for qmail started ...
Aug 27 22:22:45 hostname qmail-queue-handlers[20758]: from=localpart@example.com
Aug 27 22:22:45 hostname qmail-queue-handlers[20758]: to=recipient@domain.tld
Aug 27 22:22:45 hostname qmail-queue-handlers[20758]: hook_dir = '/var/qmail//handlers/before-queue'
Aug 27 22:22:45 hostname qmail-queue-handlers[20758]: recipient[3] = 'recipient@domain.tld'
Aug 27 22:22:45 hostname qmail-queue-handlers[20758]: handlers dir = '/var/qmail//handlers/before-queue/recipient/recipient@domain.tld'
Aug 27 22:22:45 hostname qmail-queue-handlers[20758]: found handlers entry = '/var/qmail//handlers/before-queue/global/2policy_1'
Aug 27 22:22:45 hostname qmail-queue-handlers[20758]: call_handlers: call executable = '/var/qmail//handlers/info/2policy_1/executable'
Aug 27 22:22:45 hostname postfix/policyd-weight[20640]: decided action=PREPEND X-policyd-weight: using cached result; rate: -7.6; <client=XX.XX.XXX.XX> <helo=> <from=localpart@example.com> <to=recipient@domain.tld>; delay: 0s
Aug 27 22:22:45 hostname qmail-queue-handlers[20758]: handlers_stderr: PASS