Server IP : 85.214.239.14 / Your IP : 3.145.12.195 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/3/cwd/usr/share/doc/amavisd-new/ |
Upload File : |
<?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet href="#internalStyle" type="text/css"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>amavisd-new documentation bits and pieces</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <meta name="AUTHOR" content="Mark Martinec" /> <link rev="made" href="mailto:mark.martinec@ijs.si" /> <style type="text/css" id="internalStyle"> body { background: white; color: black } kbd { font-family: monospace } img.noboarder { color: white; border: none } </style> <!-- [link rel="STYLESHEET" href="./a.css" type="text/css"] --> </head> <body> <h1><em><a href="http://www.ijs.si/software/amavisd/">amavisd-new</a></em> documentation bits and pieces</h1> <p>The most recent version of this document is available at <a href="http://www.ijs.si/software/amavisd/amavisd-new-docs.html"> http://www.ijs.si/software/amavisd/amavisd-new-docs.html</a></p> <ul> <li><a href="#checks">Performing mail checks</a></li> <li><a href="#actions">Acting on mail checks results</a></li> <li><a href="#tagkill">Tag, tag2 and kill levels</a></li> <li><a href="#quarantine">Quarantine</a></li> <li><a href="#quar-release">Releasing from a quarantine</a></li> <li><a href="#addrext">Redirecting malware to a different mailbox -- plus addressing</a></li> <li><a href="#wblist">Hard black- and whitelisting senders regarding spam</a></li> <li><a href="#score_sender">Soft black- and whitelisting senders regarding spam -- @score_sender_maps</a></li> <li><a href="#confvars">Configuration variables</a></li> <li><a href="#pbanks">Policy banks</a></li> <li><a href="#pbanks-ex">Putting policy banks to good use -- examples</a></li> <li><a href="#max_requests">$max_requests</a></li> <li><a href="#dkim">Setting up DKIM mail signing and verification</a> <ul> <li><a href="#dkim-impatient">DKIM: For the impatient - signing from scratch</a></li> <li><a href="#dkim-impatient-from-milter">DKIM: For the impatient - replacing signing by dkim-milter with signing by amavisd</a></li> <li><a href="#dkim-mail-flow">DKIM: Implementation and mail flow</a></li> <li><a href="#dkim-postfix-dual-path">DKIM: Configuring multiple mail paths in Postfix</a></li> <li><a href="#dkim-amavisd-path">DKIM: Configuring multiple mail paths in amavisd</a></li> <li><a href="#dkim-milter">DKIM: Hooking-in dkim-milter (optional)</a></li> <li><a href="#dkim-am-verify">DKIM: Setting up DKIM signature verification in amavisd</a></li> <li><a href="#dkim-am-sign">DKIM: Setting up DKIM signing in amavisd</a></li> <li><a href="#dkim-sa">DKIM: Putting DKIM verification to good use in SpamAssassin</a></li> <li><a href="#dkim-experience">DKIM: Some experience with DKIM and DomainKeys</a></li> <li><a href="#dkim-links">DKIM: Links</a></li> </ul> </li> </ul> <h2><a name="checks">Performing mail checks</a></h2> <p>The following checks on mail are available</p> <ul> <li>mail header validity checks</li> <li>banned names and types checks</li> <li>virus checks</li> <li>spam checks</li> <li>is sender white- or blacklisted (regarding spam)</li> </ul> <p>Although checks are presently not performed in parallel, it is best to consider the order of their evaluation unspecified (unknown). Besides possible future parallel implementation, another reason is the caching of results, where subsequent mail with the same contents may benefit from earlier checks if validity of these check results has not yet expired -- so a check result may be instantly available, regardless of whether it has been asked for or not.</p> <p>Using configuration variables @bypass_virus_checks_maps, @bypass_banned_checks_maps, @bypass_header_checks_maps and @bypass_spam_checks_maps each recipient (or administrator on their behalf) may suggest that certain tests are not needed, primarily for performance reasons. Although the @bypass_*_checks_maps pertain to individual recipients, a mail check is an operation done on the whole message, regardless of the number of recipients and their individual preferences. Suggestion by some of the recipients that certain check is not needed (is to be bypassed) does not guarantee the test will not be performed.</p> <p>Similarly the (hard) blacklisting or whitelisting of sender address may make running spam check unnecessary, but it does not guarantee the spam check result will not be available for subsequent decisions.</p> <p>There are two primary reasons why a check result may still be available despite the bypass hint or a sender being black- or whitelisted:</p> <ul> <li>a check result from some previous mail with the same contents has been cached and is still valid;</li> <li>when mail has multiple recipients and not all of them agree that a check should be bypassed.</li> </ul> <p>The amavisd-new program is allowed to skip some check for performance reasons if all recipients agree that a check is not necessary (that it may be bypassed), or if the outcome of a check to be skipped could not influence further mail processing and delivery/non-delivery of the message (as is the case of a sender being black- or whitelisted regarding spam check).</p> <p>For example spam checks may be skipped if it is already known that a mail is infected. This is an implementation and optimization issue, and no guarantee is given about interdependency of checks. Future version may use a different strategy of performing checks (e.g. some checks may be performed in parallel), as long as a change does not affect the final outcome.</p> <h2><a name="actions">Acting on mail checks results</a></h2> <p>Based on the outcome of mail checks performed during mail analysis or cached from previous mail with the same contents, and based on global settings and individual recipient preferences, the program now decides what action to perform next. As described in the previous section, not all results of checks are necessarily known (e.g. if all recipients voted for some check to be bypassed). For the purpose of deciding further actions, unknown results of a check are considered equivalent to negative (false) results, i.e. skipped virus check is treated the same as non-infected mail, bypassed spam check is equivalent to low spam score (ham).</p> <p>The following decisions are made at this stage:</p> <ul> <li>whether a mail should be quarantined and how;</li> <li>whether an administrator (and which administrator) should receive a notification (and which notification);</li> <li>whether recipients should receive a notification;</li> </ul> <p>and regarding mail delivery and/or sender (non)delivery notifications:</p> <ul> <li>whether a mail should be delivered to each recipient or not;</li> <li>whether delivered mail should be modified (header edits, defanging);</li> <li>whether a sender should receive a (non)delivery notification (bounce);</li> <li>what should be the final status code returned to the mailer (reject/pass).</li> </ul> <p>For the purpose of deciding on these actions, a mail is classified based on all available checks results. It is quite possible that more than one check results would be positive (e.g. virus and banned and bad header, or spam and bad header, or virus and spam), yet a mail is considered to be only in one category. The logic is currently hard-wired into the program and can not be influenced by configuration variables. The following order is used, the first condition met decides the outcome:</p> <ol> <li>a virus is detected: mail is considered infected;</li> <li>contains banned name or type: mail is considered banned;</li> <li>spam level is above kill level for at least one recipient, or a sender is blacklisted: mail is considered spam;</li> <li>bad (invalid) headers: mail is considered as having a bad header.</li> </ol> <p>This decision order explains why amavisd-new is not free to skip (to optimize away) virus checks if a presence of a banned name or a bad header is already known or can easily be determined. The order was chosen with the intention that a more informative or a stronger assertion is the one to base further mail delivery on, and to be quoted in notifications and in the log. Even at the expense of possibly longer processing time, it is more important to declare a mail infected than complain about a bad header, a banned executable or spamy contents.</p> <p>The determined mail category now governs further action. Administrators are notified if enabled for the category, mail is quarantined if quarantining if enabled for the category, recipients are notified if enabled for the category.</p> <p>Next a mail delivery is attempted. A decision to deliver depends on mail category and on global and individual recipient preferences. The global setting $final_*_destiny=D_PASS or a per-recipient setting @*_lovers_maps ensure mail delivery for corresponding mail category even if mail would otherwise be blocked for being infected or banned or spam or having a bad header.</p> <p>A mail that is decided to be passed to an individual recipient undergoes some simple header editing which happens on-the-fly during mail forwarding. Certain mail header fields may be inserted or removed, or an existing header field (e.g. Subject) may be modified. This header editing may be different for each recipient even in multi-recipient messages. If necessary, a multi-recipient mail is split into more than one forwarding transaction, grouping (clustering) recipients with same settings into one SMTP transaction.</p> <p>Based on decisions to forward or to block mail to each recipient, and on the global setting for the mail category ($final_*_destiny=D_BOUNCE or D_REJECT), the sender (non)delivery notification is now prepared in case of D_BOUNCE, and MTA receives a 2xx status (success); or in case of D_REJECT the MTA receives a 5xx (reject) status and preparing sender notifications is thus delegated to MTA (not recommended in post-queue or dual-MTA content filtering setup).</p> <p>Even in cases of mail non-delivery when a (non-)delivery status notification (DSN) for the sender should have been prepared and sent, there are certain exceptions where the DSN is suppressed, which makes mail effectively lost as far as the sender and the recipient are concerned (but quarantining is not affected):</p> <ul> <li>when $final_*_destiny=D_DISCARD;</li> <li>when mail is infected and the detected virus name matches the @viruses_that_fake_sender_maps (unconditionally true by default);</li> <li>when spam score exceeds level determined by @spam_dsn_cutoff_level_maps for all recipients;</li> <li>when mail is coming from a mailing list, as determined by examining a mail header <i>Precedence:</i> for containing string 'bulk' or 'list' or 'junk';</li> </ul> <h2><a name="tagkill">tag, tag2 and kill levels</a></h2> <p>When SpamAssassin is called upon to analyze a mail message, it returns a spam score (spam level, hits), which is a numeric representation of spaminess. The higher the number, the more spamy the message is considered. Small numbers near zero or negative indicate a clean message, colloquially called ham. Spam score is a characteristic of the whole message, and does not depend on recipient preferences. SpamAssassin is called only once for each message regardless of the number of recipients.</p> <p>To determine further course of action, amavisd-new compares the spam score to three numeric values: tag level, tag2 level and kill level. These values may be different for each recipient, and further actions may be different for each recipient. If necessary, the mail forwarding is split into more than one transaction to cater for different recipient preferences.</p> <dl> <dt>tag level</dt> <dd>if spam score is at or above tag level, spam-related header fields (X-Spam-Status, X-Spam-Level) are inserted for local recipients; undefined (unknown) spam score is interpreted as lower than any spam score;</dd> <dt>tag2 level</dt> <dd>if spam score is at or above tag2 level, spam-related header fields (X-Spam-Status, X-Spam-Level, X-Spam-Flag and X-Spam-Report) are inserted for local recipients, and X-Spam-Flag and X-Spam-Status bear a YES; also recipient address extension (if enabled) is tacked onto recipient address for local recipients; for these actions to have any effect, mail must be allowed to be delivered to a recipient;</dd> <dt>kill level</dt> <dd>if spam score is at or above kill level, mail is blocked; and sender receives a nondelivery notification unless spam score exceeds dsn cutoff level.</dd> </dl> <p>The general idea is that kill level is what controls the main actions as far as MTA and amavisd-new is concerned (regardless of what recipients' MUA later does with the mail).</p> <p>Reaching kill level for at least one recipient controls the following:</p> <ul> <li>mail gets quarantined (unless disabled)</li> <li>spam administrator gets a notification (unless disabled)</li> <li>ContentSpamMsgs counter is incremented</li> <li>sender gets a notification if warnspamsender is true and $final_spam_destiny is D_PASS</li> <li>if message is not delivered, sender gets a nondelivery notification (suppressed under certain conditions)</li> <li>the main log entry says: Passed/Blocked SPAM.</li> </ul> <p>On the other hand the tag2 level just adds some mark to the passed mail (only for local recipients), which recipient or his MUA may decide to act on or not. Specifically:</p> <ul> <li>Subject header field is modified (unless disabled)</li> <li>X-Spam-Flag and X-Spam-Status header field get a Yes</li> <li>address extension for spam gets tacked on the recipient address</li> <li>spam defanging is done (unless disabled)</li> <li>the main log entry says: Passed/Blocked SPAMMY.</li> </ul> <p>For mail below kill level, if a recipient (or his MUA) decides to discard a message based on tag2 marking, there is no way to retrieve it later from a quarantine, the sender is never notified, spam administrator is never notified. As far as the MTA and amavisd-new are concerned, the message was successfully delivered. Whatever MUA does with the mail is entirely the responsibility and jurisdiction of the recipient and his LDA and MUA.</p> <h2><a name="quarantine">Quarantine</a></h2> <p>Mail quarantining is attempted when enabled for a given contents category, which usually includes infected, or banned, or spam mail with score for at least one of its recipients at or above his kill level. It is also possible to enable quarantining of clean messages for archiving or troubleshooting purposes. The <i>*quarantine_to</i> for each recipient (when nonempty), along with a corresponding global <i>*_quarantine_method</i>, determines where the quarantine location should be.</p> <h3><a name="quarantine_method">quarantine_method</a></h3> <p>The <i>*_quarantine_method</i> can be considered a static and a site-wide setting, generally controlling a format and location of the quarantine on the system. The <i>*quarantine_to</i> can be considered a dynamic part of the quarantine location, possibly affected by per-recipient settings and the type of malware (contents category). It serves to fully specify the final location, e.g. a file or a mailbox.</p> <p>Depending on mail contents category (type of malware), the following variables specify the quarantine method: <tt>$virus_quarantine_method</tt>, <tt>$spam_quarantine_method</tt>, <tt>$banned_files_quarantine_method</tt>, and <tt>$bad_header_quarantine_method</tt>. One way to globally disable quarantine is to specify undef or an empty string as a value of these variables. A nonempty string should follow a syntax:</p> <ul> <li><tt>local:</tt><i>filename-template</i></li> <li><tt>bsmtp:</tt><i>filename-template</i></li> <li><tt>smtp:[</tt><i>IPv4-or-IPv6-address-or-hostname</i><tt>]:</tt><i>port</i></li> <li><tt>smtp:</tt><i>hostname</i><tt>:</tt><i>port</i></li> <li><tt>smtp:</tt><i>/path/to/a/unix/socket</i></li> <li><tt>lmtp:[</tt><i>IPv4-or-IPv6-address-or-hostname</i><tt>]:</tt><i>port</i></li> <li><tt>lmtp:</tt><i>hostname</i><tt>:</tt><i>port</i></li> <li><tt>lmtp:</tt><i>/path/to/a/unix/socket</i></li> <li><tt>pipe:</tt><i>argv=command args...</i></li> <li><tt>sql:</tt><i>anything</i></li> </ul> <p>The <tt>local:</tt>, <tt>bsmtp:</tt> and <tt>sql:</tt> methods are the usual methods for quarantining. The <tt>smtp:</tt> or <tt>lmtp:</tt> methods are only useful for quarantining if quarantine location is some dedicated mailbox instead of a local file or directory. The <tt>smtp:</tt>, <tt>lmtp:</tt> and <tt>pipe:</tt> methods are more often used for forwarding and notifications, and only rarely for quarantining. The following features became available with version 2.5.0: the <tt>lmtp:</tt> method, support for IPv6, and specifying a Unix socket to a <tt>smtp:</tt> or <tt>lmtp:</tt> method.</p> <p>When quarantine method starts with <tt>local:</tt>, the rest of the string is a <i>filename-template</i>, which serves to specify a file name to store a quarantined message. The template may contain placeholders which are composed of a percent character, followed by exactly one character. The following expansions are recognized:</p> <ul> <li><tt>%b</tt> is replaced by $msginfo->body_digest</li> <li><tt>%P</tt> is replaced by $msginfo->partition_tag</li> <li><tt>%m</tt> is replaced by $msginfo->mail_id</li> <li><tt>%n</tt> is replaced by $msginfo->log_id</li> <li><tt>%i</tt> is replaced by ISO 8601 timestamp of a mail reception time</li> <li><tt>%%</tt> is replaced by a single %</li> </ul> <p>If a <i>filename-template</i> ends up in <tt>.gz</tt>, the resulting file will be gzip-compressed.</p> <h3><a name="quarantine_to">quarantine_to</a></h3> <p>Depending on the method specified (local/bsmtp/smtp/sql) a per-recipient setting <i>*quarantine_to</i> adopts different semantics and syntax, possibly modified by the configuration variable <tt>$QUARANTINEDIR</tt>.</p> <table border="1"> <tr> <th>method</th> <th>quarantine_to</th> <th><tt>$QUARANTINEDIR</tt></th> <th>effect</th></tr> <tr> <td>anything</td> <td>empty or undef</td> <td>anything</td> <td>not quarantined</td></tr> <tr> <td>empty or undef</td> <td>anything</td> <td>anything</td> <td>not quarantined</td></tr> <tr> <td><tt>local:</tt></td> <td>pseudo-alias mapped through %local_delivery_aliases</td> <td>directory</td> <td>stored as an individual file below the directory <tt>$QUARANTINEDIR</tt>, file name comes from the template specified in the <i>*_quarantine_method</i>; if a template file name ends in .gz the message will be gzip-compressed </td></tr> <tr> <td><tt>local:</tt></td> <td>pseudo-alias mapped through %local_delivery_aliases</td> <td>filename of a mailbox</td> <td>appended to a file <tt>$QUARANTINEDIR</tt> in mbox format</td></tr> <tr> <td><tt>local:</tt></td> <td>pseudo-alias mapped through %local_delivery_aliases</td> <td>empty or undef</td> <td>not quarantined</td></tr> <tr> <td><tt>local:</tt></td> <td>e-mail address containing '@'-sign</td> <td>anything</td> <td>sent via SMTP to a mailer for storage, uses $notify_method to specify how to deliver to MTA; much like a newer '<tt>smtp:</tt>' entry below</td></tr> <tr> <td><tt>smtp:</tt></td> <td>e-mail address</td> <td>anything</td> <td>sent via SMTP to a mailer for storage, uses the specified IP address and port, or a Unix socket for delivery; formerly a '<tt>local:</tt>' method was used for this purpose</td></tr> <tr> <td><tt>lmtp:</tt></td> <td>e-mail address</td> <td>anything</td> <td>sent via LMTP to a mailer for storage, uses the specified IP address and port, or a Unix socket for delivery</td></tr> <tr> <td><tt>bsmtp:</tt></td> <td>anything (nonempty)</td> <td>anything</td> <td>stored in a file specified in the <i>*_quarantine_method</i> in BSMTP format (if file name is absolute, i.e. starts with a "/")</td></tr> <tr> <td><tt>bsmtp:</tt></td> <td>anything (nonempty)</td> <td>directory</td> <td>stored in a file specified in the <i>*_quarantine_method</i> in BSMTP format (file name relative to <tt>$QUARANTINEDIR</tt>)</td></tr> <tr> <td><tt>sql:</tt></td> <td>anything (nonempty)</td> <td>anything</td> <td>stored into SQL database specified by @storage_sql_dsn</td></tr> </table> <p>The <i>*quarantine_to</i> is currently quite limited in functionality, it is often used only to turn off the quarantining for some user or local subdomain. The reason for this limited functionality is a more vulnerable nature of this value, as it may come from SQL or LDAP lookups where non-careful access controls to these databases might permit users to enter any value in the <i>*quarantine_to</i> field, which is why we do not let it control the directory or the exact file name of the quarantine file. This may be somewhat relaxed in the future.</p> <p>In common setups the quarantine location (e.g. a directory or a dedicated mailbox) is the same for all recipients. If at least one recipient specifies a nonempty <i>*quarantine_to</i> specifying this location, the message is quarantined (stored) there once, regardless of the number of recipients.</p> <p>The general algorithm is: the <i>*quarantine_to</i> value associated with each recipient is looked up. Empty or undef values are ignored and duplicates are discarded. A mail to be quarantined is then stored/sent to each unique location remaining on the list.</p> <p>The "bsmtp:" quarantine method is somewhat special in that the quarantine file location is entirely determined by the <i>*_quarantine_method</i> setting, and the value of per-recipient <i>*quarantine_to</i> settings do not influence the quarantine location, as long as this value is nonempty.</p> <p>When using the "bsmtp:" quarantine method and versions of amavisd-new earlier than 2.2.0, the <i>*_quarantine_to</i> was completely ignored, which made it impossible to turn off quarantining selectively for certain users by specifying an empty or undef value. Since 2.2.0, an empty <i>*_quarantine_to</i> turns off quarantine for a recipient regardless of the quarantine method. A nonempty string in <i>*_quarantine_to</i> (the exact value is ignored) must now be used even with "bsmtp:" to enable quarantining.</p> <h2><a name="quar-release">Releasing from a quarantine</a></h2> <p>The utility <i>amavisd-release</i> tells the amavisd daemon to fetch a mail from a local quarantine, and send it to MTA through its regular channels ($notify_method), bypassing re-checking.</p> <p>By default it connects to socket /var/amavis/amavisd.sock, on which amavisd should be listening for AM.PDP protocol, but one can use inet socket instead of a Unix socket if there is a need to run <i>amavisd-release</i> from a remote host.</p> <p>In the amavisd.conf the following should be added:</p> <pre> $unix_socketname = "$MYHOME/amavisd.sock"; # listen on Unix socket # alternatively (less common): # $inet_socket_port = [10024, 9998]; # listen on listed inet tcp ports # apply policy bank AM.PDP-SOCK on a Unix socket: # (note that this precludes the use of old amavis-milter # helper program (with sendmail) on the same socket) $interface_policy{'SOCK'} = 'AM.PDP-SOCK'; # apply policy bank AM.PDP-INET to some inet tcp socket, e.g. tcp port 9998: $interface_policy{'9998'} = 'AM.PDP-INET'; $policy_bank{'AM.PDP-SOCK'} = { protocol => 'AM.PDP', # select Amavis policy delegation protocol auth_required_release => 0, # don't require secret_id for amavisd-release }; $policy_bank{'AM.PDP-INET'} = { protocol => 'AM.PDP', # select Amavis policy delegation protocol inet_acl => [qw( 127.0.0.1 [::1] )], # restrict access to these IP addresses # auth_required_release => 0, # don't require secret_id for amavisd-release }; </pre> <p>Setting of $auth_required_release decides whether the requestor needs to specify secret_id in addition to mail_id to authorize a mail release. The secret_id is stored in SQL table msgs when logging to SQL is enabled, otherwise this information is not accessible.</p> <p>Note that turning off $auth_required_release check is safe as long as access to the socket is restricted, like with file protections on a Unix socket, or restricted with inet_acl to specific IP addresses. Enabling or disabling $auth_required_release is a management / setup decision and convenience.</p> <p>To release a mail message an exact quarantine location from a log file should be specified as an argument to amavisd-release, e.g.:</p> <pre> amavis[29297]: (29297-01-6) Blocked SPAM, ... <xxx> -> <yyy>, quarantine: <i>spam/U/UM3XM3XDbN52.gz</i>, Message-ID:<...>, mail_id: UM3XM3XDbN52, Hits: 13.365, $ amavisd-release <i>spam/U/UM3XM3XDbN52.gz</i> 250 2.6.0 Ok, id=rel-UM3XM3XDbN52, from MTA([193.2.4.66]:10025): 250 2.0.0 Ok: queued as F137717B88B </pre> <p>The <i>amavisd-release</i> utility also accepts <i>mail_id</i> from STDIN if releasing more than one message in one go is more convenient:</p> <pre> $ amavisd-release - <i>spam/U/UM3XM3XDbN52.gz</i> <i>spam/g/gnwKVFKiuey3.gz</i> <i>spam/X/Xpkj9mLLBHTR.gz</i> </pre> <h2><a name="addrext">Redirecting malware to a different mailbox -- plus addressing</a></h2> <p>Amavisd-new can tag passed malware by appending an address extension to a recipient address. An address extension is usually a short string (such as 'spam') appended to the local part of the recipient address, delimited from it by a single character delimiter, often a '+' (or sometimes a '-'). This is why address extensions are also known as "plus addressing". Examples of such mail addresses belonging to user <i>jim@example.com</i> are: <i>jim+spam@example.com</i>, <i>jim+cooking@example.com</i>, <i>jim+health@example.com</i>, <i>jim+postfix@example.com</i>.</p> <p>Most mailers (MTA), including Postfix and sendmail, have some provision to put address extensions to good use. Similarly, local delivery agents (LDA) such as Cyrus or LDAs that come with MTA, can be configured to recognize and make use of address extensions.</p> <p>The most common application for address extensions is to provide additional information to LDA to store mail into a separate mail folder. Users may for example choose to use this feature to let LDA automatically file messages from mailing lists to a dedicated subfolder, or to file spam to a spam folder, just by letting LDA simply and quickly examine the envelope recipient address, without having to parse mail header or having to configure and run filters such as procmail or Sieve.</p> <p>Mailers (MTA and LDA) usually attempt first to examine (to check for validity, to lookup in virtual or aliases maps) a full unmodified recipient address. If the attempt is unsuccessful, they strip away the extension part, and try again. This way a presence of some unknown address extension is simply ignored. For example, a delivery for <i>jim+health@example.com</i> would deliver the mail to the main Jim's inbox if he hasn't provided a subfolder <i>health</i> in his mailbox.</p> <p>For this fallback to work (to ignore unknown extensions), it is important that all components that need to deal with address extensions (MTA, LDA, content filters) have the same notion of the delimiter in use on the system. For Postfix the configuration option is <tt>recipient_delimiter=+</tt> (see also propagate_unmatched_extensions), for amavisd-new the option is <tt>$recipient_delimiter='+';</tt> for Cyrus the delimiter is hardcoded as '+', see <a href="http://cyrusimap.web.cmu.edu/imapd/faq.html">Cyrus IMAP FAQ -> plus addressing</a>.</p> <p>The amavisd-new configuration options for adding address extensions are @addr_extension_virus_maps, @addr_extension_spam_maps, @addr_extension_banned_maps, @addr_extension_bad_header_maps. The configuration must also ensure the malware mail is to be delivered, otherwise there is nothing to tack an address extension on -- either by setting kill level sufficiently high, or by declaring spam lovers, or by <tt>$final_spam_destiny=D_PASS</tt>; an example:</p> <pre> $recipient_delimiter = '+'; @addr_extension_spam_maps = ('spam'); $sa_tag2_level_deflt = 6.7 ; # score above which spam extension is added $sa_kill_level_deflt = 15; # block higher score entirely $final_spam_destiny=D_DISCARD; # junk all above kill level </pre> <p>or provide extension string more selectively for certain users or subdomains:</p> <pre> @addr_extension_spam_maps = ( { '.sub1.example.com' => 'spam', # an entire subdomain 'user1@example.com' => 'spam', # a particular user 'user2@example.com' => 'malware', # another user wants a different ext. '.' => '' } # all the rest do not receive an extension ); </pre> <p>If one is considering using a quarantine mechanism but wants a per-user (or perhaps per-subdomain) quarantines, this is not such a good idea, because quarantined files are not supposed to be directly visible or handled by recipients: to protect the privacy of the sender, some header pre-processing must be performed on a quarantined file before handing it over to a recipient.</p> <p>The cleanest way to achieve per-user quarantine which may be directly accessible and/or manipulated by recipients is to turn on adding address extensions, and configure MTA and/or LDA to store such mail wherever necessary, either to a user's dedicated subfolder, or perhaps to some centralized dedicated set of malware mailboxes (per-user or perhaps per-subdomain).</p> <p>If it is desired to reroute extension-tagged mail to some mailbox away from the usual LDA, the virtual alias mapping by MTA is the tool for the job. With Postfix, a pcre-based virtual map can specify for example:</p> <pre> /^(.*)\+spam@([^@]*)\.example\.com$/ spam-$2-box@example.com </pre> <p>which will collect all spam into one mailbox for each subdomain.</p> <p>For the Postfix local(8) LDA, a presence of a file $HOME/.forward+spam can redirect mail for user+spam to some dedicated file. For the Postfix virtual(8) LDA, a virtual_mailbox_maps may contain entries like:</p> <pre> user1 mbxfile1 user1+spam mbxspamfile1 user2 mbxfile2 user2+spam mbxspamfile2 </pre> <h2><a name="wblist">Hard black- and whitelisting senders regarding spam</a></h2> <p>The blacklisting and the whitelisting are ways of telling that we already know that a message is spam or is ham (non-spam) just by examining the envelope sender address and comparing it to lists of known spammers or to lists of known legitimate senders of ham. It is a quick check, potentially saving us the trouble of examining the mail contents. It has a big drawback however in that the sender mail address can be (and often is) faked and there is no guarantee that the claimed sender address represents the actual sender.</p> <p>The sender address is usually faked for spam messages, so whitelisting some sender address is a of questionable value, and often lets in far more spam than it does good by approving legitimate mail. For a reliable way of permitting certain sending clients to send spamy mail see <i>policy banks</i>.</p> <p>Blacklisting however is still useful: spammer has no desire to pretend to be some blacklisted sending address, when he can choose any other address. Genuine sender that is intentionally blacklisted can only avoid being blocked by falsifying his address (joining spammers in his methods) <em>and</em> sending non-spamy mail, the later being our objective anyway. Although amavisd-new does provide blacklisting, it is functionally equivalent but more effective to blacklist senders at the MTA, preventing such mail from even entering the mail system.</p> <p>It should be emphasized that whitelisting (and blacklisting) only affects spam checks. It has no influence on other checks such as virus, banned or header checks. Infected mail from whitelisted sender would still be blocked if our policy is to block viruses.</p> <p>Another point to bear in mind is that the sender address examined is the one from the SMTP protocol, exactly as provide by MTA to amavisd-new. It is known as the envelope sender address or return path. This address does not necessarily match the mail author's address from the mail header (From:) or the sender's address from the header (Sender:). This is most obvious with mail from mailing lists, where the envelope sender address is usually the address of a mailing list management service, while the author's address (From:) is the address of a person sending the message. Using the envelope sender address in most cases makes it easier to black- or whitelist mail from mailing lists, compared to guessing a sender address by parsing mail header.</p> <p>To avoid surprises, whitelisted sender suppresses inserting/editing the tag2-level header fields (X-Spam-*, Subject), appending spam address extension, and quarantining, even if we know the message is spam (e.g. because the spam check result on the same mail contents has been cached from some earlier mail or known from check on behalf of another recipient).</p> <p>For mail from blacklisted senders, the effect is as if the spam level were artificially pushed high, resulting in 'X-Spam-Flag: YES', high 'X-Spam-Level' bar and other usual reactions to spam, including possible rejection. If the message nevertheless still passes (e.g. for spam loving recipients), it is tagged as BLACKLISTED in the 'X-Spam-Status' header field, but the reported spam value and set of tests in this report header field is not adjusted (if available from SpamAssassin, which may or may not have been called)</p> <p>If <em>all</em> recipients of a message either white- or blacklist the sender, amavisd is free to skip spam scanning (calling the SpamAssassin), saving on time. There is no guarantee however that spam scanning will actually and always be skipped.</p> <p>The following variables (lists of lookup tables) are available, with the semantics and syntax as specified in README.lookups: @whitelist_sender_maps, @blacklist_sender_maps, which implement global policy applicable to all recipients. Similarly there are $per_recip_blacklist_sender_lookup_tables and $per_recip_whitelist_sender_lookup_tables, which make possible for each recipient or subdomain to specify its own set of black- or whitelisted senders. The per-recipient tables take precedence over global tables.</p> <p>For SQL lookups, amavisd-new will first lookup the recipient in table <i>users</i> in order of descending priority, e.g. user@sub.domain.org, user, @.sub.domain.org, @.domain.org, @.org, and @. (which can be considered a catchall). Each matching recipient record may have a list of senders associated (through join on field <i>users.id</i> and <i>wblist.rid</i>). The sender address is then looked up in the associated list of senders (<i>wblist</i>) in order of descending priority, e.g. sender@sub.example.com, @.sub.example.com, @.example.com, @.com, and @. . This search stops at the first matching sender record with a non-NULL field <i>wblist.wb</i>. The value of a field <i>wblist.wb</i> from the matched record determines if the sender is considered whitelisted ('W'), blacklisted ('B') or neutral (' ') for this recipient.</p> <p>The neutral value is there just as a way to explicitly stop the search, which may be used by a recipient to overrule site-wide or static white- or blacklisting defaults for some specific sender, and to explicitly neither whitelist nor blacklist the sender, letting the normal spam check determine the spaminess of a mail.</p> <p>For recipient user@sub.domain.com and sender sender@sub.example.com the following search is performed:</p> <pre> user@sub.domain.org sender@sub.example.com @.sub.example.com @.example.com @.com @. user sender@sub.example.com @.sub.example.com @.example.com @.com @. @.sub.domain.org sender@sub.example.com @.sub.example.com @.example.com @.com @. @.domain.org sender@sub.example.com @.sub.example.com @.example.com @.com @. @.org sender@sub.example.com @.sub.example.com @.example.com @.com @. @. sender@sub.example.com @.sub.example.com @.example.com @.com @. </pre> <h2><a name="score_sender">Soft black- and whitelisting senders regarding spam -- @score_sender_maps</a></h2> <p>Instead of hard black- or whitelisting a sender address (unconditionally considering mail spam or ham solely based on sender address regardless of mail contents), a more gentle approach is to add score points (penalties) to the spam score for mail from certain senders or sending domains. Positive points lean towards blacklisting, negative towards whitelisting. This is much like adding SpamAssassin rules or using its white/blacklisting, except that here only envelope sender addresses are considered (not addresses in a mail header), and that score points can be assigned per-recipient (or per-domain or globally), and that the assigned penalties are customarily much lower than the default SpamAssassin white/blacklisting score.</p> <p>The table structure of @score_sender_maps is similar to $per_recip_blacklist_sender_lookup_tables i.e. the first level key is recipient address, pointing to by-sender lookup tables. The essential difference is that scores from <em>all</em> matching by-recipient lookups (not just the first that matches) are summed to give the final score boost. That means that both the site and domain administrators, as well as the recipient can have a say on the final score.</p> <p>For SQL lookups, the mechanism is much like the one described for hard black- or whitelisting, with the following differences:</p> <ul> <li>the field <i>wblist.wb</i> is numeric, representing score points, instead of containing a character W or B or space;</li> <li>the search through matching recipients does not stop at the first match, but traverses all matching recipients, summing up the corresponding <i>wblist.wb</i> field values.</li> </ul> <p>Namely, amavisd will lookup the recipient, e.g. user@sub.domain.org, user, @.sub.domain.org, @.domain.org, @.org, and @. . Since the search will not stop at the first recipient match, the search order in this case is unimportant, although it is actually the same descending-priority order as with hard b/w listing. Each matching recipient record may have a list of senders associated (through join on field <i>users.id</i> and <i>wblist.rid</i>). The sender address is then looked up in the associated list of senders (<i>wblist</i>) in order of descending priority, e.g. sender@sub.example.com, @.sub.example.com, @.example.com, @.com, and @. . This search stops at the first matching sender record with a non-NULL field <i>wblist.wb</i>, but this does not terminate the outer recipients search. Numeric values of a field <i>wblist.wb</i> from matched records are summed up across all matching recipients tables, and the result is added to the spam score as produced by SpamAssassin.</p> <p>Unlike static tables, where hard and soft w/b-listing use separate tables, the SQL-based hard and soft w/b-listing uses the same SQL tables and the same field <i>wblist.wb</i>. Mixing the 'W', 'B' with numeric values is somewhat frowned upon, but is supported to facilitate transition. The search goes like described above as long as only numeric field values are encountered, summing up the values and adding the accumulated sum to the final score. If a non-numeric value of field <i>wblist.wb</i> is encountered during this search, its value (W or B or space) is interpreted as described for hard w/b listing, and the search stops at this point.</p> <h2><a name="confvars">Configuration variables</a></h2> <p>The behaviour of the amavisd-new is controlled by a set of configuration variables, which are just normal module-global Perl variables (in package Amavis::Conf). At daemon startup time these variables are first assigned an initial value (often just an undefined value, the undef). The default values of configuration variables are documented in file amavisd.conf-defaults, which lists all configuration variables.</p> <p>Next a configuration file amavisd.conf (or other file as specified by option -c) is read and interpreted by the Perl interpreter itself. The amavisd.conf is just a normal Perl program, and can in principle do whatever and however it pleases, but its main purpose is to assign values to configuration variables.</p> <p>After execution of amavisd.conf is done, the daemon may correct some configuration variable values (mainly to maintain backwards compatibility with earlier version of configuration file), and may assign a default value to certain variables which are still undefined -- these variables and their default values are marked "after-defaults" in the documentation file amavisd.conf-defaults. The main reason for existence of the "after-defaults" concept is that some default values depend on other configuration variables and can not be computed before the amavisd.conf is finished. To force such variables to an off/false/disabled state, one needs to assign some false but defined value to them, such as '' (an empty string) or a 0 for booleans.</p> <p>Perl variables always start with a character $, @ or % to indicate a type of variable. This leading character is part of the variable name for all practical purposes.</p> <dl> <dt>$ (dollar character)</dt> <dd>indicates a scalar variable (a string, a number, a reference)</dd> <dt>@ (at sign)</dt> <dd>indicates an array variable (a list)</dd> <dt>% (percent character)</dt> <dd>indicates an associative array (also known as hash), which maps keys to values</dd> </dl> <p>A couple of Perl syntactical elements deserve mention at this point, as they are often used in the amavisd.conf configuration file.</p> <dl> <dt>"...", a double-quoted string</dt> <dd>is a string; variables within are evaluated, e.g. "$MYHOME/tmp"</dd> <dt>'...', a single-quoted string</dt> <dd>is a string; variables within are not evaluated, the $ and @ loose their special meaning, e.g. 'user@example.com'</dd> <dt>(...)</dt> <dd>is a list of comma-separated expressions, e.g. (1,2,"test"); a list is normally assigned to an array variable</dd> <dt>qw(string)</dt> <dd>is an operator that interprets its argument as a single string, splits it on whitespace to words, and returns a list of words (strings); it is a convenience to avoid some typing, e.g. qw(user@example.com .example.net .org) is exactly equivalent to ('user@example.com', '.example.net', '.org'); </dd> <dt>[...]</dt> <dd>is a reference to an anonymous list of comma-separated expressions, e.g. [1,2,"test"]; (note: a reference is a scalar)</dd> <dt>{...}</dt> <dd>is a reference to an anonymous associative array, e.g. {'alfa'=>1, 'beta'=>99, 'other'=>'test'}; (note: a reference is a scalar)</dd> <dt>\variable</dt> <dd>is a reference to a variable, e.g. \$virus_admin, \@mynetworks, \%whitelist_sender; (note: a reference is a scalar)</dd> </dl> <p>Historically amavisd-new accessed all configuration variables directly with their name, e.g. %spam_lovers, @spam_lovers_acl, $spam_lovers_re. Later it became apparent that certain groups of variables (lookups) are always used together in the same way, so new array variables like @spam_lovers_maps were introduced. The program now never accesses old lookup table variables directly, but always through higher level lists. The solution is fully backwards compatible, as the default value for the new lists references the old variables, e.g.:</p> <pre> @spam_lovers_maps = (\%spam_lovers, \@spam_lovers_acl, \$spam_lovers_re); </pre> <p>Administrator is free to modify or replace the lists in variables like @spam_lovers_maps, perhaps rearranging the order or loosing all references to legacy variables, and replacing them with other variables, often anonymous arrays/lists or anonymous associative maps (hashes), or constants which can serve as a convenient catchall default value when used last in the list.</p> <p>Since amavisd-new version 2.0, there is one further generalization step in the way a program accesses configuration variables. More than a hundred configuration variables which control amavisd-new operation on a by-message level (as opposed to by-recipient and truly global settings) are now grouped in associative array called a <i>policy bank</i>. These configuration variables are no longer accessed directly by their variable name by the program, but always through a currently installed policy bank. Administrator is free to modify the policy bank, normally by providing replacement policy banks and specifying under what conditions the replacement policy bank is to be automatically installed.</p> <h2><a name="pbanks">Policy banks</a></h2> <p>Policy banks hold sets of configuration variables controlling most of per-message settings, including: static lookup tables, IP interface access rules, forwarding address, log level, templates, administrator addresses, spam trigger levels, quarantine rules, lists of anti-virus scanner entries (or just a subset), banned names rules, defang settings, etc. The whole set of these settings may be replaced with another predefined set based on incoming port number, making it possible for one amavisd daemon to cope with more diverse needs of served user communities which could so far only be implemented by running more than one instance of the amavisd daemon, each with its own configuration file.</p> <p>This mechanism brings new potentials for the future: in principle policy banks could be swapped not only based on port number or SMTP client IP address, but on any characteristics pertaining to a mail message as a whole (not specific to each of its recipients), or to characteristics of a connection from a mailer (e.g. the interface address or protocol);</p> <p>Until a better mechanism is available, a policy bank named 'MYNETS' has special semantics: this policy bank is loaded (if it exists) whenever MTA supplies a SMTP client's IP address (through Postfix XFORWARD extension to the SMTP protocol, or via a new AM.PDP protocol) and that address matches the @mynetworks list (actually: the list referenced by 'mynetworks_maps' key in the currently installed policy map).</p> <p>An associative array %interface_policy is a current mechanism of assigning a policy bank to an incoming TCP port number (port must be in the list @$inet_socket_port, otherwise amavisd will not listen on that port). Whenever a connection from MTA is received, first a built-in policy bank with an empty name -- the $policy_bank{''} gets loaded, which brings in all the global/legacy settings. Then it is overlaid by whatever configuration settings are in the bank named in the $interface_policy{$port} if any, and finally the policy bank named 'MYNETS' (i.e. settings from $policy_bank{'MYNETS'}) is overlaid if such policy bank exists and the SMTP client IP address is known (by XFORWARD SMTP extension command from MTA) and it matches the current mynetworks_maps.</p> <p>When a new policy bank is overlaid over an existing set of configuration variables, the variables not present in the new policy bank retain their value. This makes it possible to specify new policy banks which carry only a minimal set of settings that need to be changed.</p> <p>The built-in policy bank (with empty name) is predefined, and includes references to most other variables (the dynamic config variables), which are accessed only indirectly through the currently installed policy bank. Overlaying a policy bank with another policy bank may bring in references to entirely different variables, possibly unnamed, and may remove references to legacy variables if it so chooses.</p> <p>Configuration variables are referenced from a policy bank (which is implemented as a perl associative array, i.e. a hash) by keys of the same name, e.g. { log_level => \$log_level, inet_acl => \@inet_acl, ...}. For scalars one level of indirection is allowed, e.g. a policy bank { log_level => \$log_level }; $log_level=2; is equivalent to { log_level => $log_level } or to { log_level => 2 }, but in the first example with an indirect reference, the $log_level may be assigned to even _after_ the policy bank has already been formed.</p> <p>A word of caution: the syntax of entries within a policy bank hash is slightly different from assignments to configuration variables. This is because entries within policy bank are not assignments, but key=>value pairs as in any Perl associative array. And these pairs are delimited by commas, unlike statements, which are delimited by semicolons. Value is separated from its key by '=>' (or by a comma), whereas the assignment operator is '='. Keys of a policy bank are without leading $ or @ or %, unlike variable names. Values of an associative array can only be scalars (e.g. strings or numbers or references to arrays or references to associative array).</p> <p>Compare:</p> <ul> <li>value of a policy bank is a reference to a Perl associative array, e.g.: <pre> { log_level => 3, forward_method => 'smtp:[127.0.0.1]:10025', spam_admin_maps => ["spamalert\@$mydomain"], blacklist_sender_maps => [ [qw(.example.org .example.net)] ], } </pre> </li> <li>normal assignments look like: <pre> $log_level = 3; $forward_method = 'smtp:[127.0.0.1]:10025'; @spam_admin_maps = ("spamalert\@$mydomain"); @blacklist_sender_maps = ( [qw(.example.org .example.net)] ); </pre> </li> </ul> <p>And a final note: Perl can detect and report typing mistakes in variable names, but mistyped key is just some unused associative array entry lurking in a hash, never used and never reported as mistyped/useless.</p> <h2><a name="pbanks-ex">Putting policy banks to good use -- examples</a></h2> <p>The sender address can be faked, so comparing envelope sender address to @local_domains_maps or some other lookup table to base some important decisions on would not be trustworthy. The only reliable information is the recipient's e-mail address and information about client SMTP session, such as the IP address of the sending SMTP client and the server port number or the interface address. Such information can be made available by MTA to amavisd-new through a feeding protocol (e.g. XFORWARD extension or via AM.PDP), or separate MTA paths can be set up for mail that needs to be treated differently, such as internally originating and externally originating mail, or perhaps separating authenticated mail from the rest.</p> <p>Amavisd-new has two ways of receiving such extra information from MTA:</p> <ul> <li>it can listen on more than one TCP port and apply different policy banks to each port (applicable to any dual-MTA setup including Postfix), and/or</li> <li>it can accept SMTP client's IP address from MTA by XFORWARD extension to the SMTP protocol (available in Postfix only), which can control loading of policy bank MYNETS. This is in addition to loading policy banks based on TCP port number. The MYNETS policy bank is loaded (if applicable) <i>after</i> (on top of the) the port-assigned policy bank.</li> </ul> <p>The following examples illustrate several ways of distinguishing between different mail origins. For most common purposes the only distinction that really matters is separating internally originating mail from the rest, and for this purpose the use of policy bank MYNETS and a sufficiently recent version of Postfix supporting XFORWARD suffices -- the complication with multiple ports and multiple interfaces is needed only for more demanding sites which prefer maximum flexibility.</p> <h3>Example 1</h3> <p>As stated earlier, a policy bank named 'MYNETS' is loaded (if it exists) whenever MTA supplies an original SMTP client's IP address (e.g. via the Postfix XFORWARD extension) and that address matches the @mynetworks list. This covers most common needs to distinguish internally-originating mail from the rest, and allows them to be treated differently, as illustrated by the following example:</p> <pre> $policy_bank{'MYNETS'} = { # mail originating from @mynetworks virus_admin_maps => ["security\@$mydomain"], # alert of infected local hosts spam_admin_maps => ["abuse\@$mydomain"], # alert of internal spam spam_kill_level_maps => [7.0], # slightly more permissive spam kill level spam_dsn_cutoff_level_maps => [15], banned_filename_maps => [ new_RE( # block double extensions in names: qr'\.[^./]*\.(exe|vbs|pif|scr|bat|cmd|com|cpl|dll)\.?$'i, # allow any name or type (except viruses) within an archive: [ qr'^\.(Z|gz|bz2|rpm|cpio|tar|zip|rar|arc|arj|zoo)$' => 0], # blocks MS executable file(1) types, unless allowed above: qr'^\.(exe-ms)$', ), ], }; </pre> <h3>Example 2</h3> <p>In the following example some of the external mail is coming in via fetchmail, the rest of the externally originating mail is coming in via normal SMTP at tcp port 25, and all internally originating mail is coming to MTA via mail submission port 587 reserved for that purpose, or via dedicated IP address accessible only from inside, or through a Postfix pickup service. We'll use Postfix in this example, although it does not rely on any particular Postfix capability that wouldn't be available in any general purpose MTA in some form or another.</p> <p>Only the specifics of this setup are described here. Missing bits like the MTA re-entry port 10025 and other options are described in <a href="./README.postfix">README.postfix</a> and are assumed here. Specifying additional smtpd restrictions and options may be desired, and is omitted here for brevity.</p> <p>To let amavisd-new be able to distinguish between all four mail entry routes, we let amavisd listen on four TCP ports (the fifth is for good measure, to be used in the next example): <tt>$inet_socket_port = [10040,10041,10042,10043,10044];</tt> (any unused non-privileged TCP ports can be used)</p> <p>In Postfix configuration file master.cf we attach different <i>content_filter</i> options to each of the Postfix services receiving mail. We'll assume the MTA host has two IP addresses 192.0.2.1 and 192.0.2.2 assigned (IP aliases or separate physical interfaces), which makes it easier to distinguish between internally originating mail and the rest even if XFORWARD can not be used (older Postfix versions or some other MTA):</p> <pre> # regular incoming mail, originating from anywhere (usually from outside) # the MX record (or backup mailers) should point to this IP address 192.0.2.1:smtp inet n - n - - smtpd -o content_filter=amavisfeed:[127.0.0.1]:10040 # incoming mail from fetchmail, considered externally originating # (add 'smtphost localhost/2345' to the poll section in .fetchmailrc) 127.0.0.1:2345 inet n - n - - smtpd -o content_filter=amavisfeed:[127.0.0.1]:10041 -o smtpd_client_restrictions=permit_mynetworks,reject -o mynetworks=127.0.0.0/8 # IP address to be used by internal hosts for mail submission 192.0.2.2:smtp inet n - n - - smtpd -o content_filter=amavisfeed:[127.0.0.1]:10042 -o smtpd_client_restrictions=permit_mynetworks,reject # or, tcp port 587 to be used by internal hosts for mail submission submission inet n - n - - smtpd -o content_filter=amavisfeed:[127.0.0.1]:10042 -o smtpd_client_restrictions=permit_mynetworks,reject # locally originating mail submitted on this host through a sendmail binary pickup fifo n - n 60 1 pickup -o content_filter=amavisfeed:[127.0.0.1]:10043 </pre> <p>A global option <i>content_filter</i> in file main.cf could provide a convenient default, only services that need a different setting would then need to override it.</p> <p>Now let's make up names for policy banks which will cover all four cases. We'll pick names EXT, EXT-FM, INT, INT-HOST for policy banks. The amavisd needs to be told to load corresponding policy when a request comes in on each of the listening ports:</p> <pre> $interface_policy{'10040'} = 'EXT'; $interface_policy{'10041'} = 'EXT-FM'; $interface_policy{'10042'} = 'INT'; $interface_policy{'10043'} = 'INT-HOST'; $interface_policy{'10044'} = 'AUTH'; # to be used in the next example </pre> <p>Next we'll prepare each policy and specify there the options which should be different from global options. Note that the following policies serve mostly as an example and to provide ideas -- they should not be considered a recommendation. For example:</p> <pre> # regular incoming mail, originating from anywhere (usually from outside) $policy_bank{'EXT'} = { # just use global settings, no special overrides }; # incoming mail from fetchmail, considered externally originating $policy_bank{'EXT-FM'} = { log_level => 2, # no bounces for spam, not even for score below spam_dsn_cutoff_level_maps: final_spam_destiny => D_DISCARD, }; # locally originating mail guaranteed to be from inside $policy_bank{'INT'} = { # enable/redirect admin notifications for locally originating malware: virus_admin_maps => ["virusalert\@$mydomain"], spam_admin_maps => ["virusalert\@$mydomain"], # be slightly more permissive on spam levels for mail from our hosts: spam_kill_level_maps => [7.0], spam_dsn_cutoff_level_maps => [15], final_virus_destiny => D_BOUNCE, # (unless in viruses_that_fake_sender_maps) final_spam_destiny => D_BOUNCE, # (unless above spam_dsn_cutoff_level_maps) bypass_banned_checks_maps => [ 1 ], # allow sending any file type or name # provide customized sender notifications for spam from our users: notify_spam_sender_templ => read_text("$MYHOME/notify_spam_sender.txt"), }; # mail locally submitted on the host on which MTA runs $policy_bank{'INT-HOST'} = { # NOTE: this is just an example; ignoring internally generated spam # may not be such a good idea, consider zombified infected local PCs bypass_spam_checks_maps => [ 1 ], bypass_banned_checks_maps => [ 1 ], final_spam_destiny => D_PASS, final_banned_destiny => D_PASS, }; # authenticated mail (used by the next example) $policy_bank{'AUTH'} = { # enable admin notifications for malware originating from our users: virus_admin_maps => ["virusalert\@$mydomain"], spam_admin_maps => ["virusalert\@$mydomain"], # be slightly more permissive on spam levels for mail from our users: spam_kill_level_maps => 7.0, spam_dsn_cutoff_level_maps => 15, bypass_banned_checks_maps => 1, # allow sending any file type or name final_bad_header_destiny => D_BOUNCE; # block invalid headers }; </pre> <p>If not all four cases need to be distinguished, the same policy bank name (or none at all) can be assigned to more than one port. Also the MTA configuration can use the same amavisd port for more than one of its incoming services if there is no need for different settings.</p> <h3>Example 3</h3> <p>Besides setting different <i>content_filter</i> options for different Postfix services, one may use the option FILTER in Postfix lookup tables, as described in Postfix man pages access(5) and header_checks(5), to specify different <i>content_filter</i> settings based on various conditions, such as sender domain name or IP address, mail header fields, etc.</p> <p>Consider the next example which uses the FILTER settings to distinguish from internally originating, authenticated external mail and the rest.</p> <pre> # global default: content_filter=amavisfeed:[127.0.0.1]:10044 # note that permit_mynetworks only checks for key presence and ignores rhs mynetworks = cidr:/etc/postfix/mynetworks-filter.cidr smtpd_sender_restrictions = ... the usual rejects if any ... check_client_access cidr:/etc/postfix/mynetworks-filter.cidr permit_mynetworks permit_sasl_authenticated permit_tls_clientcerts check_sender_access regexp:/etc/postfix/filter-catchall.regexp </pre> <p>The <tt>check_client_access cidr:/etc/postfix/mynetworks-filter.cidr</tt> preceeds the <i>permit_mynetworks</i> (which uses the same cidr table, but ignores the righthand side), and it serves to override the global <i>content_filter</i> setting by the use of FILTER for each of the networks (presumably internal) listed in mynetworks-filter.cidr. The final effect is that mail matching networks listed in mynetworks-filter.cidr will be sent for content filtering to tcp port 10042 (the FILTER setting in access map), authenticated non-local mail will be sent for content filtering to port 10044 (the global setting), while all the rest will be sent to port 10040 (as specified in catchall filter). If there are any other overrides in master.cf like in the previous example, they take precedence over the global settings, but the FILTER rules take the ultimate precedence.</p> <p>/etc/postfix/mynetworks-filter.cidr :</p> <pre> 127.0.0.0/8 FILTER amavisfeed:[127.0.0.1]:10042 10.0.0.0/8 FILTER amavisfeed:[127.0.0.1]:10042 172.16.0.0/12 FILTER amavisfeed:[127.0.0.1]:10042 192.168.0.0/16 FILTER amavisfeed:[127.0.0.1]:10042 </pre> <p>/etc/postfix/filter-catchall.regexp:</p> <pre> /^/ FILTER amavisfeed:[127.0.0.1]:10040 </pre> <p>Note that in place of the last catchall entry: <tt>check_sender_access regexp:/etc/postfix/filter-catchall.regexp</tt> one would be tempted to do: <tt>check_sender_access static:FILTER amavisfeed:[127.0.0.1]:10040</tt>, but unfortunately spaces are not allowed within an option value in master.cf, so we have to resort to a lookup table.</p> <h2><a name="max_requests">$max_requests</a></h2> <p>Amavisd-new runs under process control of Net::Server. This is a pre-forked environment where $max_servers child processes are constantly kept alive and ready to accept new tasks (mail messages to be checked). Each amavisd child process is able to handle several tasks in a row, which helps to reduce startup (fork) costs. In case of SMTP or LMTP protocol, each session may consist of several SMTP/LMTP transactions. Each SMTP/LMTP transaction is counted a one task, regardless of whether it came in from the same SMTP/LMTP client in a multi-transaction session, or as separate sessions, possibly from different SMTP/LMTP clients.</p> <p>A configuration variable $max_requests (default value 20) controls the approximate number of tasks each child process is willing to handle. After that the child process terminates and Net::Server provides a new child process to take its place.</p> <p>The exact value of $max_requests is not critical. There are two opposing needs, and some in-between value should be chosen.</p> <p>On the low side, the number should not be too small in order for the startup cost to be averaged out / sufficiently diluted over an entire child lifetime. A value above 5 or 10 meets this goal in most amavisd-new configurations.</p> <p>On the high side, the value depends on the amavisd-new configuration. The amavisd daemon itself is conservative in its use of dynamically allocated memory and does not load mail into memory, but keeps mail being processed and its components on files. Similarly, most of the called external virus scanners and decoders are rational in their use of memory (a notable exception was Archive::Tar which was used if a pax or cpio command was not available, but is no longer supported). Unfortunately this is not true for Perl module Mail::SpamAssassin, which expects to have an entire decoded mail in memory in order to be able to run its large set of rules on it in reasonable time. This is a design decision of SpamAssassin.</p> <p>When amavisd-new is not configured to use SpamAssassin, the value of $max_requests can be quite high without any known or expected problems. For general sanity reasons, an upper limit could be a 100 for example, although anything above 20 or so would not bring measurable benefit to the maximum sustained mail throughput.</p> <p>When amavisd-new <em>is</em> configured to use SpamAssassin however, the slurping of entire mail in memory and decoding it may have implications, depending on the $sa_mail_body_size_limit value, on the maximum mail size allowed at the MTA (e.g. Postfix setting for <i>message_size_limit</i>) and on the mail compression factor. Even though the allocated memory is reclaimed by Perl after mail processing, and is reused for subsequent processing, the process virtual memory footprint never shrinks, it can only expand as needed.</p> <p>The $sa_mail_body_size_limit sets a limit on a mail size beyond which SpamAssassin is not called, so it can not contribute to memory usage much beyond this limit, times a small factor (2-5?, due to multiple internal representations of a message). If the $sa_mail_body_size_limit is large, and MTA mail size is not limited, or if mail has a huge mail header, the memory footprint can become noticable. For the rest of a lifetime the child process that processed the mail stays at its high virtual memory size. If this happens frequently, host resources may become scarce. Limiting the number of tasks is very much desirable in this case.</p> <p>The default value of 20 for $max_servers was chosen as a good compromise between averaging-out the startup costs and not wasting too much resources on hosts with high message size limit and SpamAssassin enabled.</p> <p>In the setup with Postfix where its lmtp client is chosen to feed amavisd-new, this client tries to keep LMTP session open and submit several mail messages in multiple transactions. With recent Postfix versions its SMTP client is capable and willing of using multiple transaction sessions as well, although it seems to be less persistent than the LMTP client.</p> <p>According to SMTP and LMTP protocol specifications, dropping the session on the server side is considered rude and should be used only as a last resort. In order to respect the $max_requests setting (which is not strictly enforced by amavisd, and is considered an advisory value), the client side should preferably be configured with a comparable limit. Starting with amavisd-new-2.2.0 the amavisd daemon is more strict in enforcing the limit and drops the SMTP or LMTP session after $max_servers is exceeded by one. This was a recommendation from the Postfix community, as the option of reducing Postfix max_use setting is considered less appropriate.</p> <p>Nevertheless, Postfix doesn't take session dropping lightly, it backs off a while after content filter forcibly drops the session, which is undesired. Better behaviour is achieved when Postfix voluntarily terminates a SMTP session before amavisd would reach its $max_requests limit. This can be achieved by applying max_use to the Postfix smtp service feeding a content filter (typically this entry in master.cf is named 'amavisfeed').</p> <h2><a name="dkim">Setting up DKIM mail signing and verification</a></h2> <p>A DKIM standard (RFC 4871) states the following, which applies to its predecessor DomainKeys (historical: RFC 4870) as well:</p> <blockquote> <p><i> DomainKeys Identified Mail (DKIM)</i> defines a mechanism by which email messages can be cryptographically signed, permitting a signing domain to claim responsibility for the introduction of a message into the mail stream. Message recipients can verify the signature by querying the signer's domain directly to retrieve the appropriate public key, and thereby confirm that the message was attested to by a party in possession of the private key for the signing domain.</p> </blockquote> <blockquote> <p>The <i>DomainKeys</i> specification was a primary source from which the <i>DomainKeys Identified Mail [DKIM]</i> specification has been derived. The purpose in submitting the RFC 4870 document is as an historical reference for deployed implementations written prior to the DKIM specification.</p> </blockquote> <p>The main advantage of DKIM signing <b>to sending domains</b> is that it allows recipients to reliably validate mail origin for purposes of <b>whitelisting</b> on spam checks and whitelisting reception of otherwise banned mail contents. By signing outbound mail you give your correspondents a chance to distinguish between your genuine mail, and fraud or spam mail which may happen to carry your domain name as a sender address. Signing outbound mail is a <b>kind gesture towards recipients</b>, making it much easier for them to <b>treat your mail as important or desirable</b> if they choose so.</p> <p>The main advantage of DKIM signature verification <b>to recipients</b> is that it allows them to reliably distinguish genuine mail originating from a claimed sending domain from other (possibly faked) mail. It makes <b>signature-based whitelisting</b> a <b>reliable</b> mechanism. It also makes it possible to recognize and automatically discard <b>fake mail</b> claiming to be from domains which are known to always sign their outbound mail and to always send mail directly. Coupled with <b>reputation</b> schemes (mostly manual/static at present, or dynamic in the future) makes it possible to assign score points (positive or negative) based on merit and past experience with each signing domain. A valid signature also offers <b>non-repudiation</b>: a domain which signed a message can not disclaim message origin, which offers recipient a strong argument when <b>reporting abuse</b> to the signing domain.</p> <h3><a name="dkim-impatient">For the impatient - signing from scratch</a></h3> <p>Here is a quick Spartanic setup of DKIM signing and DKIM/DK verification by amavisd for the impatient, without much explanation, assuming all originating mail comes from internal networks (not from authenticated roaming clients), only one domain needs signing, using default signature tags, no milters are in use and no mailing list manager needs signing. No changes in Postfix configuration is necessary for this simple setup. For more information and more complex setups please see sections further on.</p> <p>Generate a signing key:</p> <pre> $ amavisd genrsa /var/db/dkim/example-foo.key.pem </pre> <p>add to amavisd.conf:</p> <pre> $enable_dkim_verification = 1; $enable_dkim_signing = 1; dkim_key('example.com', 'foo', '/var/db/dkim/example-foo.key.pem'); @dkim_signature_options_bysender_maps = ( { '.' => { ttl => 21*24*3600, c => 'relaxed/simple' } } ); @mynetworks = qw(0.0.0.0/8 127.0.0.0/8 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16); # list your internal networks </pre> <p>run:</p> <pre> $ amavisd showkeys </pre> <p>add the public key (as displayed) to your DNS zone, increment SOA sequence number and reload DNS; then test signing and a published key:</p> <pre> $ amavisd testkeys </pre> <p>if all went well:</p> <pre> $ amavisd reload </pre> <h3><a name="dkim-impatient-from-milter">For the impatient - replacing signing by dkim-milter with signing by amavisd</a></h3> <p>For sites already signing their mail by dkim-milter, most work of preparing signing keys and publishing public keys in DNS has already been done. All it needs to be done is to declare these signing keys in amavisd.conf and turn on $enable_dkim_signing.</p> <p>To facilitate transition of DKIM signing from dkim-milter to amavisd-new, a new command-line tool is available with amavisd-new-2.6.2 (the extra utility code is not loaded during normal operation), taking a file name as its argument, e.g.:</p> <pre> $ amavisd convert_keysfile /var/db/dkim/keysfile.txt </pre> <p>and writing to stdout a set of lines that may be directly included into amavisd.conf configurations file, matching semantics of a dkim-filter keys file. It can be useful during transition, or for those who prefer to specify signing keys and sender-to-key mappings as a file in a syntax compatible with options -K -k of dkim-filter, and can live with limitations of such syntax. See dkim-filter(8) man page for details on the syntax.</p> <p>The produced output consists of signing key declarations (calls to a procedure dkim_key), where each call normally corresponds to exactly one DNS resource record publishing a corresponding DKIM public key. When necessary output also produces an assignment to a list of lookup tables @dkim_signature_options_bysender_maps, which supplies non-default mappings of sender domains to signing keys, e.g. when third-party signatures are desired.</p> <h3><a name="dkim-mail-flow">Implementation and mail flow</a></h3> <p>Signing of originating mail (or mail being redistributed by our domain), and verifying signatures of incoming mail are two tasks that can be performed by the same program, or they can be performed by separate entities. Traditionally with sendmail, both tasks are performed by one milter, which may be easier to maintain, but has certain disadvantages.</p> <p>Verifying signatures should be performed early, before any local mail transformations get a chance of invalidating a signature, e.g. by performing MIME conversions to quote-printable, by fixing syntactically invalid mail header section, by reformatting or reordering some header fields (some MTAs do it frivolously), by modifying/inserting/removing certain header fields, or by a local mailing list modifying mail text, e.g. by appending footers.</p> <p>Signing outgoing mail should be performed late, after mail sanitation, after conversion to 7-bit characters (to avoid later uncontrollable changes by a relaying or receiving MTA), and after editing header section by a content filter. Similar applies to local mailing lists, which may be rewriting messages, requiring them to be re-signed by the domain hosting a mailing list, just before being sent out.</p> <p>Starting with amavisd-new version 2.6.0, DKIM signing can be performed directly by amavisd (using a Perl module Mail::DKIM, which is the same module as used by DKIMproxy and by SpamAssassin). Signing directly by amavisd reduces setup complexity using a milter or DKIMproxy, and avoids additional data transfers. Regarding mail flow through the system there are similarities between signing in amavisd and signing by dkim-milter, which is why the diagram below shows both possibilities.</p> <p>For verification there are three choices: either amavisd itself can do it by calling Mail::DKIM directly, or a SpamAssassin plugin can do it by calling the same Perl module, or a milter in verification-only mode can be invoked by an incoming Postfix smtpd service.</p> <p>Advantage of invoking signature <i>verification by amavisd</i> is that <i>all mail is checked</i> for signatures, regardless of whether SpamAssassin is called or not. Typically messages beyond a certain size are not passed to SpamAssassin, and neither are infected message or identified bounces. Amavisd also offers loading of policy banks based on valid DKIM/DK signatures (e.g. allowing some domains to send-in otherwise banned files, or whitelisting on spam), offers to add score points based on signing domain reputation, and adds Authentication-Results header field (like a dkim-milter does).</p> <p>Invoking signature <i>verification by SpamAssassin</i> has an advantage that DKIM-based or DomainKeys-based whitelisting or scoring can be used, but has a disadvantage that possibly not all mail is checked (e.g. large mail and infected mail may be exempt from spam checks). Performing the same signature validation task twice (by amavisd and by SA) may seem wasteful, but in practice it is not too bad: thanks to DNS server caching a network lookup for a public signing key is only done once, and as SpamAssassin does not receive large mail for processing, its signature verification is very quick: few milliseconds for non-signed mail, and of the order of a tenth of a second for signed mail.</p> <p>Invoking signature <i>verification by calling a milter</i> from incoming smtpd service has an advantage that it has the best chance of seeing mail in its pristine form (before canonical and virtual mapping or masquerading by MTA, regardless of their settings). Because it is poorly integrated with the rest of the chain (e.g. with SpamAssassin rules and amavisd policy banks), and because it adds one extra data transfer, it is mainly still useful as a way to double-check the correctness of DKIM validation by having two independent implementations in use, each inserting its independently derived Authentication-Results header field into passed mail.</p> <p>To sign as late as possible with a dkim-milter, the signing milter can be invoked by a Postfix smtpd service which is receiving content-checked mail from a content filter such as amavisd-new. As this second-stage smtpd service does not reliably know how a given message came into a mail system and whether it is supposed to be signed or not, a clean solution is to provide two (or more) parallel paths through MTA and through a content filter, one used for mail that is eligible for being signed (originating mail), the other for all the rest. This same dual path approach through amavisd is beneficial for signing by amavisd too, for the same reason of providing a reliable source of information on mail origin to a signature choosing code:</p> <pre> +------+ |verify| (verify) +--+---+ | (by amavisd and/or SA) ^^^ milter | incoming: ||| +---v-------+ MX ----> 25 smtpd ---> 10024 > >---> 10025 smtpd --> || | | SASL --> 25 smtpd \ | amavisd | (notifications) submission | +-> | >--->_ mynets-> 25 smtpd ---> 10026 >ORIGINATING>---> 10027 smtpd --> submission +-> +-------^---+ | --> 587 smtpd / : | v milter (convert | +------+ to 7-bit) (sign) | sign | +------+ </pre> <p>There are other benefits to providing two parallel paths: a content filter may be configured to apply different rules and settings to mail that is known to be originating from our users. Some suggestions: apply less strict banning rules, enable spam administrator notifications for internally originating spam and viruses, letting SpamAssassin rules be conditionalized based on amavisd-new policy banks loaded, etc.</p> <h3><a name="dkim-postfix-dual-path">Configuring multiple mail paths in Postfix</a></h3> <p>Here is one way of configuring Postfix for providing two paths through a content filter. Locally submitted or authenticated mail will go to a content filter to its port 10026 and will be signed on its way out (either by amavisd or by a signing milter). All other mail (incoming) will be diverted to port 10024 for normal content filtering, and will not be eligible for signing.</p> <p><i>main.cf:</i></p> <pre> # on re-queueing of a message smtpd_*_restrictions do not apply, # so we'd better provide a safe default for a content_filter, # even at an expense of later flipping the choice twice # (which adds a bit to log clutter, but never mind) # content_filter = amavisfeed:[127.0.0.1]:10024 # each triggered FILTER deposits its argument into a # content_filter setting, the last deposited value applies # smtpd_sender_restrictions = check_sender_access regexp:/etc/postfix/tag_as_originating.re permit_mynetworks permit_sasl_authenticated permit_tls_clientcerts check_sender_access regexp:/etc/postfix/tag_as_foreign.re # Make sure to assign FILTER tags in restrictions which # are only invoked once per message, e.g. client or sender # restrictions, but NOT on smtpd_recipient_restrictions, # as a message may have multiple recipients, so multiple # passes through FILTER tag assignments can yield a # surprising (and incorrect) result. </pre> <p><i>/etc/postfix/tag_as_originating.re:</i></p> <pre> /^/ FILTER amavisfeed:[127.0.0.1]:10026 </pre> <p><i>/etc/postfix/tag_as_foreign.re:</i></p> <pre> /^/ FILTER amavisfeed:[127.0.0.1]:10024 </pre> <p>In master.cf set up two listening smtpd services for receiving filtered mail from amavisd (as per README.postfix), one on tcp port 10025 (for inbound mail) and the other on port 10027 (for originating mail). If a signing milter is in use it will be attached to a smtpd service on 10027 only. If no milters are in use and signing is done by amavisd, both smtpd services can have exactly the same settings, and in fact only one suffices, in which case redirecting $forward_method and $notify_method to 'smtp:[127.0.0.1]:10027' in later example can be disregarded.</p> <h3><a name="dkim-amavisd-path">Configuring multiple mail paths in amavisd</a></h3> <p>In amavisd.conf two parallel paths need to be provided, one receiving on port 10024 and forwarding to 10025, the other receiving on port 10026 and forwarding to 10027.</p> <pre> $inet_socket_port = [10024,10026]; # listen on two ports </pre> <p>The 10024>10025 path will be controlled by a default policy bank, the other (10026>10027), dedicated to mail intended to be signed, will use a policy bank (arbitrarily) named ORIGINATING:</p> <pre> $forward_method = 'smtp:[127.0.0.1]:10025'; # MTA with non-signing service $notify_method = 'smtp:[127.0.0.1]:10027'; # MTA with signing service # switch policy bank to 'ORIGINATING' for mail received on port 10026: $interface_policy{'10026'} = 'ORIGINATING'; $policy_bank{'ORIGINATING'} = { # mail originating from our users originating => 1, # indicates client is ours, allows signing # # force MTA to convert mail to 7-bit before DKIM signing # to avoid later conversions which could destroy signature: smtpd_discard_ehlo_keywords => ['8BITMIME'], # # forward to a smtpd service providing DKIM signing service # (if using a signing milter instead of signing by amavisd): forward_method => 'smtp:[127.0.0.1]:10027', # # other special treatment of locally originating mail, # just some suggestions here: spam_admin_maps => ["spamalert\@$mydomain"], # warn of spam from us virus_admin_maps => ["virusalert\@$mydomain"], banned_filename_maps => ['ALT-RULES'], # more relaxed rules spam_quarantine_cutoff_level_maps => undef, # quarantine all spam spam_dsn_cutoff_level_maps => undef, spam_dsn_cutoff_level_bysender_maps => # bounce to local senders only [ { lc(".$mydomain") => undef, '.' => 15 } ], }; </pre> <p>The <tt>smtpd_discard_ehlo_keywords=>['8BITMIME']</tt> serves to persuade Postfix to convert mail to 7-bit quoted-printable before submitting it to content filtering and signing. Avoiding 8-bit characters in mail body makes signatures less susceptible to breaking by some relaying or receiving MTA over which we have no control. The same effect (making Postfix convert outgoing mail to 7-bits before DKIM signing) could be achieved by a Postfix setting <tt>smtp_discard_ehlo_keywords=8bitmime</tt> on a smtp service feeding mail-to-be-signed to amavisd, but this would require setting up two such services, one with the option and one without.</p> <p>Note that 8-bit to 7-bit conversion may break a S/MIME or PGP signature, so if mail signing is in use, it may not be desirable to let Postfix do the conversion, and it may be acceptable to take a risk that a remote MTA will clobber signatures if it decides the mail text is to be converted to 7-bits QP. The only reliable solution in this case is to configure MUA clients to stick to 7-bit characters/encodings before generating S/MIME or PGP signatures.</p> <p>The following text from the Postfix documentation file MILTER_README <em>should be disregarded</em> -- amavisd <em>is</em> 8-bit clean, and we do want Postfix to convert to 7-bits on the signing path but not on the other path: <span style="text-decoration:line-through;font-style:italic">Content filters may break domain key etc. signatures. If you use an SMTP-based content filter, then you should add a line to master.cf with "-o disable_mime_output_conversion=yes", as described in the advanced content filter example.</span></p> <p>While testing how the configured system plays with some mailing lists (such as <i>postfix-users</i> or SpamAssassin <i>users</i> list), one has to keep in mind that amavisd-new caches spam checking results of recently seen message bodies: a mail going out to a mailing list is not yet signed as it reaches a content filter, but the SpamAssassin verdict is remembered at that point (claiming the message is not signed). When this message with unchanged body comes back from a mailing list, this time signed in the header section by our domain, the signature should prove correct, yet the cached result from a minute ago still claims the message is not signed. If this is of concern, one can turn off caching of spam checking results for ham by setting: <tt>$spam_check_negative_ttl = 0;</tt></p> <p>While on the topic of providing multiple paths through amavisd, when one has to deal with a mailing list manager (e.g. Mailman) in the same setup, and re-signing of its fan-out mail is desired, it may be useful to add a third path through amavisd, this one stripped down to bare bones, providing only DKIM signing and nothing else (no virus or spam checks, no decoding), as these checks were already done once on mail before it reached a mailing list manager. Here is one possibility, accepting mail on port 10028 and sending it to 10025:</p> <pre> $inet_socket_port = [10024,10026,10028]; $interface_policy{'10028'} = 'NOCHECKS'; $policy_bank{'NOCHECKS'} = { # no checks, just DKIM signing originating => 1, # allows signing forward_method => 'smtp:[127.0.0.1]:10025', smtpd_greeting_banner => '${helo-name} ${protocol} ${product} NOCHECKS service ready', mynetworks_maps => [], # avoids loading MYNETS policy unnecessarily os_fingerprint_method => undef, penpals_bonus_score => undef, bounce_killer_score => 0, bypass_decode_parts => 1, bypass_header_checks_maps => [1], bypass_virus_checks_maps => [1], bypass_spam_checks_maps => [1], bypass_banned_checks_maps => [1], spam_lovers_maps => [1], banned_files_lovers_maps => [1], archive_quarantine_to_maps => [], remove_existing_x_scanned_headers => undef, remove_existing_spam_headers => undef, signed_header_fields => { 'Sender' => 1 }, }; </pre> <h3><a name="dkim-milter">Hooking-in dkim-milter (optional)</a></h3> <p>This section can be ignored when all DKIM signing and verification is to be done by amavisd, and dkim-milter will not be used. It is mainly provided for compatibility reasons, retaining the old documentation section.</p> <p>Let's begin by starting a dkim milter in two instances, one dedicated to signing, the other to verification. For security reasons all milters should run under a dedicated username, certainly not as <i>root</i>, not as user <i>amavis</i> and not as user <i>postfix</i> or <i>mail</i>: </p> <p><i>verifying:</i></p> <pre> dkim-filter -u dkfilter -b v \ -l -p inet:4443@127.0.0.1 -P /var/run/dkim-filter-v.pid </pre> <p><i>signing:</i></p> <pre> dkim-filter -u dkimfilter -b s -m ORIGINATING \ -c relaxed/simple -S rsa-sha1 \ -d example.com -s myselector -k /var/db/dkim/mykey.pem \ -l -p inet:4445@127.0.0.1 -P /var/run/dkim-filter-s.pid </pre> <p>Generating a public and a private pair of keys and publishing a public key in DNS is described in the dkim milter documentation and also in the DKIM RFC document.</p> <p>We are not specifying option -i to milters, the default of -i 127.0.0.1 suits our setup just fine, as mail to be signed is coming from a content filter, usually on a loopback interface from the IP address 127.0.0.1.</p> <p>Now we can tie the verifying milter to a Postfix smtpd service listening for incoming mail:</p> <p><i>master.cf:</i></p> <pre> smtp inet n - n - 300 smtpd -o milter_default_action=accept -o milter_macro_daemon_name=MTA -o smtpd_milters=inet:127.0.0.1:4443 </pre> <p>and tie the signing milter to a Postfix smtpd service that is receiving checked mail from amavisd, intended to be signed:</p> <p><i>master.cf:</i></p> <pre> # mail return from a content filter (non-signing) 10025 inet n - n - - smtpd -o content_filter= ... (other options, mail not to be signed) ... # mail from our users returning from a content filter (DKIM signing) 10027 inet n - n - - smtpd -o content_filter= ... (other options, mail intended to be signed) ... -o milter_default_action=accept -o milter_macro_daemon_name=ORIGINATING -o smtpd_milters=inet:127.0.0.1:4445 </pre> <p>As a sidenote, attaching milters to sendmail would use the same order of invocations: signature verifying milter first, content filters next, and signing milter last, for example:</p> <pre> dnl Verifiers: INPUT_MAIL_FILTER(`dkim-filter-v', `S=inet:4443@127.0.0.1, T=R:2m') dnl Content filter: INPUT_MAIL_FILTER(`amavisd-milter', `S=unix:/var/amavis/amavisd-milter.sock, F=T, T=S:10m;R:10m;E:10m') dnl Signers: INPUT_MAIL_FILTER(`dkim-filter-s', `S=inet:4445@127.0.0.1, T=R:2m') </pre> <h3><a name="dkim-am-verify">Setting up DKIM signature verification in amavisd</a></h3> <p>Starting with 2.6.0, verification of DKIM signatures (and historical DomainKeys signatures) is provided directly by amavisd (not only by a SpamAssassin plugin DKIM). A required version of a perl module Mail::DKIM is 0.31 or later, but recommended is 0.33 or later. Signature verification is sufficiently fast so there is no need for concern about extra processing load (see TIMING breakdown in your log, level 2). To turn on DKIM (and historical DomainKeys) signature verification, please add the following line to amavisd.conf (if not already there):</p> <pre> $enable_dkim_verification = 1; </pre> <p>Benefits:</p> <ul> <li>Whitelisting of banned checks or spam checks on messages carrying valid DKIM or DomainKeys signatures from trustworthy signers is possible through the @author_to_policy_bank_maps list of lookup tables. The mechanism uses loading of policy banks based on author's e-mail address (addresses in a 'From:' header field) and a signing domain, so a full flexibility of per-policy-bank settings is available. See description of a new configuration variable @author_to_policy_bank_maps in release notes.</li> <li>To each message passed to local recipients amavisd inserts a header field <i>Authentication-Results</i> (according to RFC 5451) for each signature found in a message, reporting a verification result. These header fields can reliably tell a recipient or his MUA what domains claimed responsibility for a message, or can be used for troubleshooting DKIM signing, verification and tracking mail transformations.</li> <li>Can adjust spam score based on signing domain's reputation for valid signatures found in a message. A useful reputation metric is an average long term spam score for past messages signed by a domain, which can currently be provided manually by @signer_reputation_maps in a configuration file (see example in release notes). A spam score is shifted towards this reputation score by a configurable factor $reputation_factor (value between 0 and 1, default is 0.2) using a formula: <tt>adjusted_spam_score = f * reputation + (1-f) * spam_score</tt> . Semantics of a $reputation_factor is equivalent to auto_whitelist_factor in a SpamAssassin's AWL plugin, which shifts spam score towards a long term spam score average of a sender.</li> <li>Notifications and bounces show a "(dkim:AUTHOR)" next to a From address, and a "(dkim:SENDER)" next to a Sender address if these header fields were signed and their domain corresponds to a signer's domain identity.</li> <li>A valid DKIM or DomainKeys signature turns on a 'sender_credible' attribute which serves to choose one of the two DSN cutoff levels, so that delivery status notifications can be restricted to or preferred for likely-to-be-valid sending addresses, and bounces to possibly fake addresses can be minimized. More information on the 'sender_credible' attribute can be found in release notes.</li> </ul> <p>Currently the ADSP (RFC 5617, Author Domain Signing Practices, formerly SSP) is not implemented by amavisd, but is implemented in the SpamAssassin's plugin DKIM as of version 3.3.0.</p> <h3><a name="dkim-am-sign">Setting up DKIM signing in amavisd</a></h3> <p>A recommended version of a perl module Mail::DKIM is 0.33 or later when signing.</p> <p><b>1.</b> Generate one or more keys to be used for signing, and enable signing code by adding the following line to amavisd.conf (if not already there):</p> <pre> $enable_dkim_signing = 1; # loads DKIM signing code </pre> <p>Signing keys must be made available to amavisd, each private key in a separate file in PEM format. Customarily such keys would be generated and kept in a dedicated directory such as /var/db/dkim or /var/lib/dkim, preferably owned by root.</p> <p>Private keys can be generated by a 'openssl genrsa' command (see RFC 4871 Appendix C), or by an amavisd equivalent. Commonly one key per signing domain or one key per signing host is used, but other choices are possible. If such keys were already prepared for some other DKIM-signing solution, they can be reused by amavisd.</p> <pre> # amavisd genrsa /var/db/dkim/a.key.pem # amavisd genrsa /var/db/dkim/b.key.pem 786 # amavisd genrsa /var/db/dkim/sel-example-com.key.pem # amavisd genrsa /var/db/dkim/g-guest-ex-com.key.pem # amavisd genrsa /var/db/dkim/notif-mail.key.pem 512 </pre> <p>Amavisd already ensures the generated files are only readable by owner, but a manual procedure may require explicitly setting file permissions. Private keys must be protected from unauthorized access, only the signing software such as amavisd should have access. Amavisd loads these files on startup before dropping privileges, so if amavisd is started as root it is not necessary that these key files are readable by uid under which amavisd is running.</p> <p><b>2.</b> Add commands to amavisd.conf to load private keys, associate them with signing domains and selectors, and describe constraints (tags) to be published with public keys.</p> <p>Calls to dkim_key() load all available private keys and supply their public key RR constraints. Arguments are a domain, a selector, a key (a file name of a private key in PEM format), followed by optional attributes/constraints (tags, represented here as Perl hash key/value pairs) which are allowed by RFC 4871 in a public key resource record (v, g, h, k, n, s, t), of which only g, h, k, s and t are considered to be constraints limiting the choice of a signing key. A command 'amavisd showkeys' can be used for displaying corresponding public keys in a format directly suitable for inclusion into DNS zone files.</p> <p>For example:</p> <pre> # signing domain selector private key options # ------------- -------- ---------------------- ---------- dkim_key('example.org', 'abc', '/var/db/dkim/a.key.pem'); dkim_key('example.org', 'yyy', '/var/db/dkim/b.key.pem', t=>'s'); dkim_key('example.org', 'zzz', '/var/db/dkim/b.key.pem', h=>'sha256'); dkim_key('example.com', 'sel-2008', '/var/db/dkim/sel-example-com.key.pem', t=>'s:y', g=>'*', k=>'rsa', h=>'sha256:sha1', s=>'email', n=>'testing; 1, 2'); dkim_key('guest.example.com', 'g', '/var/db/dkim/g-guest-ex-com.key.pem'); dkim_key('mail.example.com', 'notif', '/var/db/dkim/notif-mail.key.pem'); </pre> <p>A selector paired with a domain name uniquely identifies a key, both for a signer as well as for a recipient. There may be multiple keys for each domain as long as each one has its own selector.</p> <p>A selector along with a domain name will be used by a receiving mailer in assembling a DNS query (selector._domainkey.signingdomain) to fetch a public key from a signing domain's DNS server when verifying signature validity.</p> <p>A selector paired with a domain name will also be used by a signing amavisd when choosing a key applicable to signing, meeting constraints on its public key (tags, RFC 4871 section 3.6) as given by optional arguments. Optional arguments serve as site documentation, may help amavisd choose between multiple choices (ruling out keys with incompatible tags), and supply additional information for step 3.</p> <p>For a list of options (tags) see RFC 4871 section 3.6. Amavisd does not check the syntax of tag values, except for performing qp-section encoding of a tag 'n'. Note the Perl syntax of key/value pairs, e.g. t => 's:y' will end up as "t=s:y", and n => 'testing; 1, 2' will end up encoded as "n=testing=3B 1, 2".</p> <p><b>3.</b> Prepare and publish public keys.</p> <p>Public keys can be extracted from generated key files (which contain both a private and a public key). To publish public keys they need to be edited into a format suitable for inclusion in a DNS server's zone file for each signing domain, either by following a procedure in RFC 4871 Appendix C, or if step 2 was completed, by asking amavisd to do so:</p> <pre> # amavisd showkeys </pre> <p>or more selectively, e.g.:</p> <pre> # amavisd showkeys .org example.com </pre> <p>This step is not needed if public keys were already prepared and published earlier for some other DKIM-signing solution.</p> <p><b>4.</b> Edit zone files in master DNS server(s) for each signing domain, adding the just prepared TXT resource records, not forgetting to bump up the serial number in a SOA record. Optionally add a TXT record with ADSP information (formerly SSP) if a default Author Domain Signing Practices is not appropriate. Then reload zone(s) or restart DNS server(s).</p> <p><b>5.</b> Test published public keys.</p> <p>Similar to 'showkeys', a 'testkeys' command walks through available signing keys (as declared by calls to dkim_key), generates test messages each signed with one key, and validates them by fetching a corresponding public key from a DNS server.</p> <pre> # amavisd testkeys </pre> <p>or more selectively, e.g.:</p> <pre> # amavisd testkeys .org example.com </pre> <p>(btw, if testkeys fails and you believe your DNS is correctly serving your DKIM public keys, you may need to upgrade Perl module Mail-DKIM to version 0.33)</p> <p><b>6.</b> Restart amavisd, watch the log at log level 2, searching for " dkim: ".</p> <p>Note that signing could be started (amavisd reload) right after completing step 2, but mail recipients would not be able to verify validity of signatures until public keys are made available by a signing domain through its DNS. Recipients are supposed to treat mail with signatures which fail verification exactly the same as mail with no signatures, so there is usually no harm done with a premature start of signing, but there is no benefit either.</p> <p><b>7.</b> Optional: to override default values for signature tags, one may specify by-sender signature tags through @dkim_signature_options_bysender_maps.</p> <p>@dkim_signature_options_bysender_maps maps author/sender addresses or domains to signature tags/requirements. Possible signature tags according to RFC 4871 are: (v), a, (b), (bh), c, d, (h), i, l, q, s, (t), x, z; of which the following are determined automatically: v, b, bh, h, t (tag h is controlled by %signed_header_fields). Currently ignored tags are l and z. Instead of an absolute expiration time (tag x) one may use a pseudo tag 'ttl' to specify a relative expiration time in seconds, which is converted to an absolute expiration time prior to signing: x = t + ttl. A built-in default is provided for each tag if no better match is found.</p> <p>For example:</p> <pre> @dkim_signature_options_bysender_maps = ( { 'postmaster@mail.example.com' => { a => 'rsa-sha1', ttl => 7*24*3600 }, 'spam-reporter@example.com' => { a => 'rsa-sha1', ttl => 7*24*3600 }, 'mail.example.com' => { a => 'rsa-sha1', ttl => 10*24*3600 }, # explicit 'd' forces a third-party signature on foreign (hosted) domains 'ggg.example.net' => { d => 'guest.example.com' }, '.example.com' => { d => 'example.com' }, # catchall defaults '.' => { a => 'rsa-sha256', c => 'relaxed/simple', ttl => 30*24*3600 }, # 'd' defaults to a domain of an author/sender address, # 's' defaults to whatever selector is offered by a matching key } ); </pre> <p>The result of a by-sender lookup into @dkim_signature_options_bysender_maps is a hash (a set) of DKIM signing requirements (tags), i.e. canonicalization method, hashing algorithm, domain, identity, selector and expiration time. All matching entries can participate in the result: for each tag individually the first setting (the most specific) is chosen from all matching entries. Resulting tags are then used to choose the most appropriate signing key from a set of keys as declared by calls to dkim_key. Main selection criterium is a match on tags d (domain) and s (selector), but other signature requirements must also meet the constraints of a public key (e.g. subdomain matching flag, granularity, hashing algorithm, key type). If a lookup does not find a signing key which meets requirements, no signing takes place. Also, only mail with 'originating' flag is eligible for signing. A lookup is based on either the From header field, the Sender header field, the Resent-From and Resent-Sender header field, or on a mail_from address from the envelope, whichever yields a useful result first. Note that neither the Sender header field, nor the Resent-* header fields, nor a mail_from address has any special meaning in the standard (RFC 4871). This results either in an author signature (i.e. a first-party signature, when based on a From header field), or in a third-party signature (when signing domain does not match the From, regardless of what other header field (or forced through a 'd' tag) it was based on.</p> <p>An associative array %signed_header_fields controls which header fields are to be signed. By default it contains a standard (RFC 4871) set of header field names, augmented by some additional header field names considered appropriate at the time of a release (RFC 4021, RFC 3834). In addition a 'Sender' header field is excluded because it is frequently replaced by a mailing list, and as the RFC 2821 mandates there can only be one such header field the original one is dropped, invalidating a signature. Also the 'To' and 'Cc' are excluded from a default set because sendmail mailers are known to gratuitously reformat the list, invalidating a signature.</p> <p>The default set of header fields to be signed can be controlled by setting %signed_header_fields elements to true (to sign) or to false (not to sign). Keys must be in lowercase, e.g.:</p> <pre> $signed_header_fields{'received'} = 0; # turn off signing of Received $signed_header_fields{'sender'} = 1; # turn on signing of Sender $signed_header_fields{'to'} = 1; # turn on signing of To $signed_header_fields{'cc'} = 1; # turn on signing of Cc $signed_header_fields{lc('X-MySpecialFlag')} = 1; </pre> <h3><a name="dkim-sa">Putting DKIM verification to good use in SpamAssassin</a></h3> <p>In SpamAssassin all that is necessary is to add (or uncomment) a line in any of the .pre files (e.g. in local.pre, or in init.pre and v320.pre):</p> <pre> loadplugin Mail::SpamAssassin::Plugin::DKIM </pre> <p>Perl module Mail::DKIM needs to be installed. Note that Mail::DKIM starting with version 0.20 also recognizes DomainKeys signatures, so that Plugin::DomainKeys is not needed any longer, and in fact its underlying module is not supported any longer. It is advisable to stick to the most recent version of Mail::DKIM, at least 0.32.</p> <p>The following SpamAssassin rules (in local.cf) work quite well.</p> <pre> score DKIM_VERIFIED -0.1 score DKIM_SIGNED 0 # don't waste time on fetching ASP record, hardly anyone publishes it score DKIM_POLICY_SIGNALL 0 score DKIM_POLICY_SIGNSOME 0 score DKIM_POLICY_TESTING 0 # DKIM-based whitelisting of domains with good reputation: score USER_IN_DKIM_WHITELIST -8.0 whitelist_from_dkim *@ebay.com whitelist_from_dkim *@*.ebay.com whitelist_from_dkim *@ebay.co.uk whitelist_from_dkim *@*.ebay.co.uk whitelist_from_dkim *@ebay.at whitelist_from_dkim *@ebay.ca whitelist_from_dkim *@ebay.de whitelist_from_dkim *@ebay.fr whitelist_from_dkim *@*.paypal.com whitelist_from_dkim *@paypal.com whitelist_from_dkim *@* paypal.com whitelist_from_dkim *@*.paypal.be whitelist_from_dkim *@cern.ch whitelist_from_dkim *@amazon.com whitelist_from_dkim *@springer.delivery.net whitelist_from_dkim *@cisco.com whitelist_from_dkim *@alert.bankofamerica.com whitelist_from_dkim *@bankofamerica.com whitelist_from_dkim *@cnn.com whitelist_from_dkim *@*.cnn.com whitelist_from_dkim *@skype.net whitelist_from_dkim service@youtube.com whitelist_from_dkim *@welcome.skype.com whitelist_from_dkim *@cc.yahoo-inc.com yahoo-inc.com whitelist_from_dkim *@cc.yahoo-inc.com whitelist_from_dkim rcapotenoy@yahoo.com whitelist_from_dkim googlealerts-noreply@google.com # DKIM-based whitelisting of domains with less then perfect # reputation can be given fewer negative score points: score USER_IN_DEF_DKIM_WL -1.5 def_whitelist_from_dkim *@google.com def_whitelist_from_dkim *@googlemail.com def_whitelist_from_dkim *@* googlegroups.com def_whitelist_from_dkim *@* yahoogroups.com def_whitelist_from_dkim *@* yahoogroups.co.uk def_whitelist_from_dkim *@* yahoogroupes.fr def_whitelist_from_dkim *@yousendit.com def_whitelist_from_dkim *@meetup.com def_whitelist_from_dkim dailyhoroscope@astrology.com # reduce default scores, which are being abused score ENV_AND_HDR_DKIM_MATCH -0.1 score ENV_AND_HDR_SPF_MATCH -0.5 </pre> <p>Another suggestions - penalize mail claiming to be from PayPal, eBay, Yahoo or Gmail but was not signed by their official mailers:</p> <pre> header __ML1 Precedence =~ m{\b(list|bulk)\b}i header __ML2 exists:List-Id header __ML3 exists:List-Post header __ML4 exists:Mailing-List header __ML5 Return-Path:addr =~ m{^([^\@]+-(request|bounces|admin|owner)|owner-[^\@]+)(\@|\z)}mi meta __VIA_ML __ML1 || __ML2 || __ML3 || __ML4 || __ML5 describe __VIA_ML Mail from a mailing list header __AUTH_YAHOO1 From:addr =~ m{[\@.]yahoo\.com$}mi header __AUTH_YAHOO2 From:addr =~ m{\@yahoo\.com\.(ar|au|br|cn|hk|mx|my|ph|sg|tw)$}mi header __AUTH_YAHOO3 From:addr =~ m{\@yahoo\.co\.(id|in|jp|nz|th|uk)$}mi header __AUTH_YAHOO4 From:addr =~ m{\@yahoo\.(ca|cn|de|dk|es|fr|gr|ie|it|no|pl|se)$}mi meta __AUTH_YAHOO __AUTH_YAHOO1 || __AUTH_YAHOO2 || __AUTH_YAHOO3 || __AUTH_YAHOO4 describe __AUTH_YAHOO Author claims to be from Yahoo header __AUTH_GMAIL From:addr =~ m{\@gmail\.com$}mi describe __AUTH_GMAIL Author claims to be from gmail.com header __AUTH_PAYPAL From:addr =~ /[\@.]paypal\.(com|co\.uk)$/mi describe __AUTH_PAYPAL Author claims to be from PayPal header __AUTH_EBAY From:addr =~ /[\@.]ebay\.(com|at|be|ca|ch|de|ee|es|fr|hu|ie|in|it|nl|ph|pl|pt|se|co\.(kr|uk)|com\.(au|cn|hk|mx|my|sg))$/mi describe __AUTH_EBAY Author claims to be from eBay meta NOTVALID_YAHOO !DKIM_VERIFIED && __AUTH_YAHOO && !__VIA_ML priority NOTVALID_YAHOO 500 describe NOTVALID_YAHOO Claims to be from Yahoo but is not meta NOTVALID_GMAIL !DKIM_VERIFIED && __AUTH_GMAIL && !__VIA_ML priority NOTVALID_GMAIL 500 describe NOTVALID_GMAIL Claims to be from gmail.com but is not meta NOTVALID_PAY !DKIM_VERIFIED && (__AUTH_PAYPAL || __AUTH_EBAY) priority NOTVALID_PAY 500 describe NOTVALID_PAY Claims to be from PayPal or eBay, but is not score NOTVALID_YAHOO 2.8 score NOTVALID_GMAIL 2.8 score NOTVALID_PAY 6 # accept replies from abuse@yahoo.com even if not dkim/dk-signed: whitelist_from_rcvd abuse@yahoo.com yahoo.com whitelist_from_rcvd MAILER-DAEMON@yahoo.com yahoo.com </pre> <h3><a name="dkim-experience">Some experience with DKIM and DomainKeys</a></h3> <p>Recent versions of software components must be used to avoid bugs and known interoperability problems:</p> <ul> <li>if using Postfix with milters, use Postfix versions 2.3.12 or later, or 2.4.5 or later, or 2.5 (or later);</li> <li>amavisd-new 2.6.0 introduced direct support for DKIM signing and verification by calling a perl module Mail::DKIM directly; version amavisd-new-2.6.2 (or later) is recommended;</li> <li>Mail::DKIM is solid; use the latest version, currently 0.33;</li> <li>SpamAssassin 3.2.5 or later;</li> </ul> <p>Several big players are already signing mail from their customers or employees: Yahoo! (worldwide), Gmail, eBay, Earthlink, google.com, Amazon, Springer, CNN, Skype, YouTube, Cisco, many universities, etc.</p> <p>Mail transformations as performed by some mailing lists are probably the most challenging problem facing DKIM deployment (and to other schemes as well). Nevertheless, mailing lists can be configured to either avoid transformations which invalidate mail signatures, or can re-sign fan-out mail. Examples of mailing lists which work very well with DKIM (and DomainKeys), preserving existing signatures provided by posters, are the <i>postfix-users</i> ( postfix-users@postfix.org ) and the <i>SpamAssassin users</i> list ( users@spamassassin.apache.org ). Example of re-signing mailing lists are Yahoo groups. A representative of another type of mailing lists is Mailman, which often modifies mail body and strips out original signatures, unless explicitly configured not to.</p> <p>When signatures are missing on mail from domains which are known to be signing all their mail (yahoo.com, gmail.com), the most common reason is that a sender submitted his mail through some other provider, but supplied his Yahoo or gmail e-mail address in the <i>From</i> header field. Similar to other schemes designed to prevent faking of sending address, the DKIM (and the DomainKeys) encourages mail submission only through a domain which is used in the <i>From</i> address.</p> <p>People need to become aware that their best choice is to submit mail through their native domain to prevent their messages from being treated as second-class. With a widespread support for authorized mail submission for roaming users (SASL, TLS) through a mail submission port (tcp port 587, RFC 4409), supported by practically all modern clients and mailers, there is no longer any good excuse for submitting mail through foreign mail submission agents.</p> <p>Note that some spam is also being signed by DomainKeys or DKIM lately, which is a good thing -- it indicates the sender owns (or <i>ownz</i>) a domain they are sending mail from. This either shows sender's sincere desire of not hiding behind a faked sender mail address (in which case such mail can be easily filtered if necessary), or they are using a short-lived temporary domain (<i>domain kiting</i>), which can be counteracted by black lists of few-days old freshly registered domains (such as <a href="http://support-intelligence.com/dob/" >http://support-intelligence.com/dob/</a>), <i>spameatingmonkey.net</i> or other reputation schemes. Signing and verifying mail is a good mechanism for companies to reliably whitelist mail from their partner companies or frequent clients.</p> <h3><a name="dkim-links">Links</a></h3> <ul> <li><a href="http://www.dkim.org/info/dkim-faq.html">DKIM Frequently Asked Questions</a> (at MIPA)</li> <li><a href="http://www.rfc-editor.org/rfc/rfc4871.txt">RFC 4871</a>: DomainKeys Identified Mail (DKIM) Signatures</li> <li><a href="http://www.rfc-editor.org/rfc/rfc5672.txt">RFC 5672</a>: RFC 4871 DomainKeys Identified Mail (DKIM) Signatures -- Update</li> <li><a href="http://www.rfc-editor.org/rfc/rfc4870.txt">RFC 4870</a>: (historical document) Domain-Based Email Authentication Using Public Keys Advertised in the DNS (DomainKeys)</li> <li><a href="http://www.rfc-editor.org/rfc/rfc5617.txt">RFC 5617</a>: DKIM Author Domain Signing Practices (ADSP)</li> <li><a href="http://www.rfc-editor.org/rfc/rfc4686.txt">RFC 4686</a>: Analysis of Threats Motivating DomainKeys Identified Mail (DKIM)</li> <li><a href="http://www.rfc-editor.org/rfc/rfc5016.txt">RFC 5016</a>: Requirements for a DomainKeys Identified Mail (DKIM) Signing Practices Protocol</li> <li><a href="http://www.rfc-editor.org/rfc/rfc5585.txt">RFC 5585</a>: DomainKeys Identified Mail (DKIM) Service Overview</li> <li><a href="http://tools.ietf.org/html/draft-ietf-dkim-deployment" >draft-ietf-dkim-deployment</a> DomainKeys Identified Mail (DKIM) Development, Deployment and Operations</li> <li><a href="http://ietf.org/html.charters/dkim-charter.html">IETF charter: Domain Keys Identified Mail (DKIM)</a></li> <li><a href="http://www.postfix.org/MILTER_README.html">Postfix before-queue Milter support</a> (original Postfix documentation)</li> <li><a href="http://www.dkim.org/deploy/">DKIM Deployment Reports</a> (at <i>Mutual Internet Practices Association</i> - MIPA)</li> <li><a href="http://jason.long.name/dkimproxy/">Mail::DKIM and dkimproxy</a></li> <li><a href="http://cpan.perl.org/authors/id/J/JA/JASLONG/" >Mail::DKIM</a> module download page at CPAN</li> <li><a href="http://www.opendkim.org/">OpenDKIM</a> (fork from dkim-milter)</li> <li><a href="http://sourceforge.net/projects/dkim-milter/">dkim-milter</a></li> <li>See also: <a href="http://www.arschkrebs.de/postfix/postfix_cisco_pix_bugs.shtml" >Cisco PIX bugs</a> or this <a href="http://www.heise-online.co.uk/security/Cisco-PIX-obstructs-anti-spam-protocol--/news/93725" >heise-online article</a> on handling DKIM-signed mail (the solution is to upgrade PIX to version 7.2(2.19) or 8.0(2.7), or to disable a <i>smtp protocol fixup</i> (mis)feature</li> <li><a href="http://www.rfc-editor.org/rfc/rfc5598.txt">RFC 5598</a>: Internet Mail Architecture</li> <li><a href="http://www.rfc-editor.org/rfc/rfc5451.txt">RFC 5451</a>: Message Header Field for Indicating Message Authentication Status</li> </ul> <hr /> <p> <i><a href="http://www.ijs.si/people/mark/">mm</a></i> <br />Last updated: 2010-10-20 </p> <p> <a href="http://validator.w3.org/check?uri=referer" ><img class="noboarder" src="./valid-xhtml10.png" height="31" width="88" alt="Valid XHTML 1.0!" /></a> </p> </body> </html>