Difference between revisions of "Postfix: Authentikasi SMTP untuk Client"

From OnnoWiki
Jump to navigation Jump to search
Line 1: Line 1:
 
Sumber: http://postfix.state-of-mind.de/patrick.koetter/smtpauth/smtp_auth_mailclients.html
 
Sumber: http://postfix.state-of-mind.de/patrick.koetter/smtpauth/smtp_auth_mailclients.html
  
 
 
How to enable user authentication for a Postfix SMTP server with SASL
 
Last updated on January 28, 2014 Authored by Sarmed Rahman 4 Comments
 
  
 
Every mail server administrator dreads his or her server becoming compromised by spammers. A lot of effort, time and even money is spent on securing mail servers and making sure that the servers do not become open relay.
 
Every mail server administrator dreads his or her server becoming compromised by spammers. A lot of effort, time and even money is spent on securing mail servers and making sure that the servers do not become open relay.
Line 18: Line 14:
 
     SSL/TLS support for the mail server3  
 
     SSL/TLS support for the mail server3  
  
Preparing Dovecot
+
==Preparing Dovecot==
  
 
Backing up configuration files prior to modification is always a good idea.
 
Backing up configuration files prior to modification is always a good idea.
Line 25: Line 21:
  
 
First of all, a listener is added to Dovecot. Postfix will use this listener to communicate with Dovecot.
 
First of all, a listener is added to Dovecot. Postfix will use this listener to communicate with Dovecot.
root@mail:~# vim /etc/dovecot/conf.d/10-master.conf
 
  
## The listener is added under the service auth section ##
+
vim /etc/dovecot/conf.d/10-master.conf
service auth {
+
 
unix_listener /var/spool/postfix/private/auth {
+
## The listener is added under the service auth section ##
mode = 0660
+
service auth {  
        user = postfix
+
unix_listener /var/spool/postfix/private/auth {
        group = postfix
+
mode = 0660
  } ##end listener
+
        user = postfix
} ## end service auth
+
        group = postfix
 +
  } ##end listener
 +
} ## end service auth
  
 
The above definition places the socket to be used by Postfix at /var/spool/postfix/private/auth with permission 0660 for Postfix only.
 
The above definition places the socket to be used by Postfix at /var/spool/postfix/private/auth with permission 0660 for Postfix only.
root@mail:~# vim /etc/dovecot/conf.d/10-auth.conf
 
  
auth_mechanisms = plain login
+
vim /etc/dovecot/conf.d/10-auth.conf
 +
 
 +
auth_mechanisms = plain login
  
 
The above parameter provides the plain login authentication mechanisms for Postfix.
 
The above parameter provides the plain login authentication mechanisms for Postfix.
  
 
Finally, for the changes to take effect, we restart the Dovecot service as follows.
 
Finally, for the changes to take effect, we restart the Dovecot service as follows.
root@mail:~# service dovecot restart
 
  
Preparing Postfix
+
service dovecot restart
 +
 
 +
==Preparing Postfix==
  
 
Necessary SST/TLS and SASL parameters are added in the configuration file main.cf.
 
Necessary SST/TLS and SASL parameters are added in the configuration file main.cf.
root@mail:~# vim /etc/postfix/main.cf
 
  
#### SASL ####
+
vim /etc/postfix/main.cf
## specify SASL type ##
 
smtpd_sasl_type = dovecot
 
  
## path to the SASL socket relative to postfix spool directory i.e. /var/spool/postfix ##
+
#### SASL ####
smtpd_sasl_path = private/auth
+
## specify SASL type ##
 +
smtpd_sasl_type = dovecot
  
## postfix appends the domain name for SASL logins that do not have the domain part ##
+
## path to the SASL socket relative to postfix spool directory i.e. /var/spool/postfix ##
smtpd_sasl_local_domain = example.tst
+
smtpd_sasl_path = private/auth
 
+
## SASL default policy ##
+
## postfix appends the domain name for SASL logins that do not have the domain part ##
smtpd_sasl_security_options = noanonymous
+
smtpd_sasl_local_domain = example.tst
 
+
## for legacy application compatibility ##
+
## SASL default policy ##
broken_sasl_auth_clients = yes
+
smtpd_sasl_security_options = noanonymous
 
+
## enable SMTP auth ##
+
## for legacy application compatibility ##
smtpd_sasl_auth_enable = yes
+
broken_sasl_auth_clients = yes
 
