Blame SOURCES/README-Postfix-SASL-RedHat.txt

8c23a1
Quick Start to Authenticate with SASL and PAM:
8c23a1
----------------------------------------------
8c23a1
8c23a1
If you don't need the details and are an experienced system
8c23a1
administrator you can just do this, otherwise read on.
8c23a1
8c23a1
1) Edit /etc/postfix/main.cf and set this:
8c23a1
8c23a1
smtpd_sasl_auth_enable = yes
8c23a1
smtpd_sasl_security_options = noanonymous
8c23a1
broken_sasl_auth_clients = yes
8c23a1
8c23a1
smtpd_recipient_restrictions = 
8c23a1
  permit_sasl_authenticated,
8c23a1
  permit_mynetworks,
8c23a1
  reject_unauth_destination
8c23a1
8c23a1
2) Turn on saslauthd:
8c23a1
8c23a1
   /sbin/chkconfig --level 345 saslauthd on
8c23a1
   /sbin/service saslauthd start
8c23a1
8c23a1
3) Edit /etc/sysconfig/saslauthd and set this:
8c23a1
8c23a1
   MECH=pam
8c23a1
8c23a1
4) Restart Postfix:
8c23a1
8c23a1
   /sbin/service postfix restart
8c23a1
8c23a1
A crash course in using SASL with Postfix:
8c23a1
------------------------------------------
8c23a1
8c23a1
Red Hat's Postfix RPMs include support for both SASL and TLS.  SASL, the
8c23a1
Simple Authentication and Security Layer, allows Postfix to implement RFC
8c23a1
2554, which defines an extension to ESMTP, SMTP AUTH, which compliant
8c23a1
ESMTP clients can use to authenticate themselves to ESMTP servers.
8c23a1
Typically, this is used to allow roaming users to relay mail through a
8c23a1
server safely without configuring the SMTP server to be an open relay.
8c23a1
Inclusion of TLS support allows Postfix to implement RFC 2487, which
8c23a1
defines an extension to ESMTP, SMTP STARTTLS, which compliant ESMTP
8c23a1
clients and servers can use to encrypt the SMTP session.  This is a
8c23a1
security enhancement -- normally SMTP is transmitted as cleartext over the
8c23a1
wire, making it vulnerable to both passive sniffing and active alteration
8c23a1
via monkey-in-the-middle attacks.  In addition, STARTTLS can also be
8c23a1
used by either or both server and client to verify the identity of the
8c23a1
other end, making it useful for the same sorts of purposes as SMTP AUTH.
8c23a1
The two can even be combined.  Typically, this is done by first starting
8c23a1
TLS, to encrypt the SMTP session, and then issuing the SMTP AUTH command,
8c23a1
to authenticate the client; this combination ensures that the username
8c23a1
and password transferred as part of the SMTP AUTH are protected by the
8c23a1
TLS encrypted session.
8c23a1
8c23a1
SMTP AUTH is implemented using SASL, an abstraction layer which can
8c23a1
authenticate against a variety of sources.  On Red Hat, SASL can use
8c23a1
the /etc/shadow file, or it can use PAM libraries, or it can use its own
8c23a1
password database (/etc/sasldb), or it can do various more exotic things.
8c23a1
8c23a1
Authentication raises a number of security concerns for obvious
8c23a1
reasons. As a consequence authentication services on Red Hat systems
8c23a1
are restricted to processes running with root privileges. However for
8c23a1
security reasons it is also essential that a mail server such as
8c23a1
Postfix run without root privileges so that mail operations cannot
8c23a1
compromise the host system. This means that Postfix cannot directly
8c23a1
use authentication services because it does not execute with root
8c23a1
privileges. The answer to this this problem is to introduce an
8c23a1
intermediary process that runs with root privileges which Postfix can
8c23a1
communicate with and will perform authentication on behalf of
8c23a1
Postfix. The SASL package includes an authentication daemon called
8c23a1
saslauthd which provided this service, think of it as an
8c23a1
authentication proxy.
8c23a1
8c23a1
Using Saslauthd:
8c23a1
---------------- 
8c23a1
8c23a1
To use saslauthd there are several things you must assure are
8c23a1
configured. 
8c23a1
8c23a1
Selecting an Authentication Method:
8c23a1
-----------------------------------
8c23a1
8c23a1
Recall that it is saslauthd which is authenticating, not
8c23a1
Postfix. To start with you must tell Postfix to use saslauthd, in
8c23a1
main.cf edit this configuration parameter:
8c23a1
8c23a1
   smtpd_sasl_auth_enable = yes
