1<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN" 2 "http://www.w3.org/TR/html4/loose.dtd"> 3 4<head> 5 6<title>Postfix SASL Howto</title> 7 8<meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> 9 10</head> 11 12<body> 13 14<h1><img src="postfix-logo.jpg" width="203" height="98" ALT="">Postfix SASL Howto</h1> 15 16<hr> 17 18<h2>Warning</h2> 19 20<p> People who go to the trouble of installing Postfix may have the 21expectation that Postfix is more secure than some other mailers. 22The Cyrus SASL library contains a lot of code. With this, Postfix 23becomes as secure as other mail systems that use the Cyrus SASL 24library. Dovecot provides an alternative that may be worth 25considering. </p> 26 27<h2><a name="intro">How Postfix uses SASL authentication</a></h2> 28 29<p> SMTP servers need to decide whether an SMTP client is authorized 30to send mail to remote destinations, or only to destinations that 31the server itself is responsible for. Usually, SMTP servers allow 32mail to remote destinations when the client's IP address is in the 33"same network" as the server's IP address. </p> 34 35<p> SMTP clients outside the SMTP server's network need a different 36way to get "same network" privileges. To address this need, Postfix 37supports SASL authentication (RFC 4954, formerly RFC 2554). With 38this a remote SMTP client can authenticate to the Postfix SMTP 39server, and the Postfix SMTP client can authenticate to a remote 40SMTP server. Once a client is authenticated, a server can give it 41"same network" privileges. </p> 42 43<p> Postfix does not implement SASL itself, but instead uses existing 44implementations as building blocks. This means that some SASL-related 45configuration will involve files that belong to Postfix, while other 46configuration will involve files that belong to the specific SASL 47implementation that Postfix will use. This document covers both the 48Postfix and non-Postfix configuration. </p> 49 50<p> You can read more about the following topics: </p> 51 52<ul> 53 54<li><a href="#server_sasl">Configuring SASL authentication in the 55Postfix SMTP server</a></li> 56 57<li><a href="#client_sasl">Configuring SASL authentication in the Postfix SMTP/LMTP client</a></li> 58 59<li><a href="#postfix_build">Building Postfix with SASL support</a></li> 60 61<li><a href="#cyrus_legacy">Using Cyrus SASL version 1.5.x</a></li> 62 63<li><a href="#credits">Credits</a></li> 64 65</ul> 66 67<h2><a name="server_sasl">Configuring SASL authentication in the 68Postfix SMTP server</a></h2> 69 70<p> As mentioned earlier, SASL is implemented separately from 71Postfix. For this reason, configuring SASL authentication in the 72Postfix SMTP server involves two different steps: </p> 73 74<ul> 75 76<li> <p> Configuring the SASL implementation to offer a list of 77mechanisms that are suitable for SASL authentication and, depending 78on the SASL implementation used, configuring authentication backends 79that verify the remote SMTP client's authentication data against 80the system password file or some other database. </p> </li> 81 82<li> <p> Configuring the Postfix SMTP server to enable SASL 83authentication, and to authorize clients to relay mail or to control 84what envelope sender addresses the client may use. </p> </li> 85 86</ul> 87 88<p> Successful authentication in the Postfix SMTP server requires 89a functional SASL framework. Configuring SASL should therefore 90always be the first step. </p> 91 92<p> You can read more about the following topics: </p> 93 94<ul> 95 96<li><a href="#server_which">Which SASL Implementations are 97supported?</a></li> 98 99<li><a href="#server_dovecot">Configuring Dovecot SASL</a> 100 101<ul> 102 103<li><a href="#server_dovecot_comm">Postfix to Dovecot SASL 104communication</a></li> 105 106</ul> </li> 107 108<li><a href="#server_cyrus">Configuring Cyrus SASL</a> 109 110<ul> 111 112<li><a href="#server_cyrus_name">Cyrus SASL configuration file 113name</a></li> 114 115<li><a href="#server_cyrus_location">Cyrus SASL configuration 116file location</a></li> 117 118<li><a href="#server_cyrus_comm">Postfix to Cyrus SASL 119communication</a></li> 120 121</ul> </li> 122 123<li><a href="#server_sasl_enable">Enabling SASL authentication and 124authorization in the Postfix SMTP server</a> 125 126<ul> 127 128<li><a href="#server_sasl_authc">Enabling SASL authentication in 129the Postfix SMTP server</a></li> 130 131<li><a href="#smtpd_sasl_security_options">Postfix SMTP Server 132policy - SASL mechanism properties</a></li> 133 134<li><a href="#server_sasl_authz">Enabling SASL authorization in the 135Postfix SMTP server</a></li> 136 137<li><a href="#server_sasl_other">Additional SMTP Server SASL 138options</a></li> 139 140</ul></li> 141 142<li><a href="#server_test">Testing SASL authentication in the Postfix 143SMTP server</a></li> 144 145</ul> 146 147 148<h3><a name="server_which">Which SASL Implementations are 149supported?</a></h3> 150 151<p> Currently the Postfix SMTP server supports the Cyrus SASL and 152Dovecot SASL implementations. </p> 153 154<blockquote> 155 156<strong>Note</strong> 157 158<p> Before Postfix version 2.3, Postfix had support only for Cyrus 159SASL. Current Postfix versions have a plug-in architecture that 160can support multiple SASL implementations. </p> 161 162</blockquote> 163 164<p> To find out what SASL implementations are compiled into Postfix, 165use the following commands: </p> 166 167<blockquote> 168<pre> 169% <strong><code>postconf -a</code></strong> (SASL support in the SMTP server) 170% <strong><code>postconf -A</code></strong> (SASL support in the SMTP+LMTP client) 171</pre> 172</blockquote> 173 174<p> These commands are available only with Postfix version 2.3 and 175later. </p> 176 177<h3><a name="server_dovecot">Configuring Dovecot SASL</a></h3> 178 179<p> Dovecot is a POP/IMAP server that has its own configuration to 180authenticate POP/IMAP clients. When the Postfix SMTP server uses 181Dovecot SASL, it reuses parts of this configuration. Consult the 182<a href="http://wiki.dovecot.org">Dovecot documentation</a> for how 183to configure and operate the Dovecot authentication server. </p> 184 185<h4><a name="server_dovecot_comm">Postfix to Dovecot SASL communication</a></h4> 186 187<p> Communication between the Postfix SMTP server 188and Dovecot SASL happens via a UNIX-domain socket. The socket 189pathname and the list of mechanisms offered to Postfix need to be 190specified on the Dovecot server side in <code>dovecot.conf</code>. 191</p> 192 193<p> The following example assumes that the Postfix queue is under 194<code>/var/spool/postfix/</code>. </p> 195 196<blockquote> 197<pre> 198 1 /etc/dovecot.conf: 199 2 auth default { 200 3 mechanisms = plain login 201 4 passdb pam { 202 5 } 203 6 userdb passwd { 204 7 } 205 8 socket listen { 206 9 client { 20710 path = /var/spool/postfix/private/auth 20811 mode = 0660 20912 user = postfix 21013 group = postfix 21114 } 21215 } 21316 } 214</pre> 215</blockquote> 216 217<p> Line 3 provides <code>plain</code> and <code>login</code> as 218mechanisms for the Postfix SMTP server, line 10 places the Dovecot 219SASL socket in <code>/var/spool/postfix/private/auth</code>, and 220lines 11-13 limit read+write permissions to user and group 221<code>postfix</code> only. </p> 222 223<p> Proceed with the section "<a href="#server_sasl_enable">Enabling 224SASL authentication and authorization in the Postfix SMTP server</a>" 225to turn on and use SASL in the Postfix SMTP server. </p> 226 227<h3><a name="server_cyrus">Configuring Cyrus SASL</a></h3> 228 229<p> The Cyrus SASL framework supports a wide variety of applications 230(POP, IMAP, SMTP, etc.). Different applications may require different 231configurations. As a consequence each application may have its own 232configuration file. </p> 233 234<p> The first step configuring Cyrus SASL is to determine name and 235location of a configuration file that describes how the Postfix 236SMTP server will use the SASL framework. </p> 237 238<h4><a name="server_cyrus_name">Cyrus SASL configuration file name</a></h4> 239 240<p> The name of the configuration file (default: <code>smtpd.conf</code>) 241is configurable. It is a concatenation from a value that the Postfix 242SMTP server sends to the Cyrus SASL library, and the suffix 243<code>.conf</code>, added by Cyrus SASL. </p> 244 245<p> The value sent by Postfix is the name of the server component 246that will use Cyrus SASL. It defaults to <code>smtpd</code> and 247is configured with one of the following variables: </p> 248 249<blockquote> 250<pre> 251/etc/postfix/main.cf: 252 # Postfix 2.3 and later 253 smtpd_sasl_path = smtpd 254 255 # Postfix < 2.3 256 smtpd_sasl_application_name = smtpd 257</pre> 258</blockquote> 259 260<h4><a name="server_cyrus_location">Cyrus SASL configuration file 261location</a></h4> 262 263<p> The location where Cyrus SASL searches for the named file depends 264on the Cyrus SASL version and the OS/distribution used. </p> 265 266<p> You can read more about the following topics: </p> 267 268<ul> 269 270<li> <p> Cyrus SASL version 2.x searches for the configuration file 271in <code>/usr/lib/sasl2/</code>. </p> </li> 272 273<li> <p> Cyrus SASL version 2.1.22 and newer additionally search 274in <code>/etc/sasl2/</code>. </p> </li> 275 276<li> <p> Some Postfix distributions are modified and look for the 277Cyrus SASL configuration file in <code>/etc/postfix/sasl/</code>, 278<code>/var/lib/sasl2/</code> etc. See the distribution-specific 279documentation to determine the expected location. </p> </li> 280 281</ul> 282 283<blockquote> 284 285<strong>Note</strong> 286 287<p> Cyrus SASL searches <code>/usr/lib/sasl2/</code> first. If it 288finds the specified configuration file there, it will not examine 289other locations. </p> 290 291</blockquote> 292 293<h4><a name="server_cyrus_comm">Postfix to Cyrus SASL communication</a></h4> 294 295<p> As the Postfix SMTP server is linked with the Cyrus SASL library 296<code>libsasl</code>, communication between Postfix and Cyrus SASL 297takes place by calling functions in the SASL library. </p> 298 299<p> The SASL library may use an external password verification 300service, or an internal plugin to connect to authentication backends 301and verify the SMTP client's authentication data against the system 302password file or other databases. </p> 303 304<p> The following table shows typical combinations discussed in 305this document: </p> 306 307<blockquote> 308 309<table border="1"> 310 311<tr> 312 313<th align="center">authentication backend</th> 314 315<th align="center">password verification service / plugin</th> 316 317</tr> 318 319<tr> 320 321<td>/etc/shadow</td> 322 323<td><a href="#saslauthd">saslauthd</a></td> 324 325</tr> 326 327<tr> 328 329<td>PAM</td> 330 331<td><a href="#saslauthd">saslauthd</a></td> 332 333</tr> 334 335<tr> 336 337<td>IMAP server</td> 338 339<td><a href="#saslauthd">saslauthd</a></td> 340 341</tr> 342 343<tr> 344 345<td>sasldb</td> 346 347<td><a href="#auxprop_sasldb">sasldb</a></td> 348 349</tr> 350 351<tr> 352 353<td>MySQL, PostgreSQL, SQLite</td> 354 355<td><a href="#auxprop_sql">sql</a></td> 356 357</tr> 358 359<tr> 360 361<td>LDAP</td> 362 363<td><a href="#auxprop_ldapdb">ldapdb</a></td> 364 365</tr> 366 367</table> 368 369</blockquote> 370 371<blockquote> 372 373<strong>Note</strong> 374 375<p> Read the Cyrus SASL documentation for other backends it can 376use. </p> 377 378</blockquote> 379 380<h4><a name="saslauthd">saslauthd - Cyrus SASL password verification service</a></h4> 381 382<p> Communication between the Postfix SMTP server (read: Cyrus SASL's 383<code>libsasl</code>) and the <code>saslauthd</code> server takes 384place over a UNIX-domain socket. </p> 385 386<p> <code>saslauthd</code> usually establishes the UNIX domain 387socket in <code>/var/run/saslauthd/</code> and waits for authentication 388requests. The Postfix SMTP server must have read+execute permission 389to this directory or authentication attempts will fail. </p> 390 391<blockquote> 392 393<strong>Important</strong> 394 395<p> Some distributions require the user <code>postfix</code> to be 396member of a special group e.g. <code>sasl</code>, otherwise it 397will not be able to access the <code>saslauthd</code> socket 398directory. </p> 399 400</blockquote> 401 402<p> The following example configures the Cyrus SASL library to 403contact <code>saslauthd</code> as its password verification service: 404</p> 405 406<blockquote> 407<pre> 408/etc/sasl2/smtpd.conf: 409 pwcheck_method: saslauthd 410 mech_list: PLAIN LOGIN 411</pre> 412</blockquote> 413 414<blockquote> 415 416<strong>Important</strong> 417 418<p> Do not specify any other mechanisms in <code>mech_list</code> 419than <code>PLAIN</code> or <code>LOGIN</code> when using 420<code>saslauthd</code>! It can only handle these two mechanisms, 421and authentication will fail if clients are allowed to choose other 422mechanisms. </p> 423 424</blockquote> 425 426<blockquote> 427 428<strong>Important</strong> 429 430<p> Plaintext mechanisms (<code>PLAIN</code>, <code>LOGIN</code>) 431send credentials unencrypted. This information should be protected 432by an additional security layer such as a TLS-encrypted SMTP session 433(see: TLS_README). </p> 434 435</blockquote> 436 437<p> Additionally the <code>saslauthd</code> server itself must be 438configured. It must be told which authentication backend to turn 439to for password verification. The backend is selected with a 440<code>saslauthd</code> command-line option and will be shown in the 441following examples. </p> 442 443<blockquote> 444 445<strong>Note</strong> 446 447<p> Some distributions use a configuration file to provide saslauthd 448command line options to set e.g. the authentication backend. Typical 449locations are <code>/etc/sysconfig/saslauthd</code> or 450<code>/etc/default/saslauthd</code>. </p> 451 452</blockquote> 453 454<h4><a name="saslauthd_shadow">Using saslauthd with /etc/shadow</a></h4> 455 456<p> Access to the <code>/etc/shadow</code> system password file 457requires <code>root</code> privileges. The Postfix SMTP server 458(and in consequence <code>libsasl</code> linked to the server) runs 459with the least privilege possible. Direct access to 460<code>/etc/shadow</code> would not be possible without breaking the 461Postfix security architecture. </p> 462 463<p> The <code>saslauthd</code> socket builds a safe bridge. Postfix, 464running as limited user <code>postfix</code>, can access the 465UNIX-domain socket that <code>saslauthd</code> receives commands 466on; <code>saslauthd</code>, running as privileged user <code>root</code>, 467has the privileges required to access the shadow file. </p> 468 469<p> The <code>saslauthd</code> server verifies passwords against the 470authentication backend <code>/etc/shadow</code> if started like this: </p> 471 472<blockquote> 473<pre> 474% <strong><code>saslauthd -a shadow</code></strong> 475</pre> 476</blockquote> 477 478<p> See section "<a href="#testing_saslauthd">Testing saslauthd 479authentication</a>" for test instructions. </p> 480 481<h4><a name="saslauthd_pam">Using saslauthd with PAM</a></h4> 482 483<p> Cyrus SASL can use the PAM framework to authenticate credentials. 484<code>saslauthd</code> uses the PAM framework when started like 485this: </p> 486 487<blockquote> 488<pre> 489% <strong><code>saslauthd -a pam</code></strong> 490</pre> 491</blockquote> 492 493<blockquote> 494 495<strong>Note</strong> 496 497<p> PAM configuration for the Postfix SMTP server is usually given 498in <code>/etc/pam.d/smtp</code> and is beyond the scope of this 499document. </p> 500 501</blockquote> 502 503<p> See section "<a href="#testing_saslauthd">Testing saslauthd 504authentication</a>" for test instructions. </p> 505 506<h4><a name="saslauthd_imap">Using saslauthd with an IMAP server</a></h4> 507 508<p> <code>saslauthd</code> can verify the SMTP client credentials 509by using them to log into an IMAP server. If the login succeeds, 510SASL authentication also succeeds. <code>saslauthd</code> contacts 511an IMAP server when started like this: </p> 512 513<blockquote> 514<pre> 515% <strong><code>saslauthd -a rimap -O imap.example.com</code></strong> 516</pre> 517</blockquote> 518 519<blockquote> 520 521<strong>Note</strong> 522 523<p> The option "<code>-O imap.example.com</code>" specifies the 524IMAP server <code>saslauthd</code> should contact when it verifies 525credentials. </p> 526 527</blockquote> 528 529<blockquote> 530 531<strong>Important</strong> 532 533<p> <code>saslauthd</code> sends IMAP login information unencrypted. 534Any IMAP session leaving the local host should be protected by an 535additional security layer such as an SSL tunnel. </p> 536 537</blockquote> 538 539<p> See section "<a href="#testing_saslauthd">Testing saslauthd 540authentication</a>" for test instructions. </p> 541 542<h4><a name="testing_saslauthd">Testing saslauthd authentication</a></h4> 543 544<p> Cyrus SASL provides the <code>testsaslauthd</code> utility to 545test <code>saslauthd</code> authentication. The username and password 546are given as command line arguments. The example shows the response 547when authentication is successful: </p> 548 549<blockquote> 550<pre> 551% <strong><code>testsaslauthd -u <em>username</em> -p <em>password</em></code></strong> 5520: OK "Success." 553</pre> 554</blockquote> 555 556<blockquote> 557 558<strong>Note</strong> 559 560<p> Sometimes the <code>testsaslauthd</code> program is not distributed 561with a the Cyrus SASL main package. In that case, it may be 562distributed with <code>-devel</code>, <code>-dev</code> or 563<code>-debug</code> packages. </p> 564 565</blockquote> 566 567<p> Specify an additional "<code>-s smtp</code>" if <code>saslauthd</code> 568was configured to contact the PAM authentication framework, and 569specify an additional "<code>-f <em>/path/to/socketdir/mux</em></code>" 570if <code>saslauthd</code> establishes the UNIX-domain socket in a 571non-default location. </p> 572 573<p> If authentication succeeds, proceed with the section "<a 574href="#server_sasl_enable">Enabling SASL authentication and authorization 575in the Postfix SMTP server</a>". </p> 576 577<h4><a name="auxprop">Cyrus SASL Plugins - auxiliary property 578plugins</a></h4> 579 580<p> Cyrus SASL uses a plugin infrastructure (called <code>auxprop</code>) 581to expand <code>libsasl</code>'s capabilities. Currently Cyrus 582SASL sources provide three authentication plugins. </p> 583 584<blockquote> 585 586<table border="1"> 587 588<tr> <th>Plugin </th> <th>Description </th> </tr> 589 590<tr> <td><a href="#auxprop_sasldb">sasldb</a></dt> <td> Accounts 591are stored stored in a Cyrus SASL Berkeley DB database </td> </tr> 592 593<tr> <td><a href="#auxprop_sql">sql</a></dt> <td> Accounts are 594stored in a SQL database </td> </tr> 595 596<tr> <td><a href="#auxprop_ldapdb">ldapdb</a></dt> <td> Accounts 597are stored stored in an LDAP database </td> </tr> 598 599</table> 600 601</blockquote> 602 603<blockquote> 604 605<strong>Important</strong> 606 607<p> These three plugins support shared-secret mechanisms i.e. 608CRAM-MD5, DIGEST-MD5 and NTLM. These mechanisms send credentials 609encrypted but their verification process requires the password to 610be available in plaintext. Consequently passwords cannot (!) be 611stored in encrypted form. </p> 612 613</blockquote> 614 615<h4><a name="auxprop_sasldb">The sasldb plugin</a></h4> 616 617<p> The sasldb auxprop plugin authenticates SASL clients against 618credentials that are stored in a Berkeley DB database. The database 619schema is specific to Cyrus SASL. The database is usually located 620at <code>/etc/sasldb2</code>. </p> 621 622<blockquote> 623 624<strong>Note</strong> 625 626<p> The <code>sasldb2</code> file contains passwords in 627plaintext, and should have read+write access only to user 628<code>postfix</code> or a group that <code>postfix</code> is member 629of. </p> 630 631</blockquote> 632 633<p> The <code>saslpasswd2</code> command-line utility creates 634and maintains the database: </p> 635 636<blockquote> 637<pre> 638% <strong>saslpasswd2 -c -u <em>example.com</em> <em>username</em></strong> 639Password: 640Again (for verification): 641</pre> 642</blockquote> 643 644<p> This command creates an account 645<code><em>username@example.com</em></code>. </p> 646 647<blockquote> 648 649<strong>Important</strong> 650 651<p> users must specify <code><em>username@example.com</em></code> 652as login name, not <code><em>username</em></code>. </p> 653 654</blockquote> 655 656<p> Run the following command to reuse the Postfix <code>mydomain</code> 657parameter value as the login domain: </p> 658 659<blockquote> 660<pre> 661% <strong>saslpasswd2 -c -u `postconf -h mydomain` <em>username</em></strong> 662Password: 663Again (for verification): 664</pre> 665</blockquote> 666 667<blockquote> 668 669<strong>Note</strong> 670 671<p> Run <code>saslpasswd2</code> without any options for further 672help on how to use the command. </p> 673 674</blockquote> 675 676<p> The <code>sasldblistusers2</code> command lists all existing 677users in the sasldb database: </p> 678 679<blockquote> 680<pre> 681% <strong>sasldblistusers2</strong> 682username1@example.com: password1 683username2@example.com: password2 684</pre> 685</blockquote> 686 687<p> Configure libsasl to use sasldb with the following instructions: </p> 688 689<blockquote> 690<pre> 691/etc/sasl2/smtpd.conf: 692 pwcheck_method: auxprop 693 auxprop_plugin: sasldb 694 mech_list: PLAIN LOGIN CRAM-MD5 DIGEST-MD5 NTLM 695</pre> 696</blockquote> 697 698<blockquote> 699 700<strong>Note</strong> 701 702<p> In the above example adjust <code>mech_list</code> to the 703mechanisms that are applicable for your environment. </p> 704 705</blockquote> 706 707<h4><a name="auxprop_sql">The sql plugin</a></h4> 708 709<p> The sql auxprop plugin is a generic SQL plugin. It provides 710access to credentials stored in a MySQL, PostgreSQL or SQLite 711database. This plugin requires that SASL client passwords are 712stored as plaintext. </p> 713 714<blockquote> 715 716<strong>Tip</strong> 717 718<p> If you must store encrypted passwords, you cannot use the sql 719auxprop plugin. Instead, see section "<a href="#saslauthd_pam">Using 720saslauthd with PAM</a>", and configure PAM to look up the encrypted 721passwords with, for example, the <code>pam_mysql</code> module. 722You will not be able to use any of the methods that require access 723to plaintext passwords, such as the shared-secret methods CRAM-MD5 724and DIGEST-MD5. </p> 725 726</blockquote> 727 728<p> The following example configures libsasl to use the sql plugin 729and connects it to a PostgreSQL server: </p> 730 731<blockquote> 732<pre> 733/etc/sasl2/smtpd.conf: 734 pwcheck_method: auxprop 735 auxprop_plugin: sql 736 mech_list: PLAIN LOGIN CRAM-MD5 DIGEST-MD5 NTLM 737 sql_engine: pgsql 738 sql_hostnames: 127.0.0.1, 192.0.2.1 739 sql_user: username 740 sql_passwd: secret 741 sql_database: dbname 742 sql_select: SELECT password FROM users WHERE user = '%u'@'%r' 743</pre> 744</blockquote> 745 746<blockquote> 747 748<strong>Note</strong> 749 750<p> Set appropriate permissions if <code>smtpd.conf</code> contains 751a password. The file should be readable by the <code>postfix</code> 752user. </p> 753 754</blockquote> 755 756<blockquote> 757 758<strong>Note</strong> 759 760<p> In the above example, adjust <code>mech_list</code> to the 761mechanisms that are applicable for your environment. </p> 762 763</blockquote> 764 765<p> The sql plugin has the following configuration options: </p> 766 767<blockquote> 768 769<dl> 770 771<dt>sql_engine</dt> 772 773<dd> 774 775<p> Specify <code>mysql</code> to connect to a MySQL server, 776<code>pgsql</code> for a PostgreSQL server or <code>sqlite</code> 777for an SQLite database </p> 778 779</dd> 780 781<dt>sql_hostnames</dt> 782 783<dd> 784 785<p> Specify one or more servers (hostname or hostname:port) separated 786by commas. </p> 787 788<blockquote> 789 790<strong>Note</strong> 791 792<p> With MySQL servers, specify <code>localhost</code> to connect 793over a UNIX-domain socket, and specify <code>127.0.0.1</code> to 794connect over a TCP socket. </p> 795 796</blockquote> 797 798</dd> 799 800<dt>sql_user</dt> 801 802<dd> 803 804<p> The login name to gain access to the database. </p> 805 806</dd> 807 808<dt>sql_passwd</dt> 809 810<dd> 811 812<p> The password to gain access to the database. </p> 813 814</dd> 815 816<dt>sql_database</dt> 817 818<dd> 819 820<p> The name of the database to connect to. </p> 821 822</dd> 823 824<dt>sql_select</dt> 825 826<dd> 827 828<p> The SELECT statement that should retrieve the plaintext password 829from a database table. </p> 830 831<blockquote> 832 833<strong>Important</strong> 834 835<p> Do not enclose the statement in quotes! Use single quotes to 836escape macros! </p> 837 838</blockquote> 839 840</dd> 841 842</dl> 843 844</blockquote> 845 846<p> The sql plugin provides macros to build <code>sql_select</code> 847statements. They will be replaced with arguments sent from the client. The 848following macros are available: </p> 849 850<blockquote> 851 852<dl> 853 854<dt>%u</dt> 855 856<dd> 857 858<p> The name of the user whose properties are being selected. </p> 859 860</dd> 861 862<dt>%p</dt> 863 864<dd> 865 866<p> The name of the property being selected. While this could technically be 867anything, Cyrus SASL will try userPassword and cmusaslsecretMECHNAME (where 868MECHNAME is the name of a SASL mechanism). </p> 869 870</dd> 871 872<dt>%r</dt> 873 874<dd> 875 876<p> The name of the realm to which the user belongs. This could be 877the KERBEROS realm, the fully-qualified domain name of the computer 878the SASL application is running on, or the domain after the "@" in a 879username. </p> 880 881</dd> 882 883</dl> 884 885</blockquote> 886 887<h4><a name="auxprop_ldapdb">The ldapdb plugin</a></h4> 888 889<p> The ldapdb auxprop plugin provides access to credentials stored 890in an LDAP server. This plugin requires that SASL client passwords are 891stored as plaintext. </p> 892 893<blockquote> 894 895<strong>Tip</strong> 896 897<p> If you must store encrypted passwords, you cannot use the ldapdb 898auxprop plugin. Instead, you can use "<code>saslauthd -a ldap</code>" 899to query the LDAP database directly, with appropriate configuration 900in <code>saslauthd.conf</code>. This may be documented in a later 901version of this document. You will not be able to use any of the 902methods that require access to plaintext passwords, such as the 903shared-secret methods CRAM-MD5 and DIGEST-MD5. </p> 904 905</blockquote> 906 907<p> The ldapdb plugin implements proxy authorization. This means 908that the ldapdb plugin uses its own username and password to 909authenticate with the LDAP server, before it asks the LDAP server 910for the remote SMTP client's password. The LDAP server then decides 911if the ldapdb plugin is authorized to read the remote SMTP client's 912password. </p> 913 914<p> In a nutshell: Configuring ldapdb means authentication and 915authorization must be configured twice - once in the Postfix SMTP 916server to authenticate and authorize the remote SMTP client, and 917once in the LDAP server to authenticate and authorize the ldapdb 918plugin. </p> 919 920<p> This example configures libsasl to use the ldapdb plugin and 921the plugin to connect to an LDAP server: </p> 922 923<blockquote> 924<pre> 925/etc/sasl2/smtpd.conf: 926 pwcheck_method: auxprop 927 auxprop_plugin: ldapdb 928 mech_list: PLAIN LOGIN NTLM CRAM-MD5 DIGEST-MD5 929 ldapdb_uri: ldap://localhost 930 ldapdb_id: proxyuser 931 ldapdb_pw: password 932 ldapdb_mech: DIGEST-MD5 933</pre> 934</blockquote> 935 936<blockquote> 937 938<strong>Important</strong> 939 940<p> Set appropriate permissions if <code>smtpd.conf</code> contains a 941password. The file should be readable by the <code>postfix</code> 942user. </p> 943 944</blockquote> 945 946<blockquote> 947 948<strong>Note</strong> 949 950<p> The shared-secret mechanisms (CRAM-MD5, etc.) require that the 951SASL client passwords are stored as plaintext. </p> 952 953</blockquote> 954 955<p> The following is a summary of applicable <code>smtpd.conf</code> 956file entries: </p> 957 958<blockquote> 959 960<dl> 961 962<dt>auxprop_plugin</dt> 963 964<dd> <p> Specify <code>ldapdb</code> to enable the plugin. </p> </dd> 965 966<dt>ldapdb_uri</dt> 967 968<dd> <p> Specify either <code>ldapi://</code> for to connect over 969a UNIX-domain socket, <code>ldap://</code> for an unencrypted TCP 970connection or <code>ldaps://</code> for an encrypted TCP connection. 971</p> </dd> 972 973<dt>ldapdb_id</dt> 974 975<dd> <p> The login name to authenticate the ldapdb plugin to the 976LDAP server (proxy authorization). </p> </dd> 977 978<dt>ldapdb_pw</dt> 979 980<dd> <p> The password (in plaintext) to authenticate the ldapdb 981plugin to the LDAP server (proxy authorization). </p> </dd> 982 983<dt>ldapdb_mech</dt> 984 985<dd> <p> The mechanism to authenticate the ldapdb plugin to the 986LDAP server. </p> 987 988<blockquote> 989 990<strong>Note</strong> 991 992<p> Specify a mechanism here that is supported by the LDAP server. 993</p> 994 995</blockquote> 996 997</dd> 998 999<dt>ldapdb_rc (optional)</dt> 1000 1001<dd> <p> The path to a file containing individual configuration 1002options for the ldapdb LDAP client (libldap). This allows to specify 1003a TLS client certificate which in turn can be used to use the SASL 1004EXTERNAL mechanism. </p> 1005 1006<blockquote> 1007 1008<strong>Note</strong> 1009 1010<p> This mechanism supports authentication over an encrypted transport 1011layer, which is recommended if the plugin must connect to an OpenLDAP 1012server on a remote machine. </p> 1013 1014</blockquote> 1015 1016</dd> 1017 1018<dt>ldapdb_starttls (optional)</dt> 1019 1020<dd> <p> The TLS policy for connecting to the LDAP server. Specify 1021either <code>try</code> or <code>demand</code>. If the option is 1022<code>try</code> the plugin will attempt to establish a TLS-encrypted 1023connection with the LDAP server, and will fallback to an unencrypted 1024connection if TLS fails. If the policy is <code>demand</code> and 1025a TLS-encrypted connection cannot be established, the connection 1026fails immediately. </p> </dd> 1027 1028</dl> 1029 1030</blockquote> 1031 1032<p> When the ldapdb plugin connects to the OpenLDAP server and 1033successfully authenticates, the OpenLDAP server decides if the 1034plugin user is authorized to read SASL account information. </p> 1035 1036<p> The following configuration gives an example of authorization configuration 1037in the OpenLDAP slapd server: </p> 1038 1039<blockquote> 1040<pre> 1041/etc/openldap/slapd.conf: 1042 authz-regexp 1043 uid=(.*),cn=.*,cn=auth 1044 ldap:///dc=example,dc=com??sub?cn=$1 1045 authz-policy to 1046</pre> 1047</blockquote> 1048 1049<p> Here, the <code>authz-regexp</code> option serves for authentication 1050of the ldapdb user. It maps its login name to a DN in the LDAP 1051directory tree where <code>slapd</code> can look up the SASL account 1052information. The <code>authz-policy</code> options defines the 1053authentication policy. In this case it grants authentication 1054privileges "<code>to</code>" the ldapdb plugin. </p> 1055 1056<p> The last configuration step is to tell the OpenLDAP <code>slapd</code> 1057server where ldapdb may search for usernames matching the one given 1058by the mail client. The example below adds an additional attribute 1059ldapdb user object (here: <code>authzTo</code> because the authz-policy 1060is "<code>to</code>") and configures the scope where the login name 1061"proxyuser" may search: </p> 1062 1063<blockquote> 1064<pre> 1065dn: cn=proxyuser,dc=example,dc=com 1066changetype: modify 1067add: authzTo 1068authzTo: dn.regex:uniqueIdentifier=(.*),ou=people,dc=example,dc=com 1069</pre> 1070</blockquote> 1071 1072<p> Use the <code>ldapmodify</code> or <code>ldapadd</code> command 1073to add the above attribute. </p> 1074 1075<blockquote> 1076 1077<strong>Note</strong> 1078 1079<p> Read the chapter "Using SASL" in the <a 1080href="http://www.openldap.org/doc/admin">OpenLDAP Admin Guide</a> 1081for more detailed instructions to set up SASL authentication in 1082OpenLDAP. </p> 1083 1084</blockquote> 1085 1086<h3><a name="server_sasl_enable">Enabling SASL authentication and 1087authorization in the Postfix SMTP server</a></h3> 1088 1089<p> By default the Postfix SMTP server uses the Cyrus SASL 1090implementation. If the Dovecot SASL implementation should be used, 1091specify an <code>smtpd_sasl_type</code> value of <code>dovecot</code> 1092instead of <code>cyrus</code>: </p> 1093 1094<blockquote> 1095<pre> 1096/etc/postfix/main.cf: 1097 smtpd_sasl_type = dovecot 1098</pre> 1099</blockquote> 1100 1101<p> Additionally set the path where the Postfix SMTP server can 1102find the Dovecot SASL socket: </p> 1103 1104<blockquote> 1105<pre> 1106/etc/postfix/main.cf: 1107 smtpd_sasl_path = private/auth 1108</pre> 1109</blockquote> 1110 1111<blockquote> 1112 1113<strong>Note</strong> 1114 1115<p> This example uses a pathname relative to the Postfix queue 1116directory, so that it will work whether or not the Postfix SMTP 1117server runs chrooted. </p> 1118 1119</blockquote> 1120 1121<h4><a name="server_sasl_authc">Enabling SASL authentication 1122in the Postfix SMTP server</a></h4> 1123 1124<p> Regardless of the SASL implementation type, enabling SMTP 1125authentication in the Postfix SMTP server always requires setting 1126the <code>smtpd_sasl_auth_enable</code> option: </p> 1127 1128<blockquote> 1129<pre> 1130/etc/postfix/main.cf: 1131 smtpd_sasl_auth_enable = yes 1132</pre> 1133</blockquote> 1134 1135<p> After a "postfix reload", SMTP clients will see the additional 1136capability AUTH in an SMTP session, followed by a list of 1137authentication mechanisms the server supports: </p> 1138 1139<blockquote> 1140<pre> 1141% <strong>telnet server.example.com 25</strong> 1142... 1143220 server.example.com ESMTP Postfix 1144<strong>EHLO client.example.com</strong> 1145250-server.example.com 1146250-PIPELINING 1147250-SIZE 10240000 1148250-AUTH DIGEST-MD5 PLAIN CRAM-MD5 1149... 1150</pre> 1151</blockquote> 1152 1153<p> However not all clients recognize the AUTH capability as defined 1154by the SASL authentication RFC. Some historical implementations expect the 1155server to send an "<code>=</code>" as separator between the AUTH 1156verb and the list of mechanisms that follows it. </p> 1157 1158<p> The <code>broken_sasl_auth_clients</code> configuration option 1159lets Postfix repeat the AUTH statement in a form that these broken 1160clients understand: </p> 1161 1162<blockquote> 1163<pre> 1164/etc/postfix/main.cf: 1165 broken_sasl_auth_clients = yes 1166</pre> 1167</blockquote> 1168 1169<blockquote> 1170 1171<strong>Note</strong> 1172 1173<p> Enable this option for Outlook up to and including version 2003 1174and Outlook Express up to version 6. This option does not hurt other 1175clients. </p> 1176 1177</blockquote> 1178 1179<p> After "postfix reload", the Postfix SMTP server will propagate 1180the AUTH capability twice - once for compliant and once for broken 1181clients: </p> 1182 1183<blockquote> 1184<pre> 1185% <strong>telnet server.example.com 25</strong> 1186... 1187<strong>EHLO client.example.com</strong> 1188250-server.example.com 1189250-PIPELINING 1190250-SIZE 10240000 1191250-AUTH DIGEST-MD5 PLAIN CRAM-MD5 1192250-AUTH=DIGEST-MD5 PLAIN CRAM-MD5 1193... 1194</pre> 1195</blockquote> 1196 1197<h4><a name="smtpd_sasl_security_options">Postfix SMTP Server policy 1198- SASL mechanism properties</a></h4> 1199 1200<p> The Postfix SMTP server supports policies that limit the SASL 1201mechanisms that it makes available to clients, based on the properties 1202of those mechanisms. The next two sections give examples of how 1203these policies are used. </p> 1204 1205<blockquote> 1206 1207<table border="1"> 1208 1209<tr> <th>Property</th> <th>Description</th> </tr> 1210 1211<tr> <td>noanonymous</td> <td> Don't use mechanisms that permit 1212anonymous authentication. </td> </tr> 1213 1214<tr> <td>noplaintext</td> <td> Don't use mechanisms that transmit 1215unencrypted username and password information. </td> </tr> 1216 1217<tr> <td>nodictionary</td> <td> Don't use mechanisms that are 1218vulnerable to dictionary attacks. </td> </tr> 1219 1220<tr> <td>forward_secrecy</td> <td> Require forward secrecy between 1221sessions (breaking one session does not break earlier sessions). 1222</td> </tr> 1223 1224<tr> <td>mutual_auth</td> <td> Use only mechanisms that authenticate 1225both the client and the server to each other. </td> </tr> 1226 1227</table> 1228 1229</blockquote> 1230 1231<h4><a name="id396877">Unencrypted SMTP session</a></h4> 1232 1233<p> The default policy is to allow any mechanism in the Postfix SMTP server 1234except for those based on anonymous authentication: </p> 1235 1236<blockquote> 1237<pre> 1238/etc/postfix/main.cf: 1239 # Specify a list of properties separated by comma or whitespace 1240 smtpd_sasl_security_options = noanonymous 1241</pre> 1242</blockquote> 1243 1244<blockquote> 1245 1246<strong>Important</strong> 1247 1248<p> Always set at least the <code>noanonymous</code> option. 1249Otherwise, the Postfix SMTP server can give strangers the same 1250authorization as a properly-authenticated client. </p> 1251 1252</blockquote> 1253 1254<h4><a name="id396969">Encrypted SMTP session (TLS)</a></h4> 1255 1256<p> A separate parameter controls Postfix SASL mechanism policy 1257during a TLS-encrypted SMTP session. The default is to copy the 1258settings from the unencrypted session: </p> 1259 1260<blockquote> 1261<pre> 1262/etc/postfix/main.cf: 1263 smtpd_sasl_tls_security_options = $smtpd_sasl_security_options 1264</pre> 1265</blockquote> 1266 1267<p> A more sophisticated policy allows plaintext mechanisms, but 1268only over a TLS-encrypted connection: </p> 1269 1270<blockquote> 1271<pre> 1272/etc/postfix/main.cf: 1273 smtpd_sasl_security_options = noanonymous, noplaintext 1274 smtpd_sasl_tls_security_options = noanonymous 1275</pre> 1276</blockquote> 1277 1278<p> To offer SASL authentication only after a TLS-encrypted session has been 1279established specify this: </p> 1280 1281<blockquote> 1282<pre> 1283/etc/postfix/main.cf: 1284 smtpd_tls_auth_only = yes 1285</pre> 1286</blockquote> 1287 1288<h4><a name="server_sasl_authz">Enabling SASL authorization in the Postfix 1289SMTP server</a></h4> 1290 1291<p> After the client has authenticated with SASL, the Postfix SMTP 1292server decides what the remote SMTP client will be authorized 1293for. Examples of possible SMTP clients authorizations are: </p> 1294 1295<ul> 1296 1297<li> <p> Send a message to a remote recipient. </p> </li> 1298 1299<li> <p> Use a specific envelope sender in the MAIL FROM command. </p> </li> 1300 1301</ul> 1302 1303<p> These permissions are not enabled by default. </p> 1304 1305<h4><a name="server_sasl_authz_relay">Mail relay authorization</a></h4> 1306 1307<p> The <code>permit_sasl_authenticated</code> restriction allows 1308SASL-authenticated SMTP clients to send mail to remote destinations. 1309Add it to the list of <code>smtpd_recipient_restrictions</code> as 1310follows: </p> 1311 1312<blockquote> 1313<pre> 1314/etc/postfix/main.cf: 1315 smtpd_recipient_restrictions = 1316 ... 1317 permit_mynetworks 1318 <strong>permit_sasl_authenticated</strong> 1319 reject_unauth_destination 1320 ... 1321</pre> 1322</blockquote> 1323 1324<h4><a name="server_sasl_authz_envelope">Envelope sender address 1325authorization</a></h4> 1326 1327<p> By default an SMTP client may specify any envelope sender address 1328in the MAIL FROM command. That is because the Postfix SMTP server 1329only knows the remote SMTP client hostname and IP address, but not 1330the user who controls the remote SMTP client. </p> 1331 1332<p> This changes the moment an SMTP client uses SASL authentication. 1333Now, the Postfix SMTP server knows who the sender is. Given a table 1334of envelope sender addresses and SASL login names, the Postfix SMTP 1335server can decide if the SASL authenticated client is allowed to 1336use a particular envelope sender address: </p> 1337 1338<blockquote> 1339<pre> 1340/etc/postfix/main.cf: 1341 <strong>smtpd_sender_login_maps = hash:/etc/postfix/controlled_envelope_senders</strong> 1342 1343 smtpd_recipient_restrictions = 1344 ... 1345 <strong>reject_sender_login_mismatch</strong> 1346 permit_sasl_authenticated 1347 permit_mynetworks 1348 reject_unauth_destination 1349 ... 1350</pre> 1351</blockquote> 1352 1353<p> The <code>controlled_envelope_senders</code> table specifies 1354the binding between a sender envelope address and the SASL login 1355names that own that address: </p> 1356 1357<blockquote> 1358<pre> 1359/etc/postfix/controlled_envelope_senders 1360 # envelope sender owners (SASL login names) 1361 john@example.com john@example.com 1362 helpdesk@example.com john@example.com, mary@example.com 1363 postmaster admin@example.com 1364 @example.net barney, fred, john@example.com, mary@example.com 1365</pre> 1366</blockquote> 1367 1368<p> With this, the <code>reject_sender_login_mismatch</code> 1369restriction above will reject the sender address in the MAIL FROM 1370command if <code>smtpd_sender_login_maps</code> does not specify 1371the SMTP client's login name as an owner of that address. </p> 1372 1373<p> See also <code>reject_authenticated_sender_login_mismatch</code> and 1374<code>reject_unauthenticated_sender_login_mismatch</code> for additional 1375control over the SASL login name and the envelope sender. </p> 1376 1377<h4><a name="server_sasl_other">Additional SMTP Server SASL options</a></h4> 1378 1379<p> Postfix provides a wide range of SASL authentication configuration 1380options. The next section lists a few that are discussed frequently. 1381See postconf(5) for a complete list. </p> 1382 1383<h4><a name="id397172">Default authentication domain</a></h4> 1384 1385<p> Postfix can append a domain name (or any other string) to a 1386SASL login name that does not have a domain part, e.g. "<code>john</code>" 1387instead of "<code>john@example.com</code>": </p> 1388 1389<blockquote> 1390<pre> 1391/etc/postfix/main.cf: 1392 smtpd_sasl_local_domain = example.com 1393</pre> 1394</blockquote> 1395 1396<p> This is useful as a default setting and safety net for misconfigured 1397clients, or during a migration to an authentication method/backend 1398that requires an authentication REALM or domain name, before all 1399SMTP clients are configured to send such information. </p> 1400 1401<h4><a name="id397205">Hiding SASL authentication from clients or 1402networks</a></h4> 1403 1404<p> Some clients insist on using SASL authentication if it is offered, even 1405when they are not configured to send credentials - and therefore 1406they will always fail and disconnect. </p> 1407 1408<p> Postfix can hide the AUTH capability from these clients/networks: </p> 1409 1410<blockquote> 1411<pre> 1412/etc/postfix/main.cf: 1413 smtpd_sasl_exceptions_networks = !192.0.2.171/32, 192.0.2.0/24 1414</pre> 1415</blockquote> 1416 1417<h4><a name="id397226">Adding the SASL login name to mail headers</a></h4> 1418 1419<p> To report SASL login names in Received: message headers (Postfix 1420version 2.3 and later): </p> 1421 1422<blockquote> 1423<pre> 1424/etc/postfix/main.cf: 1425 smtpd_sasl_authenticated_header = yes 1426</pre> 1427</blockquote> 1428 1429<blockquote> 1430 1431<strong>Note</strong> 1432 1433<p> The SASL login names will be shared with the entire world. </p> 1434 1435</blockquote> 1436 1437<h3><a name="server_test">Testing SASL authentication in the Postfix SMTP Server</a></h3> 1438 1439<p> To test the server side, connect (for example, with 1440<code>telnet</code>) to the Postfix SMTP server port and you should 1441be able to have a conversation as shown below. Information sent by 1442the client (that is, you) is shown in bold font. </p> 1443 1444<blockquote> 1445<pre> 1446% <strong>telnet server.example.com 25</strong> 1447... 1448220 server.example.com ESMTP Postfix 1449<strong>EHLO client.example.com</strong> 1450250-server.example.com 1451250-PIPELINING 1452250-SIZE 10240000 1453250-ETRN 1454250-AUTH DIGEST-MD5 PLAIN CRAM-MD5 1455250 8BITMIME 1456<strong>AUTH PLAIN AHRlc3QAdGVzdHBhc3M=</strong> 1457235 Authentication successful 1458</pre> 1459</blockquote> 1460 1461<p> Instead of <code>AHRlc3QAdGVzdHBhc3M=</code>, specify the 1462base64-encoded form of <code>\0username\0password</code> (the \0 1463is a null byte). The example above is for a user named `<code>test</code>' 1464with password `<code>testpass</code>'. </p> 1465<blockquote> 1466 1467<strong>Caution</strong> 1468 1469<p> When posting logs of the SASL negotiations to public lists, 1470please keep in mind that username/password information is trivial 1471to recover from the base64-encoded form. </p> 1472 1473</blockquote> 1474 1475<p> You can use one of the following commands to generate base64 1476encoded authentication information: </p> 1477 1478<blockquote> 1479<pre> 1480% <strong>gen-auth plain</strong> 1481username: <strong><em>username</em></strong> 1482password: 1483</pre> 1484</blockquote> 1485 1486<p> The <strong>gen-auth</strong> Perl script was written by John 1487Jetmore and can be found at http://jetmore.org/john/code/gen-auth. </p> 1488 1489<blockquote> 1490<pre> 1491% <strong>printf '\0<em>username</em>\0<em>password</em>' | mmencode</strong> 1492</pre> 1493</blockquote> 1494 1495<p> The <strong>mmencode</strong> command is part of the metamail 1496software. </p> 1497 1498<blockquote> 1499<pre> 1500% <strong>perl -MMIME::Base64 -e \ 1501 'print encode_base64("\0<em>username</em>\0<em>password</em>");'</strong> 1502</pre> 1503</blockquote> 1504 1505<p> MIME::Base64 is available from http://www.cpan.org/. </p> 1506 1507<h2><a name="client_sasl">Configuring SASL authentication in the Postfix SMTP/LMTP client</a></h2> 1508 1509<p> The Postfix SMTP and the LMTP client can authenticate with a 1510remote SMTP server via the Cyrus SASL framework. At this time, the 1511Dovecot SASL implementation does not provide client functionality. 1512</p> 1513 1514<blockquote> 1515 1516<strong>Note</strong> 1517 1518<p> The examples in this section discuss only the SMTP client. 1519Replace <code>smtp_</code> with <code>lmtp_</code> to get the 1520corresponding LMTP client configuration. </p> 1521 1522</blockquote> 1523 1524<p> You can read more about the following topics: </p> 1525 1526<ul> 1527 1528<li><a href="#client_sasl_enable">Enabling SASL authentication in 1529the Postfix SMTP/LMTP client</a></li> 1530 1531<li><a href="#client_sasl_sender">Configuring sender-dependent SASL 1532authentication</a></li> 1533 1534<li><a href="#client_sasl_policy">Postfix SMTP/LMTP client policy 1535- SASL mechanism <em>properties</em></a></li> 1536 1537<li><a href="#client_sasl_filter">Postfix SMTP/LMTP client policy 1538- SASL mechanism <em>names</em></a></li> 1539 1540</ul> 1541 1542<h3><a name="client_sasl_enable">Enabling SASL authentication in the 1543Postfix SMTP/LMTP client</a></h3> 1544 1545<p> This section shows a typical scenario where the Postfix SMTP 1546client sends all messages via a mail gateway server that requires 1547SASL authentication. </p> 1548 1549<blockquote> 1550 1551<strong> Trouble solving tips: </strong> 1552 1553<ul> 1554 1555<li> <p> If your SASL logins fail with "SASL authentication failure: 1556No worthy mechs found" in the mail logfile, then see the section 1557"<a href="SASL_README.html#client_sasl_policy">Postfix SMTP/LMTP 1558client policy - SASL mechanism <em>properties</em></a>". 1559 1560<li> <p> For a solution to a more obscure class of SASL authentication 1561failures, see "<a href="SASL_README.html#client_sasl_filter">Postfix 1562SMTP/LMTP client policy - SASL mechanism <em>names</em></a>". 1563 1564</ul> 1565 1566</blockquote> 1567 1568<p> To make the example more readable we introduce it in two parts. 1569The first part takes care of the basic configuration, while the 1570second part sets up the username/password information. </p> 1571 1572<blockquote> 1573<pre> 1574/etc/postfix/main.cf: 1575 smtp_sasl_auth_enable = yes 1576 relayhost = [mail.isp.example] 1577 # Alternative form: 1578 # relayhost = [mail.isp.example]:submission 1579 smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd 1580</pre> 1581</blockquote> 1582 1583<ul> 1584 1585<li> <p> The <code>smtp_sasl_auth_enable</code> setting enables 1586client-side authentication. We will configure the client's username 1587and password information in the second part of the example. </p> 1588</li> 1589 1590<li> <p> The <code>relayhost</code> setting forces the Postfix SMTP 1591to send all remote messages to the specified mail server instead 1592of trying to deliver them directly to their destination. </p> </li> 1593 1594<li> <p> In the <code>relayhost</code> setting, the "<code>[</code>" 1595and "<code>]</code>" prevent the Postfix SMTP client from looking 1596up MX (mail exchanger) records for the enclosed name. </p> </li> 1597 1598<li> <p> The <code>relayhost</code> destination may also specify a 1599non-default TCP port. For example, the alternative form 1600<code>[mail.isp.example]:submission</code> tells Postfix to connect 1601to TCP network port 587, which is reserved for email client 1602applications. </p> </li> 1603 1604<li> <p> The Postfix SMTP client is compatible with SMTP servers 1605that use the non-standard "<code>AUTH=<em>method.</em>...</code>" 1606syntax in response to the EHLO command; this requires no additional 1607Postfix client configuration. </p> </li> 1608 1609<li> <p> The Postfix SMTP client does not support the obsolete 1610"wrappermode" protocol, which uses TCP port <code>465</code> on the 1611SMTP server. See TLS_README for a solution that uses the 1612<code>stunnel</code> command. </p> </li> 1613 1614<li> <p> With the <code>smtp_sasl_password_maps</code> parameter, 1615we configure the Postfix SMTP client to send username and password 1616information to the mail gateway server. As discussed in the next 1617section, the Postfix SMTP client supports multiple ISP accounts. 1618For this reason the username and password are stored in a table 1619that contains one username/password combination for each mail gateway 1620server. </p> 1621 1622</ul> 1623 1624<blockquote> 1625<pre> 1626/etc/postfix/sasl_passwd: 1627 # destination credentials 1628 [mail.isp.example] username:password 1629 # Alternative form: 1630 # [mail.isp.example]:submission username:password 1631</pre> 1632</blockquote> 1633 1634<blockquote> 1635 1636<strong>Important</strong> 1637 1638<p> Keep the SASL client password file in <code>/etc/postfix</code>, 1639and make the file read+write only for <code>root</code> to protect 1640the username/password combinations against other users. The Postfix 1641SMTP client will still be able to read the SASL client passwords. 1642It opens the file as user <code>root</code> before it drops privileges, 1643and before entering an optional chroot jail. </p> 1644 1645</blockquote> 1646 1647<ul> 1648 1649<li> <p> Use the <code>postmap</code> command whenever you 1650change the <code>/etc/postfix/sasl_passwd</code> file. </p> </li> 1651 1652<li> <p> If you specify the "<code>[</code>" and "<code>]</code>" 1653in the <code>relayhost</code> destination, then you must use the 1654same form in the <code>smtp_sasl_password_maps</code> file. </p> 1655</li> 1656 1657<li> <p> If you specify a non-default TCP Port (such as 1658"<code>:submission</code>" or "<code>:587</code>") in the 1659<code>relayhost</code> destination, then you must use the same form 1660in the <code>smtp_sasl_password_maps</code> file. </p> </li> 1661 1662</ul> 1663 1664<h3><a name="client_sasl_sender">Configuring Sender-Dependent SASL 1665authentication</a></h3> 1666 1667<p> Postfix supports different ISP accounts for different sender 1668addresses (version 2.3 and later). This can be useful when one 1669person uses the same machine for work and for personal use, or when 1670people with different ISP accounts share the same Postfix server. 1671</p> 1672 1673<p> To make this possible, Postfix supports per-sender SASL passwords 1674and per-sender relay hosts. In the example below, the Postfix SMTP 1675client will search the SASL password file by sender address before 1676it searches that same file by destination. Likewise, the Postfix 1677trivial-rewrite(8) daemon will search the per-sender relayhost file, 1678and use the default <code>relayhost</code> setting only as a final 1679resort. </p> 1680 1681<blockquote> 1682<pre> 1683/etc/postfix/main.cf: 1684 smtp_sender_dependent_authentication = yes 1685 sender_dependent_relayhost_maps = hash:/etc/postfix/sender_relay 1686 smtp_sasl_auth_enable = yes 1687 smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd 1688 relayhost = [mail.isp.example] 1689 # Alternative form: 1690 # relayhost = [mail.isp.example]:submission 1691</pre> 1692</blockquote> 1693 1694<blockquote> 1695<pre> 1696/etc/postfix/sasl_passwd: 1697 # Per-sender authentication; see also /etc/postfix/sender_relay. 1698 user1@example.com username2:password2 1699 user2@example.net username2:password2 1700 # Login information for the default relayhost. 1701 [mail.isp.example] username:password 1702 # Alternative form: 1703 # [mail.isp.example]:submission username:password 1704</pre> 1705</blockquote> 1706 1707<blockquote> 1708<pre> 1709/etc/postfix/sender_relay: 1710 # Per-sender provider; see also /etc/postfix/sasl_passwd. 1711 user1@example.com [mail.example.com]:submission 1712 user2@example.net [mail.example.net] 1713</pre> 1714</blockquote> 1715 1716<ul> 1717 1718<li> <p> If you are creative, then you can try to combine the two 1719tables into one single MySQL database, and configure different 1720Postfix queries to extract the appropriate information. </p> 1721 1722<li> <p> Specify dbm instead of hash if your system uses dbm files 1723instead of db files. To find out what lookup tables Postfix supports, 1724use the command "postconf -m". </p> 1725 1726<li> <p> Execute the command "postmap /etc/postfix/sasl_passwd" 1727whenever you change the sasl_passwd table. </p> 1728 1729<li> <p> Execute the command "postmap /etc/postfix/sender_relay" 1730whenever you change the sender_relay table. </p> 1731 1732</ul> 1733 1734<h3><a name="client_sasl_policy">Postfix SMTP/LMTP client policy - 1735SASL mechanism <em>properties</em></a></h3> 1736 1737<p> Just like the Postfix SMTP server, the SMTP client has a policy 1738that determines which SASL mechanisms are acceptable, based on their 1739properties. The next two sections give examples of how these policies 1740are used. </p> 1741 1742<blockquote> 1743 1744<table border="1"> 1745 1746<tr> <th>Property</th> <th>Description</th> </tr> 1747 1748<tr> <td>noanonymous</td> <td> Don't use mechanisms that permit 1749anonymous authentication. </td> </tr> 1750 1751<tr> <td>noplaintext</td> <td> Don't use mechanisms that transmit 1752unencrypted username and password information. </td> </tr> 1753 1754<tr> <td>nodictionary</td> <td> Don't use mechanisms that are 1755vulnerable to dictionary attacks. </td> </tr> 1756 1757<tr> <td>mutual_auth</td> <td> Use only mechanisms that authenticate 1758both the client and the server to each other. </td> </tr> 1759 1760</table> 1761 1762</blockquote> 1763 1764<h4>Unencrypted SMTP session</h4> 1765 1766<p> The default policy is stricter than that of the Postfix SMTP 1767server - plaintext mechanisms are not allowed (nor is any anonymous 1768mechanism): </p> 1769 1770<blockquote> 1771<pre> 1772/etc/postfix/main.cf: 1773 smtp_sasl_security_options = noplaintext, noanonymous 1774</pre> 1775</blockquote> 1776 1777<p> This default policy, which allows no plaintext passwords, leads 1778to authentication failures if the remote server only offers plaintext 1779authentication mechanisms (the SMTP server announces "<code>AUTH 1780PLAIN LOGIN</code>"). In such cases the SMTP client will log the 1781following error message: </p> 1782 1783<blockquote> 1784<pre> 1785SASL authentication failure: No worthy mechs found 1786</pre> 1787</blockquote> 1788 1789<blockquote> 1790 1791<strong>Note</strong> 1792 1793<p> This same error message will also be logged when the 1794<code>libplain.so</code> or <code>liblogin.so</code> modules are 1795not installed in the <code>/usr/lib/sasl2</code> directory. </p> 1796 1797</blockquote> 1798 1799<p> The less secure approach is to lower the security standards and 1800permit plaintext authentication mechanisms: </p> 1801 1802<blockquote> 1803<pre> 1804/etc/postfix/main.cf: 1805 smtp_sasl_security_options = noanonymous 1806</pre> 1807</blockquote> 1808 1809<p> If the remote server supports TLS, you can protect the plaintext 1810username and password by turning on TLS in the Postfix SMTP client 1811(see: TLS_README), and configuring the client as discussed next. 1812 1813<h4>Encrypted SMTP session (TLS)</h4> 1814 1815<p> A separate parameter controls Postfix SASL mechanism policy 1816during a TLS-encrypted SMTP session. The default is to copy the 1817settings from the unencrypted session: </p> 1818 1819<blockquote> 1820<pre> 1821/etc/postfix/main.cf: 1822 smtp_sasl_tls_security_options = $smtp_sasl_security_options 1823</pre> 1824</blockquote> 1825 1826<p> A more sophisticated policy allows plaintext mechanisms, but 1827only over a TLS-encrypted connection: </p> 1828 1829<blockquote> 1830<pre> 1831/etc/postfix/main.cf: 1832 smtpd_sasl_security_options = noanonymous, noplaintext 1833 smtpd_sasl_tls_security_options = noanonymous 1834</pre> 1835</blockquote> 1836 1837<h3><a name="client_sasl_filter">Postfix SMTP/LMTP client policy - 1838SASL mechanism <em>names</em></a></h3> 1839 1840<p> Unfortunately, Postfix needs a second client policy for SASL 1841mechanism selection. Reason: the Cyrus SASL library will choose 1842the most secure authentication mechanism that both the SMTP client 1843and server implement - even if one of the parties was not configured 1844for that mechanism. </p> 1845 1846<p> To prevent this, the Postfix SMTP client can filter the names 1847of the authentication mechanisms from the remote SMTP server. Used 1848correctly, the filter hides unwanted mechanisms from the Cyrus SASL 1849library, forcing the library to choose from the mechanisms the 1850Postfix SMTP client filter passes through. </p> 1851 1852<p> The following example filters out everything but the mechanisms 1853<code>PLAIN</code> and <code>LOGIN</code>: </p> 1854 1855<blockquote> 1856<pre> 1857/etc/postfix/main.cf: 1858 smtp_sasl_mechanism_filter = plain, login 1859</pre> 1860</blockquote> 1861 1862<blockquote> 1863 1864<strong>Note</strong> 1865 1866<p> If the remote server does not offer any of the mechanisms on 1867the filter list, authentication will fail. </p> 1868 1869</blockquote> 1870 1871<p> We close this section with an example that passes every mechanism 1872except for <code>GSSAPI</code> and <code>LOGIN</code>: </p> 1873 1874<blockquote> 1875<pre> 1876/etc/postfix/main.cf: 1877 smtp_sasl_mechanism_filter = !gssapi, !login, static:all 1878</pre> 1879</blockquote> 1880 1881<h2><a name="postfix_build">Building Postfix with SASL support</a></h2> 1882 1883<p> As mentioned elsewhere, Postfix supports two SASL implementations: 1884Cyrus SASL (SMTP client and server) and Dovecot SASL (SMTP server 1885only). Both implementations can be built into Postfix simultaneously. 1886</p> 1887 1888<ul> 1889 1890<li><a href="#build_dovecot">Building Dovecot SASL support</a></li> 1891 1892<li><a href="#sasl_support">Building Cyrus SASL support</a></li> 1893 1894</ul> 1895 1896<h3><a name="build_dovecot">Building Dovecot SASL support</a></h3> 1897 1898<p> These instructions assume that you build Postfix from source 1899code as described in the INSTALL document. Some modification may 1900be required if you build Postfix from a vendor-specific source 1901package. </p> 1902 1903<p> Support for the Dovecot version 1 SASL protocol is available 1904in Postfix 2.3 and later. At the time of writing, only server-side 1905SASL support is available, so you can't use it to authenticate the 1906Postfix SMTP client to your network provider's server. </p> 1907 1908<p> Dovecot uses its own daemon process for authentication. This 1909keeps the Postfix build process simple, because there is no need 1910to link extra libraries into Postfix. </p> 1911 1912<p> To generate the necessary Makefiles, execute the following in 1913the Postfix top-level directory: </p> 1914 1915<blockquote> 1916<pre> 1917% <strong>make tidy</strong> # if you have left-over files from a previous build 1918% <strong>make makefiles CCARGS='-DUSE_SASL_AUTH \ 1919 -DDEF_SERVER_SASL_TYPE=\"dovecot\"'</strong> 1920</pre> 1921</blockquote> 1922 1923<p> After this, proceed with "<code>make</code>" as described in 1924the INSTALL document. </p> 1925 1926<strong>Note</strong> 1927 1928<ul> 1929 1930<li> 1931 1932<p> The <code>-DDEF_SERVER_SASL_TYPE=\"dovecot\"</code> is not 1933necessary; it just makes Postfix configuration a little more 1934convenient because you don't have to specify the SASL plug-in type 1935in the Postfix main.cf file (but this may cause surprises when you 1936switch to a later Postfix version that is built with the default 1937SASL type of <code>sasl</code>). </p> 1938 1939</li> 1940 1941<li> 1942 1943<p> If you also want support for LDAP or TLS (or for Cyrus SASL), 1944you need to merge their <code>CCARGS</code> and <code>AUXLIBS</code> 1945options into the above command line; see the LDAP_README and 1946TLS_README for details. </p> 1947 1948<blockquote> 1949<pre> 1950% <strong>make tidy</strong> # if you have left-over files from a previous build 1951% <strong>make makefiles CCARGS='-DUSE_SASL_AUTH \ 1952 -DDEF_SERVER_SASL_TYPE=\"dovecot\" \ 1953 ...<i>CCARGS options for LDAP or TLS etc.</i>...' \ 1954 AUXLIBS='...<i>AUXLIBS options for LDAP or TLS etc.</i>...'</strong> 1955</pre> 1956</blockquote> 1957 1958</li> 1959 1960</ul> 1961 1962<h3><a name="sasl_support">Building Cyrus SASL support</a></h3> 1963 1964<h4><a name="build_sasl">Building the Cyrus SASL library</a></h4> 1965 1966<p> Postfix works with cyrus-sasl-1.5.x or cyrus-sasl-2.1.x, which are 1967available from ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/. </p> 1968 1969<blockquote> 1970 1971<strong>Important</strong> 1972 1973<p> If you install the Cyrus SASL libraries as per the default, you will have 1974to create a symlink <code>/usr/lib/sasl</code> -> 1975<code>/usr/local/lib/sasl</code> for version 1.5.x or 1976<code>/usr/lib/sasl2</code> -> <code>/usr/local/lib/sasl2</code> 1977for version 2.1.x. </p> 1978 1979</blockquote> 1980 1981<p> Reportedly, Microsoft Outlook (Express) requires the non-standard LOGIN 1982and/or NTLM authentication mechanism. To enable these authentication 1983mechanisms, build the Cyrus SASL libraries with: </p> 1984 1985<blockquote> 1986<pre> 1987% <strong>./configure --enable-login --enable-ntlm</strong> 1988</pre> 1989</blockquote> 1990 1991<h4><a name="build_postfix">Building Postfix with Cyrus SASL support</a></h4> 1992 1993<p> These instructions assume that you build Postfix from source 1994code as described in the INSTALL document. Some modification may 1995be required if you build Postfix from a vendor-specific source 1996package. </p> 1997 1998<p> The following assumes that the Cyrus SASL include files are in 1999<code>/usr/local/include</code>, and that the Cyrus SASL libraries are in 2000<code>/usr/local/lib</code>. </p> 2001 2002<p> On some systems this generates the necessary <code>Makefile</code> 2003definitions: </p> 2004 2005<dl> 2006 2007<dt>Cyrus SASL version 2.1.x</dt> 2008 2009<dd> 2010 2011<pre> 2012% <strong>make tidy</strong> # if you have left-over files from a previous build 2013% <strong>make makefiles CCARGS="-DUSE_SASL_AUTH -DUSE_CYRUS_SASL \ 2014 -I/usr/local/include/sasl" AUXLIBS="-L/usr/local/lib -lsasl2"</strong> 2015</pre> 2016 2017</dd> 2018 2019<dt>Cyrus SASL version 1.5.x</dt> 2020 2021<dd> 2022 2023<pre> 2024% <strong>make tidy</strong> # if you have left-over files from a previous build 2025% <strong>make makefiles CCARGS="-DUSE_SASL_AUTH -DUSE_CYRUS_SASL \ 2026 -I/usr/local/include" AUXLIBS="-L/usr/local/lib -lsasl"</strong> 2027</pre> 2028 2029</dd> 2030 2031</dl> 2032 2033<p> On Solaris 2.x you need to specify run-time link information, 2034otherwise the ld.so run-time linker will not find the SASL shared 2035library: </p> 2036 2037<dl> 2038 2039<dt>Cyrus SASL version 2.1.x</dt> 2040 2041<dd> 2042 2043<pre> 2044% <strong>make tidy</strong> # remove left-over files from a previous build 2045% <strong>make makefiles CCARGS="-DUSE_SASL_AUTH -DUSE_CYRUS_SASL \ 2046 -I/usr/local/include/sasl" AUXLIBS="-L/usr/local/lib \ 2047 -R/usr/local/lib -lsasl2"</strong> 2048</pre> 2049 2050</dd> 2051 2052<dt>Cyrus SASL version 1.5.x</dt> 2053 2054<dd> 2055 2056<pre> 2057% <strong>make tidy</strong> # if you have left-over files from a previous build 2058% <strong>make makefiles CCARGS="-DUSE_SASL_AUTH -DUSE_CYRUS_SASL \ 2059 -I/usr/local/include" AUXLIBS="-L/usr/local/lib \ 2060 -R/usr/local/lib -lsasl"</strong> 2061</pre> 2062 2063</dd> 2064 2065</dl> 2066 2067<h2><a name="cyrus_legacy">Using Cyrus SASL version 1.5.x</a></h2> 2068 2069<p> Postfix supports Cyrus SASL version 1.x, but you shouldn't use 2070it unless you are forced to. The makers of Cyrus SASL write: </p> 2071 2072<blockquote> <i> This library is being deprecated and applications 2073should transition to using the SASLv2 library</i> (source: <a 2074href="http://cyrusimap.web.cmu.edu/downloads.html">Project Cyrus: 2075Downloads</a>). </blockquote> 2076 2077<p> If you still need to set it up, here's a quick rundown: </p> 2078 2079<p> Read the regular section on SMTP server configurations for the 2080Cyrus SASL framework. The differences are: </p> 2081 2082<ul> 2083 2084<li> <p> Cyrus SASL version 1.5.x searches for configuration 2085(<code>smtpd.conf</code>) in <code>/usr/lib/sasl/</code> only. You 2086must place the configuration in that directory. Some systems may 2087have modified Cyrus SASL and put the files into e.g. 2088<code>/var/lib/sasl/</code>. </p> </li> 2089 2090<li> <p> Use the <code>saslpasswd</code> command instead of 2091<code>saslpasswd2</code> to create users in <code>sasldb</code>. 2092</p> </li> 2093 2094<li> <p> Use the <code>sasldblistusers</code> command instead of 2095<code>sasldblistusers2</code> to find users in <code>sasldb</code>. 2096</p> </li> 2097 2098<li> <p> In the <code>smtpd.conf</code> file you can't use 2099<code>mech_list</code> to limit the range of mechanisms offered. 2100Instead, remove their libraries from <code>/usr/lib/sasl/</code> 2101(and remember remove those files again when a system update 2102re-installs new versions). </p> </li> 2103 2104</ul> 2105 2106<h2><a name="credits">Credits</a></h2> 2107 2108<ul> 2109 2110<li> Postfix SASL support was originally implemented by Till Franke 2111of SuSE Rhein/Main AG. </li> 2112 2113<li> Wietse trimmed down the code to only the bare necessities. 2114 </li> 2115 2116<li> Support for Cyrus SASL version 2 was contributed by Jason Hoos. 2117</li> 2118 2119<li> Liviu Daia added smtpd_sasl_application_name, separated 2120reject_sender_login_mismatch into 2121reject_authenticated_sender_login_mismatch and 2122reject_unauthenticated_sender_login_mismatch, and revised the docs. 2123 </li> 2124 2125<li> Wietse made another iteration through the code to add plug-in 2126support for multiple SASL implementations, and for reasons that 2127have been lost, also changed smtpd_sasl_application_name into 2128smtpd_sasl_path. </li> 2129 2130<li> The Dovecot SMTP server-only plug-in was originally implemented 2131by Timo Sirainen of Procontrol, Finland. </li> 2132 2133<li> Patrick Ben Koetter revised this document for Postfix 2.4 and 2134made much needed updates. </li> 2135 2136<li> Patrick Ben Koetter revised this document again for Postfix 21372.7 and made much needed updates. </li> 2138 2139</ul> 2140 2141</body> 2142 2143</html> 2144 2145