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

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