8c23a1
8c23a1
It is also recommended that you disable anonymous logins otherwise
8c23a1
you've left your system open, so also add this configuration
8c23a1
parameter. 
8c23a1
8c23a1
   smtpd_sasl_security_options = noanonymous
8c23a1
8c23a1
Now you must tell saslauthd which authentication method to use. To
8c23a1
determine the authentication methods currently supported by saslauthd
8c23a1
invoke saslauthd with the -v parameter, it will print its version and
8c23a1
its list of methods and then exit, for example:
8c23a1
8c23a1
   /usr/sbin/saslauthd -v
8c23a1
   saslauthd 2.1.10
8c23a1
   authentication mechanisms: getpwent kerberos5 pam rimap shadow 
8c23a1
8c23a1
When saslauthd starts up it reads its configuration options from the
8c23a1
file /etc/sysconfig/saslauthd. Currently there are two parameters
8c23a1
which can be set in this file, MECH and FLAGS. MECH is the
8c23a1
authentication mechanism and FLAGS is any command line flags you may
8c23a1
wish to pass to saslauthd. To tell saslauthd to use a specific
8c23a1
mechanism edit /etc/sysconfig/saslauthd and set the MECH parameter,
8c23a1
for example to use PAM it would look like this:
8c23a1
8c23a1
   MECH=pam
8c23a1
8c23a1
Of course you may use any of the other authentication mechanisms that
8c23a1
saslauthd reported it supports. PAM is an excellent choice as PAM
8c23a1
supports many of the same authentication methods that saslauthd does,
8c23a1
but by using PAM you will have centralized all of your authentication
8c23a1
configuration under PAM which is one of PAM's greatest assets.
8c23a1
8c23a1
How Postfix Interacts with SASL to Name its Authentication Services:
8c23a1
--------------------------------------------------------------------
8c23a1
8c23a1
It can be very helpful to understand how Postfix communicates with
8c23a1
SASL to name its authentication services. Knowing this will let you
8c23a1
identify the configuration files the various components will access.
8c23a1
8c23a1
When Postfix invokes SASL it must give SASL an application name that
8c23a1
SASL will use among other things to locate a configuration file for
8c23a1
the application. The application name Postfix identifies itself as is
8c23a1
"smtpd". SASL will append ".conf" to the application name and look for
8c23a1
a config file in its library and config directories. Thus SASL will
8c23a1
read Postfix's configuration from
8c23a1
8c23a1
   /etc/sasl2/smtpd.conf
8c23a1
8c23a1
This file names the authentication method SASL will use for Postfix
8c23a1
(actually for smtpd, other MTA's such as sendmail may use the same
8c23a1
file). Because we want to use the saslauthd authentication proxy
8c23a1
daemon the contents of this file is:
8c23a1
8c23a1
   pwcheck_method: saslauthd
8c23a1
8c23a1
This tells SASL when being invoked to authentication for Postfix that
8c23a1
it should use saslauthd. Saslauthd's mechanism is set in
8c23a1
/etc/sysconfig/saslauthd (see below).
8c23a1
8c23a1
When Postfix calls on SASL to authenticate it passes to SASL a service
8c23a1
name. This service name is used in authentication method specific
8c23a1
way. The service name Postfix passes to SASL is "smtp" (note this is
8c23a1
not the same as the application name which is "smtpd"). To understand
8c23a1
this better consider the case of using PAM authentication. When SASL,
8c23a1
or in our case saslauthd, invokes PAM it passes the service name of
8c23a1
"smtp" to PAM which means that when PAM wants to read configuration
8c23a1
information for this client it will find it under the name of "smtp". 
8c23a1
8c23a1
Turning on the Authentication Daemon:
8c23a1
-------------------------------------
8c23a1
8c23a1
Red Hat security policy is not to automatically enable services
8c23a1
belonging to a package when the package is installed. The system
8c23a1
administrator must explicitly enable the service. To enable saslauthd
8c23a1
do the following:
8c23a1
8c23a1
1) Tell the init process to launch saslauthd when entering various run
8c23a1
   levels. Assuming you want saslauthd to run at run levels 3,4,5
8c23a1
   invoke chkconfig.
8c23a1
8c23a1
   /sbin/chkconfig --level 345 saslauthd on
8c23a1
8c23a1
2) You will probably want to start saslauthd now without having to
8c23a1
   reboot, to do this:
