[c5c522c] | 1 | $Id: postfix.txt,v 1.0 2009/11/15 20:29:15 sbajic Exp $ |
---|
| 2 | |
---|
| 3 | POSTFIX INTEGRATION |
---|
| 4 | |
---|
| 5 | Please follow the instructions in the README for building DSPAM. Once DSPAM |
---|
| 6 | has been built, the following instructions may be used to integrate it with |
---|
| 7 | Postfix. |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | INTEGRATING DSPAM AS A CONTENT FILTER |
---|
| 11 | |
---|
| 12 | The most seamless way to integrate DSPAM into Postfix is as a content filter. |
---|
| 13 | This requires very little work, and allows the two to communicate seamlessly. |
---|
| 14 | You may want to first read Postfix's FILTER_README from the Postfix source tree |
---|
| 15 | or online at http://www.postfix.org/FILTER_README.html to familiarize yourself |
---|
| 16 | with what we're doing. In a nutshell, Postfix sends all mail to the content |
---|
| 17 | filter instead of delivering it. It's the content filter's job to then pass |
---|
| 18 | the [modified] message back into Postfix (called reinjection) or do something |
---|
| 19 | else with the message. By default, DSPAM will quarantine what it believes is |
---|
| 20 | spam, but it can be configured to tag it instead. We will use DSPAM's LMTP and |
---|
| 21 | SMTP functionality to integrate the two seamlessly together like so: |
---|
| 22 | |
---|
| 23 | [Postfix] (LMTP) -> [DSPAM] [Postfix] -> { Delivery } |
---|
| 24 | |___ (SMTP Reinjection) ____| |
---|
| 25 | |
---|
| 26 | Step 1: Configure DSPAM as a server daemon |
---|
| 27 | |
---|
| 28 | The first step is to configure DSPAM to listen as an LMTP server on a local |
---|
| 29 | UNIX socket. This is what Postfix will connect to when it sends messages to |
---|
| 30 | DSPAM. Be sure you have configured DSPAM with the --enable-daemon option. |
---|
| 31 | You will need to use an MT-safe storage driver, such as MySQL or PostgreSQL. |
---|
| 32 | Once you have DSPAM installed, make the following changes in dspam.conf: |
---|
| 33 | |
---|
| 34 | ServerMode auto |
---|
| 35 | ServerParameters "--deliver=innocent" |
---|
| 36 | ServerIdent "localhost.localdomain" |
---|
| 37 | ServerPID /var/run/dspam.pid |
---|
| 38 | ServerDomainSocketPath "/tmp/dspam.sock" |
---|
| 39 | |
---|
| 40 | This will tell DSPAM to listen on /tmp/dspam.sock using the options above. |
---|
| 41 | |
---|
| 42 | You'll also need to configure DSPAM to pass the good mail back into Postfix. |
---|
| 43 | Comment out any "TrustedDeliveryAgent" option in dspam.conf and replace it |
---|
| 44 | with the options below. We'll use local TCP port 10026 in our example. |
---|
| 45 | |
---|
| 46 | DeliveryHost 127.0.0.1 |
---|
| 47 | DeliveryPort 10026 |
---|
| 48 | DeliveryIdent localhost |
---|
| 49 | DeliveryProto SMTP |
---|
| 50 | |
---|
| 51 | This tells DSPAM to deliver using SMTP to port 10026 on the local machine. |
---|
| 52 | We'll configure Postfix to listen on this port for reinjection. |
---|
| 53 | |
---|
| 54 | Finally, you'll want to use DSPAM's ParseToHeader option. This option tells |
---|
| 55 | DSPAM to automatically train when it sees a spam- or notspam- address in |
---|
| 56 | the To: header. Depending on how you have configured DSPAM to manage users, |
---|
| 57 | your settings may be slightly different. On a typical setup, where the |
---|
| 58 | entire email address is the user's DSPAM username, you would use something |
---|
| 59 | like this: |
---|
| 60 | |
---|
| 61 | ParseToHeaders on |
---|
| 62 | ChangeModeOnParse on |
---|
| 63 | ChangeUserOnParse full |
---|
| 64 | |
---|
| 65 | This means if a user forwards their spam to spam-bob@example.org, the |
---|
| 66 | username will be set to bob@example.org and the training mode will be set to |
---|
| 67 | "learn spam". |
---|
| 68 | |
---|
| 69 | You can then start DSPAM: dspam --daemon & |
---|
| 70 | |
---|
| 71 | Step 2: Configure Postfix to use a content filter |
---|
| 72 | |
---|
| 73 | The next step is to configure Postfix to use DSPAM as a content filter. |
---|
| 74 | This is relatively simple and requires only a minor change to your |
---|
| 75 | master.cf file: |
---|
| 76 | |
---|
| 77 | Change: |
---|
| 78 | |
---|
| 79 | smtp inet n - n - - smtpd |
---|
| 80 | |
---|
| 81 | To: |
---|
| 82 | |
---|
| 83 | smtp inet n - n - - smtpd |
---|
| 84 | -o content_filter=lmtp:unix:/tmp/dspam.sock |
---|
| 85 | |
---|
| 86 | This tells Postfix to send all mail to DSPAM for content filtering. |
---|
| 87 | |
---|
| 88 | If your Postfix installation is chrooted (as eg. the default Postfix |
---|
| 89 | configuration in Debian GNU/Linux), make sure the socket is located |
---|
| 90 | within the chroot (eg. /var/spool/postfix/var/run/dspam/dspam.sock). |
---|
| 91 | |
---|
| 92 | Make sure the user under which dspam runs has write access to the |
---|
| 93 | socket directory. |
---|
| 94 | |
---|
| 95 | You can also change Postfix configuration so that it does not run |
---|
| 96 | chrooted (both smtp and lmtp services should be modified as follows: |
---|
| 97 | |
---|
| 98 | smtp inet n - n - - smtpd |
---|
| 99 | -o content_filter=lmtp:unix:/var/run/dspam/dspam.sock |
---|
| 100 | lmtp inet n - n - - smtpd |
---|
| 101 | |
---|
| 102 | The 3rd dash specifies if the process will run chrooted or not. |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | If your SMTP server is also used as a relay, and you want DSPAM to |
---|
| 106 | only inspect incoming mail, you can use the following as an alternative |
---|
| 107 | to the pure content filtering method: |
---|
| 108 | |
---|
| 109 | You will need Postfix support for PCRE maps (perl compatible regular |
---|
| 110 | expression). |
---|
| 111 | |
---|
| 112 | In Postfix main.cf, add the following to your smtpd_recipient_restrictions: |
---|
| 113 | |
---|
| 114 | smtpd_recipient_restrictions = |
---|
| 115 | [...] |
---|
| 116 | check_recipient_access pcre:/etc/postfix/dspam_filter_access |
---|
| 117 | |
---|
| 118 | where dspam_filter_access contains: |
---|
| 119 | |
---|
| 120 | /./ FILTER dspam:dspam |
---|
| 121 | |
---|
| 122 | Add he following service at the end of master.cf: |
---|
| 123 | |
---|
| 124 | dspam unix - n n - - pipe |
---|
| 125 | flags=Ru user=dspam argv=/usr/bin/dspam |
---|
| 126 | --client |
---|
| 127 | --deliver=innocent,spam |
---|
| 128 | --user ${recipient} |
---|
| 129 | --mail-from=${sender} |
---|
| 130 | |
---|
| 131 | You will also have to add the following line in main.cf: |
---|
| 132 | dspam_destination_recipient_limit = 1 |
---|
| 133 | |
---|
| 134 | |
---|
| 135 | Step 3: Configure a reinjection port |
---|
| 136 | |
---|
| 137 | You'll also need to configure Postfix to listen on a local port for |
---|
| 138 | reinjection. This is where DSPAM sends back the "good" mail (or alternatively, |
---|
| 139 | tagged mail also). Add this to your master.cf: |
---|
| 140 | |
---|
| 141 | localhost:10026 inet n - n - - smtpd |
---|
| 142 | -o content_filter= |
---|
| 143 | -o receive_override_options=no_unknown_recipient_checks,no_header_body_checks |
---|
| 144 | -o smtpd_helo_restrictions= |
---|
| 145 | -o smtpd_client_restrictions= |
---|
| 146 | -o smtpd_sender_restrictions= |
---|
| 147 | -o smtpd_recipient_restrictions=permit_mynetworks,reject |
---|
| 148 | -o mynetworks=127.0.0.0/8 |
---|
| 149 | -o smtpd_authorized_xforward_hosts=127.0.0.0/8 |
---|
| 150 | |
---|
| 151 | Any mail sent to localhost:10026 will be delivered in whatever way you |
---|
| 152 | have configured Postfix, without being passed through DSPAM again. This is |
---|
| 153 | also where DSPAM will deliver false positives to when they are retrained by |
---|
| 154 | the user. |
---|
| 155 | |
---|
| 156 | You're now good to go! Turn on Postfix and do a little testing. Send a message |
---|
| 157 | to yourself on port 25. It should have X-DSPAM headers. Send a message to |
---|
| 158 | yourself on port 10026. It should not. |
---|
| 159 | |
---|
| 160 | If you are deadset against running DSPAM as a server daemon, this design can |
---|
| 161 | be changed to call DSPAM via commandline, and have DSPAM reinject by calling |
---|
| 162 | Postfix's sendmail function. I wouldn't recommend this, but here's how. |
---|
| 163 | Instead of configuring DSPAM's DeliveryHost and Server options, you'll want to |
---|
| 164 | configure DSPAM to call sendmail to deliver mail: |
---|
| 165 | |
---|
| 166 | TrustedDeliveryAgent /usr/sbin/sendmail |
---|
| 167 | Trust postfix |
---|
| 168 | |
---|
| 169 | Use the same ParseToHeader options already outlined above. Next, instead of |
---|
| 170 | having Postfix pass the message to DSPAM via LMTP, you can use: |
---|
| 171 | |
---|
| 172 | smtp inet n - n - - smtpd |
---|
| 173 | -o content_filter=dspam: |
---|
| 174 | |
---|
| 175 | dspam unix - n n - 10 pipe |
---|
| 176 | flags=Ruq user=vmail argv=/usr/local/bin/dspam |
---|
| 177 | --deliver=innocent |
---|
| 178 | --user ${recipient} |
---|
| 179 | -i -f ${sender} -- ${recipient} |
---|
| 180 | |
---|
| 181 | To avoid users getting a message multiple times when the message contains |
---|
| 182 | more then one recipient you need to lower the concurrency limit for the |
---|
| 183 | above mentioned Postfix pipe service to 1. Add this to your main.cf: |
---|
| 184 | |
---|
| 185 | dspam_destination_recipient_limit = 1 |
---|
| 186 | |
---|
| 187 | |
---|
| 188 | INTEGRATING DSPAM AS A DELIVERY PROXY |
---|
| 189 | |
---|
| 190 | Postfix can optionally be configured to integrate with DSPAM as a delivery |
---|
| 191 | proxy if you're using a third party delivery agent for final delivery to |
---|
| 192 | your mailbox. |
---|
| 193 | |
---|
| 194 | The first step in getting DSPAM to work is to get mail delivery to work with |
---|
| 195 | one of these external LDAs before integrating DSPAM with Postfix. |
---|
| 196 | |
---|
| 197 | You can configure DSPAM with the appropriate LDA using --with-delivery-agent= |
---|
| 198 | at configure time or by specifying TrustedDeliveryAgent in dspam.conf. |
---|
| 199 | For example: |
---|
| 200 | |
---|
| 201 | TrustedDeliveryAgent "/usr/bin/procmail" |
---|
| 202 | |
---|
| 203 | You'll also want to configure the untrusted delivery agent in a similar |
---|
| 204 | fashion: |
---|
| 205 | |
---|
| 206 | UntrustedDeliveryAgent "/usr/bin/procmail -d %u" |
---|
| 207 | |
---|
| 208 | If you are using maildrop, you'll need to be sure you've compiled maildrop to |
---|
| 209 | trust the user that DSPAM is running as. |
---|
| 210 | |
---|
| 211 | Once you have configured a local delivery agent into DSPAM, the simplest way |
---|
| 212 | to configure Postfix for local users is to set the mailbox_command directive |
---|
| 213 | to point to DSPAM. This can be done by editing /etc/postfix/main.cf: |
---|
| 214 | |
---|
| 215 | mailbox_command = /usr/local/bin/dspam --deliver=innocent --user $USER -- -d %u |
---|
| 216 | |
---|
| 217 | If you're running a delivery agent (such as Cyrus deliver) that has a problem |
---|
| 218 | with the top 'From' header, you may need to perform some sed magic: |
---|
| 219 | |
---|
| 220 | mailbox_command = sed '1{/^From /d;}' | /usr/local/bin/dspam --deliver=innocent --user $USER -- -d %u |
---|
| 221 | |
---|
| 222 | Now, configure the aliases as prescribed in the README and you're good to go! |
---|
| 223 | |
---|
| 224 | |
---|
| 225 | CYRUS INTEGRATION |
---|
| 226 | |
---|
| 227 | If you're using Cyrus to deliver mail locally, you'll want to specify the |
---|
| 228 | following in dspam.conf: |
---|
| 229 | |
---|
| 230 | TrustedDeliveryAgent "/usr/cyrus/bin/deliver $u" |
---|
| 231 | |
---|
| 232 | Then use the following in Postfix: |
---|
| 233 | |
---|
| 234 | mailbox_command = /usr/local/bin/dspam --user ${user} --deliver=innocent |
---|
| 235 | |
---|