xref: /netbsd-src/external/ibm-public/postfix/dist/proto/POSTSCREEN_README.html (revision 4ac76180e904e771b9d522c7e57296d371f06499)
1<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"
2        "http://www.w3.org/TR/html4/loose.dtd">
3
4<head>
5
6<title>Postfix Postscreen Howto</title>
7
8<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
9
10</head>
11
12<body>
13
14<h1><img src="postfix-logo.jpg" width="203" height="98" ALT="">Postfix Postscreen Howto</h1>
15
16<hr>
17
18<h2> <a name="intro">Introduction</a> </h2>
19
20<p> This document describes features that are available in Postfix
213.6 and later. See <a href="POSTSCREEN_3_5_README.html">
22POSTSCREEN_3_5_README.html</a> for Postfix versions 2.8 - 3.5. </p>
23
24<p> The Postfix postscreen(8) daemon provides additional protection
25against mail server overload. One postscreen(8) process handles
26multiple inbound SMTP connections, and decides which clients may
27talk to a Postfix SMTP server process.  By keeping spambots away,
28postscreen(8) leaves more SMTP server processes available for
29legitimate clients, and delays the onset of <a
30href="STRESS_README.html">server overload</a> conditions. </p>
31
32<p> postscreen(8) should not be used on SMTP ports that receive
33mail from end-user clients (MUAs). In a typical deployment,
34postscreen(8) handles the MX service on TCP port 25, while MUA
35clients submit mail via the submission service on TCP port 587 which
36requires client authentication. Alternatively, a site could set up
37a dedicated, non-postscreen, "port 25" server that provides submission
38service and client authentication, but no MX service.  </p>
39
40<p> postscreen(8) maintains a temporary allowlist for clients that
41pass its tests; by allowing allowlisted clients to skip tests,
42postscreen(8) minimizes its impact on legitimate email traffic.
43</p>
44
45<p> postscreen(8) is part of a multi-layer defense. <p>
46
47<ul>
48
49<li> <p> As the first layer, postscreen(8) blocks connections from
50zombies and other spambots that are responsible for about 90% of
51all spam.  It is implemented as a single process to make this defense
52as inexpensive as possible. </p>
53
54<li> <p> The second layer implements more complex SMTP-level access
55checks with <a href="SMTPD_ACCESS_README.html">Postfix SMTP servers</a>,
56<a href="SMTPD_POLICY_README.html">policy daemons</a>, and
57<a href="MILTER_README.html">Milter applications</a>. </p>
58
59<li> <p> The third layer performs light-weight content inspection
60with the Postfix built-in header_checks and body_checks. This can
61block unacceptable attachments such as executable programs, and
62worms or viruses with easy-to-recognize signatures. </p>
63
64<li> <p> The fourth layer provides heavy-weight content inspection
65with external content filters. Typical examples are <a
66href="http://www.ijs.si/software/amavisd/">Amavisd-new</a>, <a
67href="http://spamassassin.apache.org/">SpamAssassin</a>, and <a
68href="MILTER_README.html">Milter applications</a>. </p>
69
70</ul>
71
72<p> Each layer reduces the spam volume. The general strategy is to
73use the less expensive defenses first, and to use the more expensive
74defenses only for the spam that remains. </p>
75
76<p> Topics in this document: </p>
77
78<ul>
79
80<li> <a href="#intro">Introduction</a>
81
82<li> <a href="#basic">The basic idea behind postscreen(8)</a>
83
84<li> <a href="#general"> General operation </a>
85
86<li> <a href="#quick">Quick tests before everything else</a>
87
88<li> <a href="#before_220"> Tests before the 220 SMTP server greeting </a>
89
90<li> <a href="#after_220">Tests after the 220 SMTP server greeting</a>
91
92<li> <a href="#other_error">Other errors</a>
93
94<li> <a href="#victory">When all tests succeed</a>
95
96<li> <a href="#config"> Configuring the postscreen(8) service</a>
97
98<li> <a href="#historical"> Historical notes and credits </a>
99
100</ul>
101
102<h2> <a name="basic">The basic idea behind postscreen(8)</a> </h2>
103
104<p> Most email is spam, and most spam is sent out by zombies (malware
105on compromised end-user computers).  Wietse expects that the zombie
106problem will get worse before things improve, if ever. Without a
107tool like postscreen(8) that keeps the zombies away, Postfix would be
108spending most of its resources not receiving email. </p>
109
110<p> The main challenge for postscreen(8) is to make an is-a-zombie
111decision based on a single measurement. This is necessary because
112many zombies try to fly under the radar and avoid spamming the same
113site repeatedly.  Once postscreen(8) decides that a client is
114not-a-zombie, it allowlists the client temporarily to avoid further
115delays for legitimate mail. </p>
116
117<p> Zombies have challenges too: they have only a limited amount
118of time to deliver spam before their IP address becomes denylisted.
119To speed up spam deliveries, zombies make compromises in their SMTP
120protocol implementation.  For example, they speak before their turn,
121or they ignore responses from SMTP servers and continue sending
122mail even when the server tells them to go away. </p>
123
124<p> postscreen(8) uses a variety of measurements to recognize
125zombies.  First, postscreen(8) determines if the remote SMTP client
126IP address is denylisted.  Second, postscreen(8) looks for protocol
127compromises that are made to speed up delivery.  These are good
128indicators for making is-a-zombie decisions based on single
129measurements.  </p>
130
131<p> postscreen(8) does not inspect message content. Message content
132can vary from one delivery to the next, especially with clients
133that (also) send legitimate email.  Content is not a good indicator
134for making is-a-zombie decisions based on single measurements,
135and that is the problem that postscreen(8) is focused on.  </p>
136
137<h2> <a name="general"> General operation </a> </h2>
138
139<p> For each connection from an SMTP client, postscreen(8) performs
140a number of tests
141in the order as described below.  Some tests introduce a delay of
142a few seconds.  postscreen(8) maintains a temporary allowlist for
143clients that pass its tests; by allowing allowlisted clients to
144skip tests, postscreen(8) minimizes its impact on legitimate email
145traffic.  </p>
146
147<p> By default, postscreen(8) hands off all connections to a Postfix
148SMTP server process after logging its findings. This mode is useful
149for non-destructive testing. </p>
150
151<p> In a typical production setting, postscreen(8) is configured
152to reject mail from clients that fail one or more tests, after
153logging the helo, sender and recipient information. </p>
154
155<p> Note: postscreen(8) is not an SMTP proxy; this is intentional.
156The purpose is to keep zombies away from Postfix, with minimal
157overhead for legitimate clients. </p>
158
159<h2> <a name="quick">Quick tests before everything else</a> </h2>
160
161<p> Before engaging in SMTP-level tests. postscreen(8) queries a
162number of local deny and allowlists. These tests speed up the
163handling of known clients. </p>
164
165<ul>
166
167<li> <a href="#perm_allow_deny"> Permanent allow/denylist test </a>
168
169<li> <a href="#temp_allow"> Temporary allowlist test </a>
170
171<li> <a href="#allow_veto"> MX Policy test </a>
172
173</ul>
174
175<h3> <a name="perm_allow_deny"> Permanent allow/denylist test </a> </h3>
176
177<p> The postscreen_access_list parameter (default: permit_mynetworks)
178specifies a permanent access list for SMTP client IP addresses. Typically
179one would specify something that allowlists local networks, followed
180by a CIDR table for selective allow- and denylisting. </p>
181
182<p> Example: </p>
183
184<pre>
185/etc/postfix/main.cf:
186    postscreen_access_list = permit_mynetworks,
187        cidr:/etc/postfix/postscreen_access.cidr
188
189/etc/postfix/postscreen_access.cidr:
190   # Rules are evaluated in the order as specified.
191   # Denylist 192.168.* except 192.168.0.1.
192   192.168.0.1          permit
193   192.168.0.0/16       reject
194</pre>
195
196<p> See the postscreen_access_list manpage documentation for more
197details.  </p>
198
199<p> When the SMTP client address matches a "permit" action,
200postscreen(8) logs this with the client address and port number as:
201</p>
202
203<blockquote>
204<pre>
205<b>ALLOWLISTED</b> <i>[address]:port</i>
206</pre>
207</blockquote>
208
209<blockquote> <p> Use the respectful_logging configuration parameter to
210select a deprecated form of this logging. </p> </blockquote>
211
212<p> The allowlist action is not configurable: immediately hand off the
213connection to a Postfix SMTP server process. </p>
214
215<p> When the SMTP client address matches a "reject" action,
216postscreen(8) logs this with the client address and port number as:
217</p>
218
219<blockquote>
220<pre>
221<b>DENYLISTED</b> <i>[address]:port</i>
222</pre>
223</blockquote>
224
225<blockquote> <p> Use the respectful_logging configuration parameter to
226select a deprecated form of this logging. </p> </blockquote>
227
228<p> The postscreen_denylist_action parameter specifies the action
229that is taken next.  See "<a href="#fail_before_220">When tests
230fail before the 220 SMTP server greeting</a>" below. </p>
231
232<h3> <a name="temp_allow"> Temporary allowlist test </a> </h3>
233
234<p> The postscreen(8) daemon maintains a <i>temporary</i>
235allowlist for SMTP client IP addresses that have passed all
236the tests described below. The postscreen_cache_map parameter
237specifies the location of the temporary allowlist.  The
238temporary allowlist is not used for SMTP client addresses
239that appear on the <i>permanent</i> access list. </p>
240
241<p> By default the temporary allowlist is not shared with other
242postscreen(8) daemons. See
243<a href="#temp_allow_sharing"> Sharing
244the temporary allowlist </a> below for alternatives. </p>
245
246<p> When the SMTP client address appears on the temporary
247allowlist, postscreen(8) logs this with the client address and port
248number as: </p>
249
250<pre>
251    <b>PASS OLD</b> <i>[address]:port</i>
252</pre>
253
254<p> The action is not configurable: immediately hand off the
255connection to a Postfix SMTP server process.  The client is
256excluded from further tests until its temporary allowlist
257entry expires, as controlled with the postscreen_*_ttl
258parameters.  Expired entries are silently renewed if possible. </p>
259
260<h3> <a name="allow_veto"> MX Policy test </a> </h3>
261
262<p> When the remote SMTP client is not on the static access list
263or temporary allowlist, postscreen(8) can implement a number of
264allowlist tests, before it grants the client a temporary allowlist
265status that allows it to talk to a Postfix SMTP server process. </p>
266
267<p> When postscreen(8) is configured to monitor all primary and
268backup MX addresses, it can refuse to allowlist clients that connect
269to a backup MX address only (an old spammer trick to take advantage
270of backup MX hosts with weaker anti-spam policies than primary MX
271hosts). </p>
272
273<blockquote> <p> NOTE: The following solution is for small sites.
274Larger sites would have to share the postscreen(8) cache between
275primary and backup MTAs, which would introduce a common point of
276failure.  </p> </blockquote>
277
278<ul>
279
280<li> <p> First, configure the host to listen on both primary and
281backup MX addresses. Use the appropriate <tt>ifconfig</tt> or <tt>ip</tt>
282command for the local operating system, or update the appropriate
283configuration files and "refresh" the network protocol stack. </p>
284
285<p> <p> Second, configure Postfix to listen on the new IP address
286(this step is needed when you have specified inet_interfaces in
287main.cf). </p>
288
289<li> <p> Then, configure postscreen(8) to deny the temporary allowlist
290status on the backup MX address(es).  An example for Wietse's
291server is: </p>
292
293<pre>
294/etc/postfix/main.cf:
295    postscreen_allowlist_interfaces = !168.100.189.8 static:all
296</pre>
297
298<p> Translation: allow clients to obtain the temporary allowlist
299status on all server IP addresses except 168.100.189.8, which is a
300backup MX address.  </p>
301
302</ul>
303
304<p> When a non-allowlisted client connects the backup MX address,
305postscreen(8) logs this with the client address and port number as:
306</p>
307
308<blockquote> <pre>
309<b>CONNECT from</b> <i>[address]:port</i> <b>to [168.100.189.8]:25</b>
310<b>ALLOWLIST VETO</b> <i>[address]:port</i>
311</pre> </blockquote>
312
313<blockquote> <p> Use the respectful_logging configuration parameter to
314select a deprecated form of this logging. </p> </blockquote>
315
316<p> Translation: the client at <i>[address]:port</i> connected to
317the backup MX address 168.100.189.8 while it was not allowlisted.
318The client will not be granted the temporary allowlist status, even
319if passes all the allowlist tests described below. </p>
320
321<h2> <a name="before_220"> Tests before the 220 SMTP server greeting </a> </h2>
322
323<p> The postscreen_greet_wait parameter specifies a short time
324interval before the "220 <i>text</i>..." server greeting, where
325postscreen(8) can run a number of tests in parallel. </p>
326
327<p> When a good client passes these tests, and no "<a
328href="#after_220">deep protocol tests</a>"
329are configured, postscreen(8)
330adds the client to the temporary allowlist and hands off the "live"
331connection to a Postfix SMTP server process.  The client can then
332continue as if postscreen(8) never even existed (except of course
333for the short postscreen_greet_wait delay).  </p>
334
335<ul>
336
337<li> <a href="#pregreet"> Pregreet test </a>
338
339<li> <a href="#dnsbl"> DNS Allow/denylist test </a>
340
341<li> <a href="#fail_before_220">When tests fail before the 220 SMTP server greeting</a>
342
343</ul>
344
345<h3> <a name="pregreet"> Pregreet test </a> </h3>
346
347<p> The SMTP protocol is a classic example of a protocol where the
348server speaks before the client. postscreen(8) detects zombies
349that are in a hurry and that speak before their turn. This test is
350enabled by default. </p>
351
352<p> The postscreen_greet_banner parameter specifies the <i>text</i>
353portion of a "220-<i>text</i>..." teaser banner (default: $smtpd_banner).
354Note that this becomes the first part of a multi-line server greeting.
355The postscreen(8) daemon sends this before the postscreen_greet_wait
356timer is started.  The purpose of the teaser banner is to confuse
357zombies so that they speak before their turn. It has no effect on
358SMTP clients that correctly implement the protocol.  </p>
359
360<p> To avoid problems with poorly-implemented SMTP engines in network
361appliances or network testing tools, either exclude them from all
362tests with the postscreen_access_list feature or else specify
363an empty teaser banner: </p>
364
365<pre>
366/etc/postfix/main.cf:
367    # Exclude broken clients by allowlisting. Clients in mynetworks
368    # should always be allowlisted.
369    postscreen_access_list = permit_mynetworks,
370        cidr:/etc/postfix/postscreen_access.cidr
371
372/etc/postfix/postscreen_access.cidr:
373    192.168.254.0/24 permit
374</pre>
375
376<pre>
377/etc/postfix/main.cf:
378    # Disable the teaser banner (try allowlisting first if you can).
379    postscreen_greet_banner =
380</pre>
381
382<p> When an SMTP client sends a command before the
383postscreen_greet_wait time has elapsed, postscreen(8) logs this as:
384</p>
385
386<pre>
387    <b>PREGREET</b> <i>count</i> <b>after</b> <i>time</i> <b>from</b> <i>[address]:port text...</i>
388</pre>
389
390<p> Translation: the client at <i>[address]:port</i> sent <i>count</i>
391bytes before its turn to speak. This happened <i>time</i> seconds
392after the postscreen_greet_wait timer was started.  The <i>text</i>
393is what the client sent (truncated to 100 bytes, and with non-printable
394characters replaced with C-style escapes such as \r for carriage-return
395and \n for newline). </p>
396
397<p> The postscreen_greet_action parameter specifies the action that
398is taken next.  See "<a href="#fail_before_220">When tests fail
399before the 220 SMTP server greeting</a>" below. </p>
400
401<h3> <a name="dnsbl"> DNS Allow/denylist test </a> </h3>
402
403<p> The postscreen_dnsbl_sites parameter (default: empty) specifies
404a list of DNS blocklist servers with optional filters and weight
405factors (positive weights for denylisting, negative for allowlisting).
406These servers will be queried in parallel with the reverse client
407IP address.  This test is disabled by default. </p>
408
409<blockquote>
410<p>
411CAUTION: when postscreen rejects mail, its SMTP reply contains the
412DNSBL domain name. Use the postscreen_dnsbl_reply_map feature to
413hide "password" information in DNSBL domain names.
414</p>
415</blockquote>
416
417<p> When the postscreen_greet_wait time has elapsed, and the combined
418DNSBL score is equal to or greater than the postscreen_dnsbl_threshold
419parameter value, postscreen(8) logs this as: </p>
420
421<pre>
422    <b>DNSBL rank</b> <i>count</i> <b>for</b> <i>[address]:port</i>
423</pre>
424
425<p> Translation: the SMTP client at <i>[address]:port</i> has a combined
426DNSBL score of <i>count</i>. </p>
427
428<p> The postscreen_dnsbl_action parameter specifies the action that
429is taken when the combined DNSBL score is equal to or greater than
430the threshold.  See "<a href="#fail_before_220">When tests fail
431before the 220 SMTP server greeting</a>" below. </p>
432
433<h3> <a name="fail_before_220">When tests fail before the 220 SMTP server greeting</a> </h3>
434
435<p> When the client address matches the permanent denylist, or
436when the client fails the pregreet or DNSBL tests, the action is
437specified with postscreen_denylist_action, postscreen_greet_action,
438or postscreen_dnsbl_action, respectively. </p>
439
440<dl>
441
442<dt> <b>ignore</b> (default) </dt>
443
444<dd> Ignore the failure of this test. Allow other tests to complete.
445Repeat this test the next time the client connects.  This option
446is useful for testing and collecting statistics without blocking
447mail. </dd>
448
449<dt> <b>enforce</b> </dt>
450
451<dd> Allow other tests to complete.  Reject attempts to deliver mail
452with a 550 SMTP reply, and log the helo/sender/recipient information.
453Repeat this test the next time the client connects. </dd>
454
455<dt> <b>drop</b> </dt>
456
457<dd> Drop the connection immediately with a 521 SMTP reply.  Repeat
458this test the next time the client connects. </dd>
459
460</dl>
461
462<h2> <a name="after_220">Tests after the 220 SMTP server greeting</a> </h2>
463
464<p> In this phase of the protocol, postscreen(8) implements a
465number of "deep protocol" tests. These tests use an SMTP protocol
466engine that is built into the postscreen(8) server. </p>
467
468<p> Important note: these protocol tests are disabled by default.
469They are more intrusive than the pregreet and DNSBL tests, and they
470have limitations as discussed next. </p>
471
472<ul>
473
474<li> <p> The main limitation of "after 220 greeting" tests is that
475a new client must disconnect after passing these tests (reason:
476postscreen is not a proxy).  Then the client must reconnect from
477the same IP address before it can deliver mail.  The following
478measures may help to avoid email delays: </p>
479
480<ul>
481
482<li> <p> Allow "good" clients to skip tests with the
483postscreen_dnsbl_allowlist_threshold feature. This is especially effective
484for large providers that usually don't retry from the same IP
485address. </p>
486
487<li> <p> Small sites: Configure postscreen(8) to listen on multiple
488IP addresses, published in DNS as different IP addresses for the
489same MX hostname or for different MX hostnames. This avoids mail
490delivery delays with clients that reconnect immediately from the
491same IP address.  </p>
492
493<li> <p> Large sites: Share the postscreen(8) cache between different
494Postfix MTAs with a large-enough memcache_table(5). Again, this
495avoids mail delivery delays with clients that reconnect immediately
496from the same IP address. </p>
497
498</ul>
499
500<li> <p> postscreen(8)'s built-in SMTP engine does not implement the
501AUTH, XCLIENT, and XFORWARD features. If you need to make these
502services available on port 25, then do not enable the tests after
503the 220 server greeting. </p>
504
505<li> <p> End-user clients should connect directly to the submission
506service, so that they never have to deal with postscreen(8)'s tests.
507</p>
508
509</ul>
510
511<p> The following "after 220 greeting" tests are available: </p>
512
513<ul>
514
515<li> <a href="#pipelining">Command pipelining test</a>
516
517<li> <a href="#non_smtp">Non-SMTP command test</a>
518
519<li> <a href="#barelf">Bare newline test</a>
520
521<li> <a href="#fail_after_220">When tests fail after the 220 SMTP server greeting</a>
522
523</ul>
524
525<h3> <a name="pipelining">Command pipelining test</a> </h3>
526
527<p> By default, SMTP is a half-duplex protocol: the sender and
528receiver send one command and one response at a time.  Unlike the
529Postfix SMTP server, postscreen(8) does not announce support
530for ESMTP command pipelining.  Therefore, clients are not allowed
531to send multiple commands. postscreen(8)'s
532<a href="#after_220">deep
533protocol test</a> for this is disabled by default. </p>
534
535<p> With "postscreen_pipelining_enable = yes", postscreen(8) detects
536zombies that send multiple commands, instead of sending one command
537and waiting for the server to reply.  </p>
538
539<p> This test is opportunistically enabled when postscreen(8) has
540to use the built-in SMTP engine anyway. This is to make postscreen(8)
541logging more informative. </p>
542
543<p> When a client sends multiple commands, postscreen(8) logs this
544as: </p>
545
546<pre>
547    <b>COMMAND PIPELINING from</b> <i>[address]:port</i> <b>after</b> <i>command</i>: <i>text</i>
548</pre>
549
550<p> Translation: the SMTP client at <i>[address]:port</i> sent
551multiple SMTP commands, instead of sending one command and then
552waiting for the server to reply. This happened after the client
553sent <i>command</i>. The <i>text</i> shows part of the input that
554was sent too early; it is not logged with Postfix 2.8. </p>
555
556<p> The postscreen_pipelining_action parameter specifies the action
557that is taken next.  See "<a href="#fail_after_220">When tests fail
558after the 220 SMTP server greeting</a>" below. </p>
559
560<h3> <a name="non_smtp">Non-SMTP command test</a> </h3>
561
562<p> Some spambots send their mail through open proxies. A symptom
563of this is the usage of commands such as CONNECT and other non-SMTP
564commands. Just like the Postfix SMTP server's smtpd_forbidden_commands
565feature, postscreen(8) has an equivalent postscreen_forbidden_commands
566feature to block these clients. postscreen(8)'s
567<a href="#after_220">deep
568protocol test</a> for this is disabled by default.  </p>
569
570<p> With "postscreen_non_smtp_command_enable = yes", postscreen(8)
571detects zombies that send commands specified with the
572postscreen_forbidden_commands parameter. This also detects commands
573with the syntax of a message header label. The latter is a symptom
574that the client is sending message content after ignoring all the
575responses from postscreen(8) that reject mail. </p>
576
577<p> This test is opportunistically enabled when postscreen(8) has
578to use the built-in SMTP engine anyway. This is to make postscreen(8)
579logging more informative.  </p>
580
581<p> When a client sends non-SMTP commands, postscreen(8) logs this
582as: </p>
583
584<pre>
585    <b>NON-SMTP COMMAND from</b> <i>[address]:port</i> <b>after</b> <i>command: text</i>
586</pre>
587
588<p> Translation: the SMTP client at <i>[address]:port</i> sent a
589command that matches the postscreen_forbidden_commands
590parameter, or that has the syntax of a message header label (text
591followed by optional space and ":").
592The "<tt><b>after</b> <i>command</i></tt>" portion is logged with
593Postfix 2.10 and later. </p>
594
595<p> The postscreen_non_smtp_command_action parameter specifies
596the action that is taken next.  See "<a href="#fail_after_220">When
597tests fail after the 220 SMTP server greeting</a>" below. </p>
598
599<h3> <a name="barelf">Bare newline test</a> </h3>
600
601<p> SMTP is a line-oriented protocol: lines have a limited length,
602and are terminated with &lt;CR&gt;&lt;LF&gt;. Lines ending in a
603"bare" &lt;LF&gt;, that is newline not preceded by carriage return,
604are not allowed in SMTP.  postscreen(8)'s
605<a href="#after_220">deep
606protocol test</a> for this is disabled by default.  </p>
607
608<p> With "postscreen_bare_newline_enable = yes", postscreen(8)
609detects clients that send lines ending in bare newline characters.
610</p>
611
612<p> This test is opportunistically enabled when postscreen(8) has
613to use the built-in SMTP engine anyway. This is to make postscreen(8)
614logging more informative.  </p>
615
616<p> When a client sends bare newline characters, postscreen(8) logs
617this as:
618</p>
619
620<pre>
621    <b>BARE NEWLINE from</b> <i>[address]:port</i> <b>after</b> <i>command</i>
622</pre>
623
624<p> Translation: the SMTP client at <i>[address]:port</i> sent a bare
625newline character, that is newline not preceded by carriage
626return.
627The "<tt><b>after</b> <i>command</i></tt>" portion is logged with
628Postfix 2.10 and later. </p>
629
630<p> The postscreen_bare_newline_action parameter specifies the
631action that is taken next.  See "<a href="#fail_after_220">When
632tests fail after the 220 SMTP server greeting</a>" below. </p>
633
634<h3> <a name="fail_after_220">When tests fail after the 220 SMTP server greeting</a> </h3>
635
636<p> When the client fails the pipelining, non-SMTP command or bare
637newline tests, the action is specified with postscreen_pipelining_action,
638postscreen_non_smtp_command_action or postscreen_bare_newline_action,
639respectively. </p>
640
641<dl>
642
643<dt> <b>ignore</b> (default for bare newline) </dt>
644
645<dd> Ignore the failure of this test. Allow other tests to complete.
646Do NOT repeat this test before the result from some other test
647expires.
648
649This option is useful for testing and collecting statistics without
650blocking mail permanently. </dd>
651
652<dt> <b>enforce</b> (default for pipelining) </dt>
653
654<dd> Allow other tests to complete.  Reject attempts to deliver
655mail with a 550 SMTP reply, and log the helo/sender/recipient
656information.  Repeat this test the next time the client connects.
657</dd>
658
659<dt> <b>drop</b> (default for non-SMTP commands) </dt>
660
661<dd> Drop the connection immediately with a 521 SMTP reply.  Repeat
662this test the next time the client connects.  This action is
663compatible with the Postfix SMTP server's smtpd_forbidden_commands
664feature. </dd>
665
666</dl>
667
668<h2> <a name="other_error">Other errors</a> </h2>
669
670<p> When an SMTP client hangs up unexpectedly, postscreen(8) logs
671this as: </p>
672
673<pre>
674    <b>HANGUP after</b> <i>time</i> <b>from</b> <i>[address]:port</i> <b>in</b> <i>test name</i>
675</pre>
676
677<p> Translation: the SMTP client at <i>[address]:port</i> disconnected
678unexpectedly, <i>time</i> seconds after the start of the
679test named <i>test name</i>. </p>
680
681<p> There is no punishment for hanging up. A client that hangs up
682without sending the QUIT command can still pass all postscreen(8)
683tests. </p>
684
685<!--
686
687<p> While an unexpired penalty is in effect, an SMTP client is not
688allowed to pass any tests, and  postscreen(8) logs each connection
689with the remaining amount of penalty time as: </p>
690
691<pre>
692    <b>PENALTY</b> <i>time</i> <b>for</b> <i>[address]:port</i>
693</pre>
694
695<p> During this time, all attempts by the client to deliver mail
696will be deferred with a 450 SMTP status.  </p>
697
698-->
699
700<p> The following errors are reported by the built-in SMTP engine.
701This engine never accepts mail, therefore it has per-session limits
702on the number of commands and on the session length. </p>
703
704<pre>
705    <b>COMMAND TIME LIMIT</b> <b>from</b> <i>[address]:port</i> <b>after</b> <i>command</i>
706</pre>
707
708<p> Translation: the SMTP client at <i>[address]:port</i> reached the
709per-command time limit as specified with the postscreen_command_time_limit
710parameter.  The session is terminated immediately.
711The "<tt><b>after</b> <i>command</i></tt>" portion is logged with
712Postfix 2.10 and later. </p>
713
714<pre>
715    <b>COMMAND COUNT LIMIT from</b> <i>[address]:port</i> <b>after</b> <i>command</i>
716</pre>
717
718<p> Translation: the SMTP client at <i>[address]:port</i> reached the
719per-session command count limit as specified with the
720postscreen_command_count_limit parameter.  The session is terminated
721immediately.
722The "<tt><b>after</b> <i>command</i></tt>" portion is logged with
723Postfix 2.10 and later. </p>
724
725<pre>
726    <b>COMMAND LENGTH LIMIT from</b> <i>[address]:port</i> <b>after</b> <i>command</i>
727</pre>
728
729<p> Translation: the SMTP client at <i>[address]:port</i> reached the
730per-command length limit, as specified with the line_length_limit
731parameter.  The session is terminated immediately.
732The "<tt><b>after</b> <i>command</i></tt>" portion is logged with
733Postfix 2.10 and later. </p>
734
735<p> When an SMTP client makes too many connections at the same time,
736postscreen(8) rejects the connection with a 421 status code and logs: </p>
737
738<pre>
739    <b>NOQUEUE: reject: CONNECT from</b> <i>[address]:port</i><b>: too many connections</b>
740</pre>
741
742<p> The postscreen_client_connection_count_limit parameter controls this limit. </p>
743
744<p> When an SMTP client connects after postscreen(8) has reached a
745connection count limit, postscreen(8) rejects the connection with
746a 421 status code and logs: </p>
747
748<pre>
749    <b>NOQUEUE: reject: CONNECT from</b> <i>[address]:port</i><b>: all screening ports busy</b>
750    <b>NOQUEUE: reject: CONNECT from</b> <i>[address]:port</i><b>: all server ports busy</b>
751</pre>
752
753<p> The postscreen_pre_queue_limit and postscreen_post_queue_limit
754parameters control these limits.  </p>
755
756<h2> <a name="victory">When all tests succeed</a> </h2>
757
758<p> When a new SMTP client passes all tests (i.e. it is not allowlisted
759via some mechanism), postscreen(8) logs this as: </p>
760
761<pre>
762    <b>PASS NEW</b> <i>[address]:port</i>
763</pre>
764
765<p> Where <i>[address]:port</i> are the client IP address and port.
766Then, postscreen(8)
767creates a temporary allowlist entry that excludes the client IP
768address from further tests until the temporary allowlist entry
769expires, as controlled with the postscreen_*_ttl parameters. </p>
770
771<p> When no "<a href="#after_220">deep protocol tests</a>" are
772configured, postscreen(8) hands off the "live" connection to a Postfix
773SMTP server process.  The client can then continue as if postscreen(8)
774never even existed (except for the short postscreen_greet_wait delay).
775</p>
776
777<p> When any "<a href="#after_220">deep protocol tests</a>" are
778configured, postscreen(8) cannot hand off the "live" connection to
779a Postfix SMTP server process in the middle of the session.  Instead,
780postscreen(8) defers mail delivery attempts with a 4XX status, logs
781the helo/sender/recipient information, and waits for the client to
782disconnect.  The next time the client connects it will be allowed
783to talk to a Postfix SMTP server process to deliver its mail.
784postscreen(8) mitigates the impact of this limitation by giving
785<a href="#after_220">deep protocol tests</a> a long expiration
786time. </p>
787
788<h2> <a name="config"> Configuring the postscreen(8) service</a>
789</h2>
790
791<p> postscreen(8) has been tested on FreeBSD [4-8], Linux 2.[4-6]
792and Solaris 9 systems. </p>
793
794<ul>
795
796<li> <a href="#enable"> Turning on postscreen(8) without blocking
797mail</a>
798
799<li> <a href="#starttls"> postscreen(8) TLS configuration </a>
800
801<li> <a href="#blocking"> Blocking mail with postscreen(8) </a>
802
803<li> <a href="#turnoff"> Turning off postscreen(8) </a>
804
805<li> <a href="#temp_allow_sharing"> Sharing the temporary allowlist
806</a>
807
808</ul>
809
810<h3> <a name="enable"> Turning on postscreen(8) without blocking mail</a> </h3>
811
812<p> To enable the postscreen(8) service and log client information
813without blocking mail: </p>
814
815<ol>
816
817<li> <p> Make sure that local clients and systems with non-standard
818SMTP implementations are excluded from any postscreen(8) tests. The
819default is to exclude all clients in mynetworks. To exclude additional
820clients, for example, third-party performance monitoring tools (these
821tend to have broken SMTP implementations): </p>
822
823<pre>
824/etc/postfix/main.cf:
825    # Exclude broken clients by allowlisting. Clients in mynetworks
826    # should always be allowlisted.
827    postscreen_access_list = permit_mynetworks,
828        cidr:/etc/postfix/postscreen_access.cidr
829
830/etc/postfix/postscreen_access.cidr:
831    192.168.254.0/24 permit
832</pre>
833
834<li> <p> Comment out the "<tt>smtp  inet ... smtpd</tt>" service
835in master.cf, including any "<tt>-o parameter=value</tt>" entries
836that follow.  </p>
837
838<pre>
839/etc/postfix/master.cf:
840    #smtp      inet  n       -       n       -       -       smtpd
841    #    -o parameter=value ...
842</pre>
843
844<li> <p> Uncomment the new "<tt>smtpd pass ... smtpd</tt>" service
845in master.cf, and duplicate any "<tt>-o parameter=value</tt>" entries
846from the smtpd service that was commented out in the previous step.
847</p>
848
849<pre>
850/etc/postfix/master.cf:
851    smtpd     pass  -       -       n       -       -       smtpd
852        -o parameter=value ...
853</pre>
854
855<li> <p> Uncomment the new "<tt>smtp inet ... postscreen</tt>"
856service in master.cf. </p>
857
858<pre>
859/etc/postfix/master.cf:
860    smtp      inet  n       -       n       -       1       postscreen
861</pre>
862
863<li> <p> Uncomment the new "<tt>tlsproxy unix ... tlsproxy</tt>"
864service in master.cf.  This service implements STARTTLS support for
865postscreen(8). </p>
866
867<pre>
868/etc/postfix/master.cf:
869    tlsproxy  unix  -       -       n       -       0       tlsproxy
870</pre>
871
872<li> <p> Uncomment the new "<tt>dnsblog  unix ... dnsblog</tt>"
873service in master.cf.  This service does DNSBL lookups for postscreen(8)
874and logs results. </p>
875
876<pre>
877/etc/postfix/master.cf:
878    dnsblog   unix  -       -       n       -       0       dnsblog
879</pre>
880
881<li> <p> To enable DNSBL lookups, list some DNS blocklist sites in
882main.cf, separated by whitespace. Different sites can have different
883weights. For example:
884
885<pre>
886/etc/postfix/main.cf:
887    postscreen_dnsbl_threshold = 2
888    postscreen_dnsbl_sites = zen.spamhaus.org*2
889        bl.spamcop.net*1 b.barracudacentral.org*1
890</pre>
891
892<p> Note: if your DNSBL queries have a "secret" in the domain name,
893you must censor this information from the postscreen(8) SMTP replies.
894For example: </p>
895
896<pre>
897/etc/postfix/main.cf:
898    postscreen_dnsbl_reply_map = texthash:/etc/postfix/dnsbl_reply
899</pre>
900
901<pre>
902/etc/postfix/dnsbl_reply:
903    # Secret DNSBL name           Name in postscreen(8) replies
904    secret.zen.dq.spamhaus.net    zen.spamhaus.org
905</pre>
906
907<p> The texthash: format is similar to hash: except that there is
908no need to run postmap(1) before the file can be used, and that it
909does not detect changes after the file is read. It is new with
910Postfix version 2.8. </p>
911
912<li> <p> Read the new configuration with "<tt>postfix reload</tt>".
913</p>
914
915</ol>
916
917<p> Notes: </p>
918
919<ul>
920
921<li> <p> Some postscreen(8) configuration parameters implement
922stress-dependent behavior. This is supported only when the default
923value is stress-dependent (that is, "postconf -d <i>parametername</i>"
924output shows
925"<i>parametername</i>&nbsp;=&nbsp;${stress?<i>something</i>}${stress:<i>something</i>}" or
926"<i>parametername</i>&nbsp;=&nbsp;${stress?{<i>something</i>}:{<i>something</i>}}").
927Other parameters always evaluate as if the stress value is the empty
928string. </p>
929
930<li> <p> See "<a href="#before_220">Tests before the 220 SMTP server
931greeting</a>" for details about the logging from these
932postscreen(8) tests. </p>
933
934<li> <p> If you run Postfix 2.6 or earlier you must stop and start
935the master daemon ("<tt>postfix stop; postfix start</tt>").  This
936is needed because the Postfix "pass" master service type did not
937work reliably on all systems. </p>
938
939</ul>
940
941<h3> <a name="starttls"> postscreen(8) TLS configuration </a> </h3>
942
943<p> postscreen(8) TLS support is available for remote SMTP clients
944that aren't allowlisted, including clients that need to renew their
945temporary allowlist status.  When a remote SMTP client requests TLS
946service, postscreen(8) invisibly hands off the connection to a
947tlsproxy(8) process. Then, tlsproxy(8) encrypts and decrypts the
948traffic between postscreen(8) and the remote SMTP client. One
949tlsproxy(8) process can handle multiple SMTP sessions. The number
950of tlsproxy(8) processes slowly increases with server load, but it
951should always be much smaller than the number of postscreen(8) TLS
952sessions.  </p>
953
954<p> TLS support for postscreen(8) and tlsproxy(8) uses the same
955parameters as with smtpd(8). We recommend that you keep the relevant
956configuration parameters in main.cf.  If you must specify "-o
957smtpd_mumble=value" parameter overrides in master.cf for a
958postscreen-protected smtpd(8) service, then you should specify those
959same parameter overrides for the postscreen(8) and tlsproxy(8)
960services. </p>
961
962<h3> <a name="blocking"> Blocking mail with postscreen(8) </a> </h3>
963
964<p> For compatibility with smtpd(8), postscreen(8) implements the
965soft_bounce safety feature. This causes Postfix to reject mail with
966a "try again" reply code. </p>
967
968<ul>
969
970<li> <p> To turn this on for all of Postfix, specify "<tt>soft_bounce
971= yes</tt>" in main.cf. </p>
972
973<li> <p> To turn this on for postscreen(8) only, append "<tt>-o
974soft_bounce=yes</tt>" (note: NO SPACES around '=') to the postscreen
975entry in master.cf. <p>
976
977</ul>
978
979<p> Execute "<tt>postfix reload</tt>" to make the change effective. </p>
980
981<p> After testing, do not forget to remove the soft_bounce feature,
982otherwise senders won't receive their non-delivery notification
983until many days later.  </p>
984
985<p> To use the postscreen(8) service to block mail, edit main.cf and
986specify one or more of: </p>
987
988<ul>
989
990<li> <p> "<tt>postscreen_dnsbl_action = enforce</tt>", to reject
991clients that are on DNS blocklists, and to log the helo/sender/recipient
992information. With good DNSBLs this reduces the amount of load on
993Postfix SMTP servers dramatically.  </p>
994
995<li> <p> "<tt>postscreen_greet_action = enforce</tt>", to reject
996clients that talk before their turn, and to log the helo/sender/recipient
997information. This stops over half of all known-to-be illegitimate
998connections to Wietse's mail server. It is backup protection for
999zombies that haven't yet been denylisted. </p>
1000
1001<li> <p> You can also enable "<a href="#after_220">deep protocol
1002tests</a>", but these are more intrusive than the pregreet or DNSBL
1003tests. </p>
1004
1005<p> When a good client passes the "<a href="#after_220">deep
1006protocol tests</a>",
1007postscreen(8) adds the client to the temporary
1008allowlist but it cannot hand off the "live" connection to a Postfix
1009SMTP server process in the middle of the session. Instead, postscreen(8)
1010defers mail delivery attempts with a 4XX status, logs the
1011helo/sender/recipient information, and waits for the client to
1012disconnect. </p>
1013
1014<p> When the good client comes back in a later session, it is allowed
1015to talk directly to a Postfix SMTP server.  See "<a href="#after_220">Tests
1016after the 220 SMTP server greeting</a>" above for limitations with
1017AUTH and other features that clients may need.  </p>
1018
1019<p> An unexpected benefit from "<a href="#after_220">deep protocol
1020tests</a>" is that some "good" clients don't return after the 4XX
1021reply; these clients were not so good after all. </p>
1022
1023<p> Unfortunately, some senders will retry requests from different
1024IP addresses, and may never get allowlisted.  For this reason,
1025Wietse stopped using "<a href="#after_220">deep protocol tests</a>"
1026on his own internet-facing mail server.  </p>
1027
1028<li> <p> There is also support for permanent denylisting and
1029allowlisting; see the description of the postscreen_access_list
1030parameter for details. </p>
1031
1032</ul>
1033
1034<h3> <a name="turnoff"> Turning off postscreen(8) </a> </h3>
1035
1036<p> To turn off postscreen(8) and handle mail directly with Postfix
1037SMTP server processes: </p>
1038
1039<ol>
1040
1041<li> <p> Comment out the "<tt>smtp inet ... postscreen</tt>" service
1042in master.cf, including any "<tt>-o parameter=value</tt>" entries
1043that follow. </p>
1044
1045<pre>
1046/etc/postfix/master.cf:
1047    #smtp      inet  n       -       n       -       1       postscreen
1048    #    -o parameter=value ...
1049</pre>
1050
1051<li> <p> Comment out the "<tt>dnsblog  unix ... dnsblog</tt>" service
1052in master.cf.  </p>
1053
1054<pre>
1055/etc/postfix/master.cf:
1056    #dnsblog   unix  -       -       n       -       0       dnsblog
1057</pre>
1058
1059<li> <p> Comment out the "<tt>smtpd pass ... smtpd</tt>" service
1060in master.cf, including any "<tt>-o parameter=value</tt>" entries
1061that follow. </p>
1062
1063<pre>
1064/etc/postfix/master.cf:
1065    #smtpd     pass  -       -       n       -       -       smtpd
1066    #    -o parameter=value ...
1067</pre>
1068
1069<li> <p> Comment out the "<tt>tlsproxy unix ... tlsproxy</tt>"
1070service in master.cf, including any "<tt>-o parameter=value</tt>"
1071entries that follow. </p>
1072
1073<pre>
1074/etc/postfix/master.cf:
1075    #tlsproxy  unix  -       -       n       -       0       tlsproxy
1076    #    -o parameter=value ...
1077</pre>
1078
1079<li> <p> Uncomment the "<tt>smtp  inet ... smtpd</tt>" service in
1080master.cf, including any "<tt>-o parameter=value</tt>" entries that
1081may follow.  </p>
1082
1083<pre>
1084/etc/postfix/master.cf:
1085    smtp       inet  n       -       n       -       -       smtpd
1086        -o parameter=value ...
1087</pre>
1088
1089<li> <p> Read the new configuration with "<tt>postfix reload</tt>".
1090</p>
1091
1092</ol>
1093
1094<h3> <a name="temp_allow_sharing"> Sharing the temporary allowlist </a> </h3>
1095
1096<p> By default, the temporary allowlist is not shared between
1097multiple postscreen(8) daemons.  To enable sharing, choose one
1098of the following options: </p>
1099
1100<ul>
1101
1102<li> <p> A non-persistent memcache: temporary allowlist can be shared
1103    between postscreen(8) daemons on the same host or different
1104    hosts.  Disable cache cleanup (postscreen_cache_cleanup_interval
1105    = 0) in all postscreen(8) daemons because memcache: has no
1106    first-next API (but see example 4 below for memcache: with
1107    persistent backup). This requires Postfix 2.9 or later. </p>
1108
1109    <pre>
1110    # Example 1: non-persistent memcache: allowlist.
1111    /etc/postfix/main.cf:
1112	postscreen_cache_map = memcache:/etc/postfix/postscreen_cache
1113	postscreen_cache_cleanup_interval = 0
1114
1115    /etc/postfix/postscreen_cache:
1116	memcache = inet:127.0.0.1:11211
1117	key_format = postscreen:%s
1118    </pre>
1119
1120<li> <p>
1121    A persistent lmdb: temporary allowlist can be shared between
1122    postscreen(8) daemons that run under the same master(8) daemon,
1123    or under different master(8) daemons on the same host.  Disable
1124    cache cleanup (postscreen_cache_cleanup_interval = 0) in all
1125    postscreen(8) daemons except one that is responsible for cache
1126    cleanup. This requires Postfix 2.11 or later. </p>
1127
1128    <pre>
1129    # Example 2: persistent lmdb: allowlist.
1130    /etc/postfix/main.cf:
1131	postscreen_cache_map = lmdb:$data_directory/postscreen_cache
1132	# See note 1 below.
1133	# postscreen_cache_cleanup_interval = 0
1134    </pre>
1135
1136<li> <p> Other kinds of persistent temporary allowlist can be shared
1137    only between postscreen(8) daemons that run under the same
1138    master(8) daemon. In this case, temporary allowlist access must
1139    be shared through the proxymap(8) daemon. This requires Postfix
1140    2.9 or later. </p>
1141
1142    <pre>
1143    # Example 3: proxied btree: allowlist.
1144    /etc/postfix/main.cf:
1145	postscreen_cache_map =
1146	    proxy:btree:/var/lib/postfix/postscreen_cache
1147	# See note 1 below.
1148	# postscreen_cache_cleanup_interval = 0
1149
1150    # Example 4: proxied btree: allowlist with memcache: accelerator.
1151    /etc/postfix/main.cf:
1152	postscreen_cache_map = memcache:/etc/postfix/postscreen_cache
1153	proxy_write_maps =
1154	    proxy:btree:/var/lib/postfix/postscreen_cache
1155	    ... other proxied tables ...
1156	# See note 1 below.
1157	# postscreen_cache_cleanup_interval = 0
1158
1159    /etc/postfix/postscreen_cache:
1160	# Note: the $data_directory macro is not defined in this context.
1161	memcache = inet:127.0.0.1:11211
1162	backup = proxy:btree:/var/lib/postfix/postscreen_cache
1163	key_format = postscreen:%s
1164    </pre>
1165
1166    <p> Note 1: disable cache cleanup (postscreen_cache_cleanup_interval
1167    = 0) in all postscreen(8) daemons except one that is responsible
1168    for cache cleanup. </p>
1169
1170    <p> Note 2: postscreen(8) cache sharing via proxymap(8) requires Postfix
1171    2.9 or later; earlier proxymap(8) implementations don't support
1172    cache cleanup.  </p>
1173
1174</ul>
1175
1176<h2> <a name="historical"> Historical notes and credits </a> </h2>
1177
1178<p> Many ideas in postscreen(8) were explored in earlier work by
1179Michael Tokarev, in OpenBSD spamd, and in MailChannels Traffic
1180Control. </p>
1181
1182<p> Wietse threw together a crude prototype with pregreet and dnsbl
1183support in June 2009, because he needed something new for a Mailserver
1184conference presentation in July. Ralf Hildebrandt ran this code on
1185several servers to collect real-world statistics. This version used
1186the dnsblog(8) ad-hoc DNS client program. </p>
1187
1188<p> Wietse needed new material for a LISA conference presentation
1189in November 2010, so he added support for DNSBL weights and filters
1190in August, followed by a major code rewrite, deep protocol tests,
1191helo/sender/recipient logging, and stress-adaptive behavior in
1192September. Ralf Hildebrandt ran this code on several servers to
1193collect real-world statistics. This version still used the embarrassing
1194dnsblog(8) ad-hoc DNS client program.  </p>
1195
1196<p> Wietse added STARTTLS support in December 2010. This makes
1197postscreen(8) usable for sites that require TLS support.  The
1198implementation introduces the tlsproxy(8) event-driven TLS proxy
1199that decrypts/encrypts the sessions for multiple SMTP clients. </p>
1200
1201<p> The tlsproxy(8) implementation led to the discovery of a "new"
1202class of vulnerability (<a
1203href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-0411"
1204>CVE-2011-0411</a>) that affected multiple implementations of SMTP,
1205POP, IMAP, NNTP, and FTP over TLS. </p>
1206
1207<p> postscreen(8) was officially released as part of the Postfix
12082.8 stable release in January 2011.</p>
1209
1210<p> Noel Jones helped with the Postfix 3.6 transition towards respectful
1211documentation. </p>
1212
1213</body>
1214</html>
1215