[c5c522c] | 1 | $Id: relay.txt,v 1.0 2009/11/15 20:39:01 sbajic Exp $ |
---|
| 2 | |
---|
| 3 | Configuring DSPAM as a seamless front-end relay using Postfix |
---|
| 4 | |
---|
| 5 | This HOWTO explains how to set up DSPAM as a front-end relay. Using this |
---|
| 6 | configuration, you can point your MX records to the DSPAM server and |
---|
| 7 | then have DSPAM pass along any valid email to your mail server. The example |
---|
| 8 | provided also provides personalized training for each user it is protecting, |
---|
| 9 | even if users have multiple email aliases. This allows you to create more than |
---|
| 10 | just a dumb gateway server, but something smart enough to learn each user's |
---|
| 11 | mail. You may either account for all addresses behind your mail server (to |
---|
| 12 | ward off dictionary attacks) or configure pass-thru for unprovisioned users |
---|
| 13 | on the system to lighten the work load by provisioning only users who want |
---|
| 14 | filtering. |
---|
| 15 | |
---|
| 16 | When configuring DSPAM as a relay, it's generally a good idea to set |
---|
| 17 | up DSPAM on its own server. Therefore, we will assume you've got a fresh server |
---|
| 18 | running *NIX with an existing MySQL 4.1+ installation (you'll want at least |
---|
| 19 | 4.1.12 to avoid some nasty bugs in MySQL which affect DSPAM). |
---|
| 20 | |
---|
| 21 | Step 1: Configure, compile and install Postfix with MySQL support |
---|
| 22 | |
---|
| 23 | To do this, you'll need to init a set of makefiles including the path to your |
---|
| 24 | MySQL includes and libraries... |
---|
| 25 | |
---|
| 26 | make -f Makefile.init makefiles \ |
---|
| 27 | 'CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include' \ |
---|
| 28 | 'AUXLIBS=-L/usr/local/mysql/lib -lmysqlclient -lz -lm' |
---|
| 29 | |
---|
| 30 | Then simply |
---|
| 31 | |
---|
| 32 | make && make install |
---|
| 33 | |
---|
| 34 | Step 2: Configure, compile and install DSPAM with daemon + MySQL support |
---|
| 35 | |
---|
| 36 | You'll need the following options: |
---|
| 37 | MySQL |
---|
| 38 | Virtual Users |
---|
| 39 | Daemon mode |
---|
| 40 | |
---|
| 41 | It may also be a good idea to enable: |
---|
| 42 | Preferences extension |
---|
| 43 | Debug |
---|
| 44 | |
---|
| 45 | For example: |
---|
| 46 | |
---|
| 47 | ./configure --with-storage-driver=mysql_drv \ |
---|
| 48 | --with-mysql-libraries=/usr/local/mysql/lib \ |
---|
| 49 | --with-mysql-includes=/usr/local/mysql/include \ |
---|
| 50 | --enable-virtual-users \ |
---|
| 51 | --enable-preferences-extension \ |
---|
| 52 | --enable-daemon |
---|
| 53 | |
---|
| 54 | Step 3: Install DSPAM MySQL Objects (With a twist) |
---|
| 55 | |
---|
| 56 | Create the MySQL objects as outlined in the MySQL DSPAM doc, but use the |
---|
| 57 | virtual_user_aliases.sql script instead of virtual-users.sql script to create |
---|
| 58 | a table without a primary key. This will allow you to create multiple email |
---|
| 59 | addresses with the same uid, which is how DSPAM recognizes users. |
---|
| 60 | |
---|
| 61 | Step 4: Configure DSPAM to receive LMTP and delivery SMTP |
---|
| 62 | |
---|
| 63 | We're going to configure Postfix to connect to DSPAM via LMTP using a domain |
---|
| 64 | socket. The following configuration properties should be set in dspam.conf: |
---|
| 65 | |
---|
| 66 | ServerQueueSize 32 |
---|
| 67 | ServerPID /var/run/dspam.pid |
---|
| 68 | ServerMode standard |
---|
| 69 | ServerParameters "--deliver=innocent" |
---|
| 70 | ServerIdent "localhost.localdomain" |
---|
| 71 | ServerDomainSocketPath /tmp/dspam.sock |
---|
| 72 | |
---|
| 73 | You'll also want to use the following ParseToHeader parameters: |
---|
| 74 | |
---|
| 75 | ParseToHeaders on |
---|
| 76 | ChangeModeOnParse on |
---|
| 77 | ChangeUserOnParse off |
---|
| 78 | |
---|
| 79 | This prevents Postfix from needing to use any aliases for retraining. When |
---|
| 80 | users email spam-name@example.org, DSPAM will automatically realize that it |
---|
| 81 | needs to retrain the message. I'll explain how to set this up in a bit. |
---|
| 82 | |
---|
| 83 | Step 5: Configure Postfix to use DSPAM + virtual UIDs table |
---|
| 84 | |
---|
| 85 | The following is a sample configuration that will tell Postfix to use DSPAM |
---|
| 86 | as its virtual transport (passing all mail to DSPAM via LMTP) and to use the |
---|
| 87 | dspam_virtual_uids table as its source for mailbox aliases. You can build on |
---|
| 88 | this and add MySQL support for virtual_mailbox_domains, but you'll need to |
---|
| 89 | maintain your own database table for that. |
---|
| 90 | |
---|
| 91 | virtual_transport = lmtp:unix:/tmp/dspam.sock |
---|
| 92 | virtual_mailbox_domains = example.org |
---|
| 93 | virtual_mailbox_maps = mysql:/etc/postfix/vmailbox.cf |
---|
| 94 | |
---|
| 95 | vmailbox.cf should look something like: |
---|
| 96 | user = [MySQL username] |
---|
| 97 | password = [MySQL password] |
---|
| 98 | dbname = [MySQL db] |
---|
| 99 | hosts = [unix:/path/to/mysqld.sock] or [host:ip-address:port] |
---|
| 100 | |
---|
| 101 | # Postfix < 2.2 |
---|
| 102 | table = dspam_virtual_uids |
---|
| 103 | select_field = username |
---|
| 104 | where_field = username |
---|
| 105 | additiona_conditions = |
---|
| 106 | |
---|
| 107 | # Postfix >= 2.2 |
---|
| 108 | query = SELECT username FROM dspam_virtual_uids WHERE username='%s' |
---|
| 109 | |
---|
| 110 | Step 6: Add a localStore preference for each user |
---|
| 111 | |
---|
| 112 | The localStore preference defines the web directory name for each user (for |
---|
| 113 | the WebUI). Since users might have multiple email addresses, you want to avoid |
---|
| 114 | having a directory for each alias. You can do this by setting their web |
---|
| 115 | directory to match their uid. |
---|
| 116 | |
---|
| 117 | To do this, you'll first need to allow the localStore override in dspam.conf: |
---|
| 118 | |
---|
| 119 | AllowOverride localStore |
---|
| 120 | |
---|
| 121 | Next, set the localStore preference for that user to their uid or some other |
---|
| 122 | unique identifier: |
---|
| 123 | |
---|
| 124 | dspam_admin change preference john.doe@example.org localStore 1 |
---|
| 125 | |
---|
| 126 | Now, whenever any address pertaining to this user is emailed, information |
---|
| 127 | will be stored in DSPAM_HOME/data/1 |
---|
| 128 | |
---|
| 129 | Step 7: Configure user aliases for dspam_virtual_uids |
---|
| 130 | |
---|
| 131 | Postfix is now set up to do a lookup in dspam_virtual_uids. It _must_ find a |
---|
| 132 | valid address in this table in order to accept the message. What you'll need |
---|
| 133 | to do now is to create email addresses (and spam addresses) in this table |
---|
| 134 | for each user behind your mail server. You will need to assign any aliases |
---|
| 135 | under the same UID, and you'll also need to create a spam alias in this |
---|
| 136 | table. For example: |
---|
| 137 | |
---|
| 138 | UID Username |
---|
| 139 | 1 john.doe@example.org |
---|
| 140 | 1 spam-john.doe@example.org |
---|
| 141 | 1 john@example.org <- An alias |
---|
| 142 | 1 jd@example.org <- Another alias |
---|
| 143 | |
---|
| 144 | When any of these destination addresses is specified, DSPAM will process |
---|
| 145 | mail under the same user so that only one database is used for all of these |
---|
| 146 | addresses. You can create as many aliases as you like, and in fact should |
---|
| 147 | probably write a script to pull this from your existing production system. |
---|
| 148 | |
---|
| 149 | Congratulations! You're now set up. You can start DSPAM using dspam --daemon. |
---|
| 150 | You might want to run with verbose debug to test and ensure everything is |
---|
| 151 | working properly. |
---|
| 152 | |
---|
| 153 | GLOBAL DATABASES |
---|
| 154 | |
---|
| 155 | If you're thinking about going with a global database, I strongly recommend |
---|
| 156 | using merged groups + TOE instead of a single global group. To do this, just |
---|
| 157 | follow the README directions for setting one up and leave everything the way |
---|
| 158 | it is. If, however, you insist on a single global group, you'll need to make |
---|
| 159 | one change to dspam.conf to accomodate this configuration. Add |
---|
| 160 | --user [globaluser] to your ServerParameters property. This will cause all |
---|
| 161 | mail to be processed using this user, but will still deliver using the |
---|
| 162 | recipient information. |
---|
| 163 | |
---|
| 164 | ALIASES |
---|
| 165 | |
---|
| 166 | If you have some aliases, you'll need to also set them up on your relay |
---|
| 167 | so that DSPAM can process the individual users. To do this, add the |
---|
| 168 | following lines to Postfix's main.cf: |
---|
| 169 | |
---|
| 170 | virtual_alias_domains = |
---|
| 171 | virtual_alias_maps = mysql:/etc/postfix/valiases.cf |
---|
| 172 | |
---|
| 173 | now create a valiases.cf similar to vmailbox.cf, only you'll want to create |
---|
| 174 | a new table just for aliases. the field pulled from should be a list of |
---|
| 175 | recipient addresses, for example: |
---|
| 176 | |
---|
| 177 | list@example.org john@example.org,bob@example.org |
---|
| 178 | |
---|
| 179 | Postfix will now deliver to each of these mailboxes instead of an alias address. |
---|