8c23a1
8c23a1
   /sbin/service saslauthd start
8c23a1
8c23a1
Trouble Shooting Authentication:
8c23a1
--------------------------------
8c23a1
8c23a1
The best way to debug authentication problems is to examine log
8c23a1
messages from the authentication components. However, normally these
8c23a1
log messages are suppressed. There are two principle reasons the
8c23a1
messages are suppressed. The first is that they are typically logged
8c23a1
at the DEBUG logging priority level which is the lowest priority and
8c23a1
the syslog configuration typically logs only higher priority
8c23a1
messages. The second reason is that for security reasons authentication
8c23a1
logging is considered a risk. Authentication logging has been divided
8c23a1
into two different facilities, auth and authpriv. authpriv is private
8c23a1
and is typically shunted off to a different log file with higher
8c23a1
protection. You will want to be able to see both auth and authpriv
8c23a1
messages at all priorities. To do this as root edit /etc/syslog.conf
8c23a1
file, find the following line
8c23a1
8c23a1
authpriv.*					/var/log/secure
8c23a1
8c23a1
edit the line to:
8c23a1
8c23a1
authpriv.*;auth.*				/var/log/secure
8c23a1
8c23a1
Then restart syslogd so the syslog configuration changes will be
8c23a1
picked up:
8c23a1
8c23a1
       /sbin/service syslog restart
8c23a1
8c23a1
Now all authentication messages at all priorities will log to
8c23a1
/var/log/secure. 
8c23a1
8c23a1
Using PAM to Authenticate:
8c23a1
--------------------------
8c23a1
8c23a1
Edit /etc/sysconfig/saslauthd and set MECH to PAM like this:
8c23a1
8c23a1
   MECH=pam
8c23a1
8c23a1
When PAM is invoked via SASL it is passed a service name of
8c23a1
"smtp". This means that PAM will read its configuration parameters for
8c23a1
Postfix from the file: /etc/pam.d/smtp. By default this file is set to
8c23a1
refer to the global system PAM authentication policy, thus by default
8c23a1
you'll get whatever PAM authentication your system is configured for
8c23a1
and virtually all applications use. Configuring PAM authentication is
8c23a1
beyond the scope of this document, please refer to the PAM
8c23a1
documentation if you which to modify PAM.
8c23a1
8c23a1
Trouble Shooting PAM Authentication:
8c23a1
------------------------------------
8c23a1
8c23a1
1) One possible reason PAM may fail to authenticate even if the user
8c23a1
is known to the system is if PAM fails to find the service
8c23a1
configuration file in /etc/pam.d. Service configuration files are not
8c23a1
required by PAM, if it does not find a service configuration file it
8c23a1
will default to "other". Since PAM does not consider the absence of a
8c23a1
service configuration file a problem it does not log anything nor does
8c23a1
it return an error to the calling application. In other words it is
8c23a1
completely silent about the fact it did not find a service
8c23a1
configuration file. On Red Hat system the default implementation of
8c23a1
"other" for PAM is to deny access. This means on Red Hat systems the
8c23a1
absence of a PAM service configuration file will mean PAM will
8c23a1
silently fail authentication. The PAM service configuration file for
8c23a1
postfix is /etc/pam.d/smtp and is intalled by the Red Hat Postfix rpm
8c23a1
and put under control of "alternatives" with name mta. Alternatives
8c23a1
allows one to select between the sendmail and postfix MTA's and
8c23a1
manages symbolic links for files the two MTA's share. /etc/pam.d/smtp
8c23a1
is one such file, if you have not selected Postfix as your prefered
8c23a1
MTA the link to this file will not be present. To select Postfix as
8c23a1
your MTA do this: "/usr/sbin/alternatives --config mta" and follow the
8c23a1
prompt to select postfix.
8c23a1
8c23a1
2) Is SASL appending a realm or domain to a username? PAM
8c23a1
   authentication requires a bare username and password, other
8c23a1
   authentication methods require the username to be qualified with a
8c23a1
   realm. Typically the username will be rewritten as user@realm
8c23a1
   (e.g. user@foo.com) PAM does not understand a username with
8c23a1
   "@realm" appended to it and will fail the authentication with the
8c23a1
   message that the user is unknown. If the log files shows saslauthd
8c23a1
   usernames with "@realm" appended to it then the
8c23a1
   smtpd_sasl_local_domain configuration parameter is likely set in
8c23a1
   /etc/postfix/main.cf file, make sure its either not set or set it