+
## smtp checks ##
+
## enable SMTP auth ##
## these checks are based on first match, so sequence is important ##
+
smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
+
 +
## smtp checks ##
 +
## these checks are based on first match, so sequence is important ##
 +
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
  
  
Line 89: Line 89:
  
 
SSL/TLS specific parameters are added to the server as well.
 
SSL/TLS specific parameters are added to the server as well.
root@mail:~# vim /etc/postfix/main.cf
 
  
#### SSL/TLS parameters ####
+
vim /etc/postfix/main.cf
  
## 'encrypt' will enforce SSL. Not recommended for live servers ##
+
#### SSL/TLS parameters ####
smtpd_tls_security_level = may  
+
#smtpd_tls_security_level = encrypt  
+
## 'encrypt' will enforce SSL. Not recommended for live servers ##
 +
smtpd_tls_security_level = may  
 +
#smtpd_tls_security_level = encrypt  
 +
 +
smtpd_tls_received_header = yes
 +
smtpd_tls_auth_only = no
 +
 +
## loglevel 3 or 4 can be used during troubleshooting ##
 +
smtpd_tls_loglevel = 1
 +
 +
## path to certificate and key file ##
 +
smtpd_tls_cert_file = /etc/ssl/certs/postfixcert.pem
 +
smtpd_tls_key_file = /etc/ssl/private/postfixkey.pem
 +
smtpd_use_tls=yes
 +
 +
## server will announce STARTTLS ##
 +
smtp_tls_note_starttls_offer = yes
 +
 +
smtpd_tls_session_cache_timeout = 3600s
 +
 +
Now Postfix is reloaded with updated settings.
  
smtpd_tls_received_header = yes
 
smtpd_tls_auth_only = no
 
  
## loglevel 3 or 4 can be used during troubleshooting ##
+
service postfix restart
smtpd_tls_loglevel = 1
 
 
 
## path to certificate and key file ##
 
smtpd_tls_cert_file = /etc/ssl/certs/postfixcert.pem
 
smtpd_tls_key_file = /etc/ssl/private/postfixkey.pem
 
smtpd_use_tls=yes
 
 
 
## server will announce STARTTLS ##
 
smtp_tls_note_starttls_offer = yes
 
 
 
smtpd_tls_session_cache_timeout = 3600s
 
 
 
Now Postfix is reloaded with updated settings.
 
root@mail:~# service postfix restart
 
  
 
At this point, Postfix will not allow SMTP connections without authentication.
 
At this point, Postfix will not allow SMTP connections without authentication.

Revision as of 05:50, 8 May 2015

Sumber: http://postfix.state-of-mind.de/patrick.koetter/smtpauth/smtp_auth_mailclients.html


Every mail server administrator dreads his or her server becoming compromised by spammers. A lot of effort, time and even money is spent on securing mail servers and making sure that the servers do not become open relay.

To combat against spambots in an SMTP server, Postfix in general uses the mynetworks parameter to specify the trusted sender network i.e., LAN. In a typical scenario, the users stationed in the internal LAN are legitimate users, and Postfix will happily accept SMTP requests from them, and forward the emails towards destination. Although this used to be the standard practice in the past, today's users want mobility. Everyone wants to be able to send/receive emails in their phones/tablets/laptops at work, home, on the go, or even from their favorite coffee shop around the corner. For people who are in the fields for critical services, a simple email alert could save a lot of time, effort and money.

To cope up with the mobility need, Postfix started to support another method of validating users. Simple Authentication and Security Layer (SASL) is a framework that can be used by many connection-oriented Internet protocols for securing data, servers and users. With SASL enabled, Postfix will not accept any incoming SMTP connections without proper authentication. As smart spammer can imitate a legitimate email account, no SMTP from even internal users are accepted without authentication.

This tutorial will focus on setting up a Postfix SMTP server to use Dovecot SASL for user authentication. As Dovecot provides mechanisms for user authentication, Postfix will simply ask Dovecot to do the work for it. That way, there is no need to re-invent the wheel. Prerequisites

   A working mail server running on postfix and dovecot2
   SSL/TLS support for the mail server3 

Preparing Dovecot

Backing up configuration files prior to modification is always a good idea.

Since Dovecot will be the one doing most of the work, we will start configuration with Dovecot.

First of all, a listener is added to Dovecot. Postfix will use this listener to communicate with Dovecot.

