- 论坛徽章:
- 0
|
Postfix-SASL
目錄
1 所需套件
2 Mail Relay 簡介
3 讓 Postfix 支援 Cyrus-SASL? V2 認証:(Debian Sarge)
4 檢測方式
所需套件
postfix-tls sasl2-bin libsasl2-modules (apt-get install postfix-tls sasl2-bin libsasl2-modules)
Mail Relay 簡介
所謂的 Mail Relay,指的就是 Mail Server 會不會替使用者將信轉寄到外部去。
比如說,我將信寄給 tetralet@pchome.com.tw,如果 tetralet@pchome.com.tw 這個信箱並不是位於本機上,那麼這封信將會轉給PCHome 的 Mail Server,而這個將郵件轉寄的動作就是 Mail Relay。
Open Relay 就是不設限地完全開放 Mail Relay 的功能,它會替所有的人進行郵件轉寄。
架設 Mail Server 的第一件事,就是防止不速之客利用您的 Mail Server 來亂發郵件,也就是關掉 Open Relay 這個功能。(基本上,幾乎所有的 Mail Server 預設上都已把 Open Relay 給關掉了)取而代之的,是使用 SMTP 認証 (SMTP AUTH) 來驗証使用者可否進行 Mail Relay。
在這裡所要介紹的,是如何使用 Cyrus-SASL? V2 來實作 SMTP 認証的功能。其中的 SASL (Simple Authentication and Security Layer) 就是用來提供符合 RFC 2222 標準的各種認証機制的 Daemon。
讓 Postfix 支援 Cyrus-SASL? V2 認証:(Debian Sarge)
修改 /etc/default/saslauthd,設定 START=yes
# This needs to be uncommented before saslauthd will be run automatically
START=yes
# You must specify the authentication mechanisms you wish to use.
# This defaults to "pam" for PAM support, but may also include
# "shadow" or "sasldb", like this:
# MECHANISMS="pam shadow"
MECHANISMS="pam"
修改 /etc/postfix/sasl/smtpd.conf,設定 PostFix 使用 Saslauthd
mkdir -p /etc/postfix/sasl
echo "pwcheck_method: saslauthd" > /etc/postfix/sasl/smtpd.conf
將 postfix 加入 sasl 群組中
addgroup postfix sasl
修改 /etc/postfix/main.cf,使其使用 SMTP AUTH 及 SASL Authenticate
(上略)
# Enable SASL Auth
# 設定 Postfix 使用 SASL 認証。
smtpd_sasl_auth_enable = yes
# 設定 SASL 支援非標準 E-mail Client 的認証動作。
broken_sasl_auth_clients = yes
# 不使用 ANONYMOUS 這個認証。
smtpd_sasl_security_options = noanonymous
# 設定 SASL 的認証方法
# permit_sasl_authenticated → 如果用戶端可通過 SASL 認証則可 Relay Mail。
# permit_mynetworks → 如果用戶端的位址為 $mynetworks 則可 Relay Mail。
# check_relay_domains
# reject_unauth_destination
smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, check_relay_domains, reject_unauth_destination
smtpd_client_restrictions = permit_sasl_authenticated
修改 /etc/postfix/master.cf,讓 Postfix 不要以 chroot 啟動。
後面的 -v 參數可以用來 Debug,但正式上線時最好拿掉,以免系統被 Log 塞爆了。
(上略)
# ==========================================================================
# service type private unpriv chroot wakeup maxproc command + args
# (yes) (yes) (yes) (never) (100)
# ==========================================================================
smtp inet n - n - - smtpd -v
(下略)
或者是新增一個 listen 在 smtps (port 465) 上的 service
# ==========================================================================
# service type private unpriv chroot wakeup maxproc command + args
# (yes) (yes) (yes) (never) (100)
# ==========================================================================
smtps inet n - n - - smtpd
# 強迫 tls 連線 (?)
-o smtpd_tls_wrappermode=yes
# 使用 sasl auth (如果在 main.cf 已經設定了,這行可以省略)
-o smtpd_sasl_auth_enable=yes
# 所有連線到這裡的都必須通過 sasl auth
-o smtpd_client_restrictions=permit_sasl_authenticated,reject
重新啟動 SASL Daemon
/etc/init.d/saslauthd restart
跑起來後,可以用
testsaslauthd -u username -p password
來測試 saslauthd 是否有正常運作
重新啟動 Postfix
/etc/init.d/postfix restart
[編輯]檢測方式
首先把帳號及密碼轉換成 base64 的編碼:(可能需要安裝 libmime-base64-perl 套件)
perl -MMIME::Base64 -e 'print encode_base64("\0username\0password");'
登入 Postfix:
$ telnet 127.0.0.1 25(在该用户的环境变量下)
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
220 Virtual ESMTP Postfix (Debian/GNU)
EHLO qemu (這裡要輸入的是 HostName)
250-Virtual
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-XVERP
250 8BITMIME
auth plain AHXXXXXXXXXXXXXXXXXXXX8/ (剛才 perl 指令計算的結果)
235 Authentication successful
quit
221 Bye
Connection closed by foreign host.
如果認証成功即表示 SASL 已經正確啟動了。 |
|