8c23a1
   to an empty string. Restart postfix and test authtentication again,
8c23a1
   the log file should show only a bare username.
8c23a1
8c23a1
8c23a1
8c23a1
Using saslpasswd to Authenticate:
8c23a1
---------------------------------
8c23a1
8c23a1
SASL can maintain its own password database independent of the host
8c23a1
system's authentication setup, it is called saslpasswd. You may wish
8c23a1
to use saslpasswd if you want to isolate who can smtp authenticate
8c23a1
from general system users. However, it does add another password
8c23a1
database that a system administrator must maintain.
8c23a1
8c23a1
To authenticate against sasldb, you'll first have to create accounts.
8c23a1
These accounts are entirely separate from system accounts, and are used
8c23a1
only by connecting SMTP clients to authenticate themselves.  Use the
8c23a1
saslpassword command:
8c23a1
8c23a1
saslpasswd -u `postconf -h myhostname` -c user
8c23a1
8c23a1
to create an account named user which can log into realm.  For the
8c23a1
realm, make absolutely certain that you use the same value as is set for
8c23a1
myhostname in /etc/postfix/main.cf.  If you don't, it likely won't work.
8c23a1
8c23a1
Also, be aware that saslpasswd is somewhat buggy.  The first time you
8c23a1
run it, it may generate an error message while initializing the sasldb.
8c23a1
If it does, just add that user a second time.
8c23a1
8c23a1
You'll need to set permissions on the SASL password database so that
8c23a1
the Postfix daemons can read it:
8c23a1
8c23a1
   chgrp postfix /etc/sasldb
8c23a1
   chmod g+r /etc/sasldb
