- Basic Postfix Configuration
- Supporting Virtual Domains
- Supporting External or Mobile Users
- Summary
Supporting External or Mobile Users
One problem that many administrators face is supporting external and mobile email users. The problem of supporting those remote users stems from one of the basic assumptions used to stop Unsolicited Commercial Email (UCE). UCE, commonly known as SPAM, is the bane of email and the Internet. Although some ISPs allow their customers to use their email servers to send UCE, most do not. Many spammers will search for email servers that are misconfigured to allow anyone, including the spammers, to send email from anywhere to any destination address, not just those the email server is responsible for. This misconfiguration is known as an "open-relay" because you are relaying email to their final destination for anyone, not just your trusted users.
The basic premise of preventing UCE works like this:
Your email server knows what domains it is to receive email for, and will gladly do so from anywhereinternal trusted users or any IP address reachable on the Internet.
Your email server is configured to know your internal trusted networks, and will gladly receive email to any destination on the Internet, as long as the client machine came from a trusted source. The email server will then speed the messages along to their final destinations on your internal trusted users' behalf.
Any email that is not destined for a domain serviced by your email server, and not originating from a trusted source, will be rejected.
The problem then is this: How does one identify trusted users to the mail server? These users might be in a different branch location, and thus using a different network address. They may be telecommuting users who have cable modems or DSL, and are either statically assigned or dynamically assigned IP addresses. They may be roaming users who are dialing up through their local or global ISP. Each of these problems can be addressed in many ways. Let's look at several common scenarios.
Remote Users with Fixed IP Addresses
Remote users, or offices, with a fixed IP address can be addressed by simply adding their IP address to an access table. Remember that Postfix's configuration files are modular, so you can simply add or remove IP addresses to access tables on an as-needed basis. There is no need to stop and restart your Postfix mail server, and the access table file can easily be distributed to multiple Postfix relays.
Although certainly not secure, there is a way you can support users without fixed IP addresses. In the Postfix access table you can also specify DNS domain names of your user's ISPs. Specifying a domain name allows any reverse resolvable IP from that ISP to effectively use your email server. While this may solve a problem, it opens the potential for many more serious problems, and is generally not a recommended way to configure Postfix.
The advantages of configuring your Postfix MTA to use the simple access table method are as follows:
You do not impact the users; they continue to use their clients as they would locally.
It is easy to bring whole offices on-line simply by adding their network address space or external firewall proxy address.
You do not expose usernames and passwords in the clear over the Internet.
There are several disadvantages, which may or may not concern you in your deployment situation:
There is no actual authentication of users to your mail server, so anyone sitting at those IP addresses or remote offices could use your mail server unhindered.
IP addresses are easy to spoof, so therefore not a strong method of identifying a remote identity.
If the lookup table contains whole ISP networks for dial-up users, any user from that ISP can use your email server as an open relay.
It may create additional administrative work to keep the access table up-to-date.
Implementing the client access table method in Postfix is quite simple. First, create or edit a file called client_access. This file will contain the IP address or DNS domain name of the host or network you want to relay mail for, followed by an action. Actions, if you recall from the first article in this series, are the measures that Postfix takes on a pattern match. We could specify whether to explicitly accept (OK) or deny (REJECT) clients or ISPs.
/etc/postfix/client_access: 4.3.2.1 OK bigisp.com OK
After you have created the client_access file, remember to issue the postmap command to convert it to a database table.
Next, edit your main.cf configuration file to set smtpd_recipient_restrictions. Normally, you would allow trusted networks using the permit_mynetworks directive, and check_relay_domains for domains you wish to relay to for untrusted clients. Add the check_client_access parameter, and specify a hash map type (the hash: part) with the actual lookup table name and location:
/etc/postfix/main.cf: smtpd_recipient_restrictions = permit_mynetworks check_client_access hash:/etc/postfix/client_access check_relay_domains
You can specify a different database format, such as dbm or btree, instead of hash if your system has those access methods available to you. Just be certain to create the database lookup table using the same method using the postmap command.
Finally, you need to tell the running Postfix processes about your configuration change. Simply type postfix reload as root-level admin, and the Postfix processes will reread the configuration file.
You should now have a Postfix configured to allow remote offices and telecommuting users to send email through your email server. But how can those concerns in the list of cons be addressed?
Authenticating the Sender
One way of allowing roaming users (and even users in remote locations) to use the email servers is to have the users be authenticated somehow.
A very easy way, although not recommended, is to authenticate the email based on the sender address. The process basically scans the email headers looking for a valid sender address. This address is then compared to a list of addresses that are allowed to relay email.
Hopefully, you can immediately see the problems with this approach: It is trivial to forge email messages, and therefore spoof a sender's address; and it also creates additional administrative burdens by keeping the sender address lookup table in sync with users within the organization.
Implementing the sender access table method in Postfix is quite similar to implementing the client access table authentication. First, create or edit a file called sender_access. This file will contain the email address of the sender you want to enable email relaying for.
/etc/postfix/sender_access: user1@domain.com OK user2@domain.com OK
Again, convert the text file into a database lookup table using the postmap command.
Next, edit your main.cf configuration file to set smtpd_recipient_restrictions. Add the check_sender_access parameter, and specify a hash map type (the hash: part) with the actual lookup table name and location.
/etc/postfix/main.cf: smtpd_recipient_restrictions = permit_mynetworks check_client_access hash:/etc/postfix/client_access check_sender_access hash:/etc/postfix/sender_access check_relay_domains
Finally, type postfix reload to put the new configuration file into effect.
POP-before-SMTP
A more effective method is to have the user authenticate first to the mail server using an actual account name and password. That is tougher to spoof and impersonate. Not impossible, but certainly harder.
There are several different methods available that are listed on the Postfix Add-on's page (http://www.postfix.org/addon.html).
The least invasive, and easiest to install and set up is POP-before-SMTP (http://people.oven.com/bet/pop-before-smtp/), written by Bennett Todd. POP-before-SMTP is a daemon written in the Perl scripting language that watches the system logs for clients that pull their email via POP or IMAP. After the script sees a successful authenticated login, it logs that IP address into a database that is readable by Postfix. After a specified interval, say 30 minutes after the last successful POP/IMAP login, the IP address is expired. The main drawback to POP-before-SMTP is that both the script and POP/IMAP daemons must run on the same server as Postfix.
DRAC (http://mail.cc.umanitoba.ca/drac/index.html), written by J. Gary Mills, is a daemon that dynamically updates a relay authorization map. This map is also in a readable format by Postfix.
Like POP-before-SMTP, the user's IP addresses are added to the map after they have successfully authenticated to the POP/IMAP server. Unlike POP-before-SMTP, DRAC needs to be patched into supporting POP/IMAP servers, so you must be comfortable with getting source, patching it, and compiling it with the appropriate configuration settings.
However, because the actual source of the POP/IMAP servers has been changed, they now know how to update the DRAC daemon on the various SMTP servers. This allows the POP/IMAP and SMTP servers to be on different machines. For highly customized environments that have multiple servers to handle the volume, this method provides a more scalable solution.
To support DRAC, the Postfix configuration would then be modified as such:
/etc/postfix/main.cf: smtpd_recipient_restrictions = permit_mynetworks check_client_access btree:/etc/postfix/dracd check_relay_domains
Notice that DRAC uses the btree indexing method on its database maps. You must make sure that your Postfix installation supports the btree map method as well.
RFC-2554, or SMTP Authentication
POP/IMAP authentication prior to sending SMTP email is fine for 90% of the instances. However you will occasionally come across those users, or situations, where POP/IMAP before sending does not work. Specifically if you have automated processes that need to send email in response to monitoring needs, for example. How can you authenticate your clients to your SMTP server?
SMTP Authentication is defined in RFC-2554 (http://www.rfc-editor.org/rfc/rfc2554.txt), and has been working in Postfix since experimental release 20000314, although it is recommended you use the newest snapshot or official releases.
SMTP requires that you install SASL, the Simple Authentication and Security Layer, as a prerequisite to compiling Postfix. So let's talk first about SASL.
SASL
SASL, the Simple Authentication and Security Layer, is defined in the base RFC-2222 (http://www.rfc-editor.org/rfc/rfc2222.txt). Cyrus SASL (http://asg.web.cmu.edu/sasl/) is a Postfix-supported implementation written by the Project Cyrus team at Carnegie Mellon University. Cyrus SASL v1.5.5 or newer is required to work with Postfix.
Your distribution may already come with the appropriate Cyrus SASL libraries, but if not, you can retrieve the source from ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/, and compile it yourself. Note that if you are compiling yourself, and you must support Microsoft clients and then you must configure Cyrus SASL with --enable-login to force building with the non-standard LOGIN authentication method.
After you have successfully installed the Cyrus SASL libraries, you must properly configure it to the method you will be using to authenticate your uses. Cyrus-SASL uses the /usr/local/lib/sasl/smtpd.conf file for this purpose.
If you plan on authenticating users to your UNIX passwd database, and you are not using Pluggable Authentication Modules (PAM), you must use the Cyrus SASL pwcheck daemon.
/usr/local/lib/sasl/smtpd.conf: pwcheck_method: pwcheck
If you plan on authenticating users to Cyrus-SASL's own databaseespecially useful if you are using the Cyrus mail system for POP/IMAP accessyou must configure the pwcheck method to use the sasldb:
/usr/local/lib/sasl/smtpd.conf: pwcheck_method: sasldb
Pluggable Authentication Modules (PAM), are generally available on most modern UNIX-like variants such as GNU/Linux, Solaris, and HP-UX. PAM can be used to authenticate against many sources, UNIX passwd database, Windows domain controllers on a WinNT/Win2K network, to NIS servers, Kerberos, LDAP, and MySQL databases. After you have your PAM authentication configuration working, you can tell your SMTP servers to authenticate in the same manner. In order to authenticate against PAM:
/usr/local/lib/sasl/smtpd.conf: pwcheck_method: PAM
After you have properly compiled, installed, and configured the Cyrus SASL libraries, you must compile Postfix with SASL support; otherwise, it will whine about being misconfigured in your system logs and not authenticate your roaming users. Compiling Postfix with SASL support is done by running the make command-line with the following arguments (assuming your SASL installation lives in /usr/local/):
make makefiles CCARGS="-DUSE_SASL_AUTH -I/usr/local/include" \ AUXLIBS="-L/usr/local/lib -lsasl"
A more detailed description of using Postfix with SASL can be found in the SASL_README file included in the Postfix source archive.
Unfortunately, the default builds for Debian and the BSD platforms do not include SASL support by default. The Debian package will need to be rebuilt from the source .deb, whereas the BSD packages will need to be built with the SASL flavor.
Making Postfix Do SMTP AUTH
Not to make light of the machinations that must be overcome to get Cyrus-SASL installed and Postfix configured to properly make use of it, but the rest is a cakewalk.
To turn on SMTP authentication in Postfix, simply add the following lines to your main.cf, some of which are already there:
/etc/postfix/main.cf: smtpd_sasl_auth_enable = yes smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, check_relay_domains
Remember the broken Microsoft clients that we enabled explicit support for in the SASL libraries? Well, older Microsoft SMTP client software implements a non-standard version of the AUTH protocol syntax, and expects that the SMTP server replies to EHLO with
250-AUTH=GSSAPI LOGIN PLAIN
instead of
250-AUTH GSSAPI LOGIN PLAIN
Note that the difference is the equal sign between AUTH and the available AUTH methods. To work around such broken but significantly deployed clients, Postfix has a specific configuration directive you must enable. Edit or add the following line to the main.cf file to support Microsoft mail clients:
/etc/postfix/main.cf: broken_sasl_auth_clients = yes