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