8c23a1
8c23a1
Now, you'll need to modify /etc/postfix/main.cf to tell it to
8c23a1
support SASL.  The complete options you might want to use are in the
8c23a1
sample-auth.cf file in the Postfix documentation directory.  An option
8c23a1
you will definitely need is:
8c23a1
8c23a1
# enable SASL support
8c23a1
smtpd_sasl_auth_enable = yes
8c23a1
8c23a1
You might also need to set the SASL authentication realm to whatever
8c23a1
realm you used when you created your sasldb; by default, this is set to
8c23a1
$myhostname, but you instead might need something like:
8c23a1
8c23a1
# set SASL realm to domain instead
8c23a1
smtpd_sasl_local_domain = $mydomain
8c23a1
8c23a1
Other Postfix Authentication Parameters:
8c23a1
----------------------------------------
8c23a1
8c23a1
If you want to allow your already configured users to still use your SMTP
8c23a1
server, and to allow users authenticated via SMTP AUTH to use your server
8c23a1
as well, then modify your existing smtpd_recipient_restrictions line to;
8c23a1
8c23a1
# also allow authenticated (RFC 2554) users
8c23a1
smtpd_recipient_restrictions = permit_sasl_authenticated ...
8c23a1
8c23a1
If you want to restrict use of your server to just authenticated clients
8c23a1
(Note: this is a bad idea for public mail servers), then instead use:
8c23a1
8c23a1
# restrict server access to authenticated (RFC 2554) clients
8c23a1
smtpd_delay_reject = yes
8c23a1
smtpd_client_restrictions = permit_sasl_authenticated ...
8c23a1
8c23a1
SASL supports several password types which have differing security
8c23a1
properties.  Different SMTP clients may support some or all of these
8c23a1
password types.  When the client issues an EHLO command, the server
8c23a1
tells it which types it supports:
8c23a1
8c23a1
$ telnet station6 25
8c23a1
Trying 10.100.0.6...
8c23a1
Connected to station6.example.com.
8c23a1
Escape character is '^]'.
8c23a1
220 station6.example.com ESMTP Postfix
8c23a1
ehlo station7
8c23a1
250-station6.example.com
8c23a1
250-PIPELINING
8c23a1
250-SIZE 10240000
8c23a1
250-VRFY
8c23a1
250-ETRN
8c23a1
250-STARTTLS
8c23a1
250-AUTH PLAIN LOGIN DIGEST-MD5 CRAM-MD5
8c23a1
250-XVERP
8c23a1
250 8BITMIME
8c23a1
8c23a1
Here, the server supports PLAIN, LOGIN, DIGEST-MD5, and CRAM-MD5 password
8c23a1
methods.
8c23a1
8c23a1
The client then chooses the first of these listed methods which it also
8c23a1
supports, and issues an SMTP AUTH request.
8c23a1
8c23a1
For security, PLAIN and LOGIN methods are typically disabled.  These two
8c23a1
methods use trivially decryptable encryption, making the username and
8c23a1
password issued by the client vulnerable to interception via a sniffer
8c23a1
in between the server and client.  Unfortunately, they can't always
8c23a1
be disabled.  Some popular SMTP clients, including MS Outlook 5.x,
8c23a1
only support PLAIN authentication, for example.
8c23a1
8c23a1
To limit the login methods offered by the server:
8c23a1
8c23a1
# disable unsafe password methods
8c23a1
smtpd_sasl_security_options = noplaintext noanonymous
8c23a1
8c23a1
Available options are:
8c23a1
8c23a1
noplaintext, which disables LOGIN and PLAIN
8c23a1
noanonymous, which disables disables ANON
8c23a1
nodictionary, which disables methods vulnerable to dictionary attacks
8c23a1
noactive, which disables methods vulnerable to active attacks
8c23a1
8c23a1
The last two are rarely used, since almost all supported methods are
8c23a1
vulnerable to those attacks ;-).
8c23a1
8c23a1
Also be aware that some broken clients mis-implement the SMTP AUTH
8c23a1
protocol, and send commands using incorrect syntax (AUTH=foo instead of
8c23a1
the correct AUTH foo).  MS Outlook 4.x clients have this bug, among
8c23a1
a legion of others....  If you need to support these clients, use:
8c23a1
8c23a1
# support braindead MS products
8c23a1
broken_sasl_auth_clients = yes
8c23a1
8c23a1
To help prevent spoofing, you can also create a map file of SASL login
8c23a1
names which are allowed to use specific envelope sender (MAIL FROM)
8c23a1
addresses.  If you choose to do this, you also have to tell Postfix to
8c23a1
reject addresses which don't match login names:
8c23a1
8c23a1
# prevent spoofing by authenticated users
8c23a1
reject_sender_login_mismatch
8c23a1
smtpd_sender_login_maps=type:/path/to/file
8c23a1
8c23a1
Configuration of SASL clients is much simpler.  Postfix itself can be
8c23a1
made a SASL client; this is typically useful when roaming users run Linux
8c23a1
on their laptop and need to relay mail back through the organization's
8c23a1
main server.
8c23a1
8c23a1
To enable Postfix to act as an SMTP AUTH client, simply add to
8c23a1
/etc/postfix/main.cf:
8c23a1
8c23a1
# support authentication (RFC 2557) when relaying through a server
8c23a1
smtp_sasl_auth_enable = yes
8c23a1
8c23a1
and tell Postfix where to find the usernames and passwords it should
8c23a1
use to authenticate:
8c23a1
8c23a1
# location of passwords for authentication client
8c23a1
smtp_sasl_password_maps = type:/path/to/file
8c23a1
8c23a1
The file itself should have the format:
8c23a1
8c23a1
destination     username:password
8c23a1
8c23a1
where destination is the name of the server, and username:password are
8c23a1
the username and password which should be presented to that server to
8c23a1
authenticate when connecting to it as a client.
8c23a1
8c23a1
Optionally, the authentication methods to be used can be specified for
8c23a1
the Postfix client, just as they can be for the Postfix server:
8c23a1
8c23a1
# disable plaintext and anonymous
8c23a1
smtp_sasl_security_options = noplaintext noanonymous
8c23a1
8c23a1
Many popular end-user MUAs can also be configured as SMTP AUTH clients.
8c23a1
Clients capable of this supplied with Red Hat include pine, Netscape,
8c23a1
and Mozilla.
8c23a1
8c23a1
Other Sources of Documentation:
8c23a1
-------------------------------
8c23a1
8c23a1
/usr/share/doc/postfix-<version>/README_FILES/SASL_README
8c23a1
8c23a1
Local configuration examples:
8c23a1
8c23a1
/usr/share/doc/postfix-*/samples
8c23a1
8c23a1
Postfix Howtos, Guides and Tips by Ralf Hildebrandt and Patrick
8c23a1
Koetter can be found at: http://postfix.state-of-mind.de
8c23a1
8c23a1
------------------------------------------------------------------------------
8c23a1
8c23a1
Please send any comments / corrections to Chris Ricker
8c23a1
<kaboom@gatech.edu>.  This material can be freely modified and
8c23a1
redistributed. Additional material provided by John Dennis
8c23a1
<jdennis@redhat.com> and Dax Kelson <dax@gurulabs.com>.