vim /etc/dovecot/conf.d/10-master.conf
## The listener is added under the service auth section ##
service auth { 
	unix_listener /var/spool/postfix/private/auth {
		mode = 0660
        	user = postfix
        	group = postfix
  	} ##end listener
} ## end service auth

The above definition places the socket to be used by Postfix at /var/spool/postfix/private/auth with permission 0660 for Postfix only.

vim /etc/dovecot/conf.d/10-auth.conf
auth_mechanisms = plain login

The above parameter provides the plain login authentication mechanisms for Postfix.

Finally, for the changes to take effect, we restart the Dovecot service as follows.

service dovecot restart

Preparing Postfix

Necessary SST/TLS and SASL parameters are added in the configuration file main.cf.

vim /etc/postfix/main.cf
#### SASL ####
## specify SASL type ##
smtpd_sasl_type = dovecot
## path to the SASL socket relative to postfix spool directory i.e. /var/spool/postfix ##
smtpd_sasl_path = private/auth

## postfix appends the domain name for SASL logins that do not have the domain part ##
smtpd_sasl_local_domain = example.tst

## SASL default policy ##
smtpd_sasl_security_options = noanonymous

## for legacy application compatibility ##
broken_sasl_auth_clients = yes

## enable SMTP auth ##
smtpd_sasl_auth_enable = yes

## smtp checks ##
## these checks are based on first match, so sequence is important ##
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination


smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
broken_sasl_auth_clients = yes
... 
smtpd_recipient_restrictions = 
   permit_sasl_authenticated, 
   permit_mynetworks, 
   check_relay_domains


The official guideline can be consulted for more details on available parameters and their function.

SSL/TLS specific parameters are added to the server as well.

vim /etc/postfix/main.cf
#### SSL/TLS parameters ####

## 'encrypt' will enforce SSL. Not recommended for live servers ##
smtpd_tls_security_level = may 
#smtpd_tls_security_level = encrypt 

smtpd_tls_received_header = yes 
smtpd_tls_auth_only = no 

## loglevel 3 or 4 can be used during troubleshooting ##
smtpd_tls_loglevel = 1 

## path to certificate and key file ##
smtpd_tls_cert_file = /etc/ssl/certs/postfixcert.pem 
smtpd_tls_key_file = /etc/ssl/private/postfixkey.pem 
smtpd_use_tls=yes 

## server will announce STARTTLS ##
smtp_tls_note_starttls_offer = yes 

smtpd_tls_session_cache_timeout = 3600s 

Now Postfix is reloaded with updated settings.


service postfix restart

At this point, Postfix will not allow SMTP connections without authentication. Mail User Agent Configuration

Your mail client is configured with mandatory authentication for SMTP as shown below.

Troubleshooting

If SASL is not working correctly, the following troubleshooting may help. Enabling Verbose Postfix Logs

To increase the level of output in Postfix log, the "-v" parameter can be added in the following file. root@mail:/etc/postfix# vim /etc/postfix/master.cf

smtp inet n - - - - smtpd -v

Now there should be more verbose information the log file at /var/log/mail.log, which can help with the troubleshooting process. Telnet to port 25

telnet connection to port 25 should be successful. $ telnet mail.example.tst 25

ehlo mail.example.tst 250- mail.example.tst 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-STARTTLS 250-AUTH PLAIN LOGIN 250-AUTH=PLAIN LOGIN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN

Amongst other features that the SMTP server advertises, the STARTTLS and AUTH features should be available.

Sending mails using telnet should fail, and no authentication information should be sent to the server. $ telnet mail.example.tst 25

ehlo mail.example.tst mail from:sarmed@example.tst 250 2.1.0 Ok rcpt to:sarmed@example.tst 554 5.7.1 : Relay access denied

Tuning parameter – mynetworks

Earlier in the tutorial, the Postfix server was configured to allow SMTP connections originated in the trusted network i.e., mynetworks, as shown in /etc/postfix/main.cf.

smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination

To make sure that mails originating from mynetworks do not pass through unauthenticated, /etc/postfix/main.cf can be modified as follows.

smtpd_recipient_restrictions = permit_sasl_authenticated, reject_unauth_destination

Based on the requirements, permit_mynetworks can be allowed or denied later on.

To sum up, SASL can provide additional security to a mail server by enforcing mandatory authentication to users for SMTP requests. As users may use a mail server from anywhere, SASL can meet with the security requirements that do not conflict with the mobility of users.

Hope this helps.






Referensi