harumaki.net

インフラ屋の覚書や、ラーメン食べある記とか。

GNU/Linux infra MAIL postfix サーバー

postfix SMTP-auth実装ログ

投稿日:2004年12月27日

Last Updated on 2022年3月13日 by かんりにん

[pukiwiki]

&topicpath;
 
**▼smtp-AUTH実装ログ [#df955667]
 (UNIXパスワードをメールパスワードとする場合)
  本番環境への実装が完了したので、インストール時の作業ログとして
  再構成します。

【参照サイト】
お世話になっています!!
[[SMTP Authに関する覚え書き:http://solaris.bluecoara.net/servers/postfix/smtpauth.phtml]]
[[postfix-2.0.7 + cyrus-sasl-2.1.12 による samtp-auth 構築記録:http://66.102.7.104/search?q=cache:o720_iOPLEIJ:otanoshike.com/postfix_install.html+libsasl2.so.2+postfix&hl=ja&lr=lang_ja]]

【使用したアプリケーション】

postfix-2.0.16
cyrus-sasl-2.1.20
※postfixは認証追加のための再コンパイルのみ
※cyrus-saslは当初2.1.12を使用してインストールしたが
 postfixとの依存関係でエラーが発生したため
 2.1.20へアップグレードし、エラーを修正。

smtp-authを実装する際、saslpasswdで生成したパスワードを
活用するのが安全だが、メールスワード=UNIXパスワードとしている場合
安全度は下がるが、送信認証時に同じパスワードを使用するほうが
ユーザーが新しいパスワードをセットする手間が省け、楽になる。
※もちろんsaslpasswdを使ったほうが安全なので決してお奨めではない。

-【外部中継認証の要件定義】

・社外・中国支社からのメール送信時にパスワード認証を追加する。
・社内ネットワークからのメール送信はパスワード無しで許可する(今までと同じ)
・認証に使用するパスワードはメール受信時に使用しているパスワードを使用する
 (UNIXパスワード)
・OutlookExplessでの送受信を可能にするため、パスワード認証はLOGIN PLAINを使用する
 セキュリティ強度を保つため、TLSモジュールを実装して認証を暗号化する(別項参照)。
 ※Beckyでも同様に設定すること。

***1)smtp-AUTH用main.cf作成 [#baa16e36]

[user@mailsvr user]$ su –
Password:
[root@mailsvr /root]# cd /etc/postfix/
[root@mailsvr postfix]# cp main.cf main.cf.saslauthed
[root@mailsvr postfix]# vi main.cf.saslauthed

”《追記箇所》”
main.cf最下段

# smtp-AUTH configure
# 2004/12/27
#smtpd_sasl_auth_enable = yes
#smtpd_sasl_local_domain = $mydomain
#smtpd_recipient_restrictions = permit_mynetworks, \
permit_sasl_authenticated,reject_unauth_destination
#broken_sasl_auth_clients = yes
#smtpd_sasl_security_options = noanonymous

# smtp-AUTH configure END

※この段階ではコメントにしておき
 再コンパイル終了後、起動時にコメントアウトして有効にする。

***2)cyrus-saslソース版インストール [#w0b2ee3b]
  ※saslコマンドのsaslauthedを使用するが
   rpm版のsaslには実装されていないため
   ソースをインストール。

[root@mailsvr postfix]# cd /usr/local/src/
[root@mailsvr src]# ls -al | grep sasl
-rw-r–r– 1 root root 1775163 Dec 27 18:13 cyrus-sasl-2.1.12.tar.gz
[root@mailsvr src]# tar -zxvf cyrus-sasl-2.1.12.tar.gz
[root@mailsvr src]# chown -R root:root cyrus-sasl-2.1.12
[root@mailsvr src]# cd cyrus-sasl-2.1.12
[root@mailsvr cyrus-sasl-2.1.12]# env CPPFLAGS=”-I/usr/include” \
LDFLAGS=”-L/usr/lib” ./configure –with-dbpath=/usr/local/etc/sasldb2 \
–with-plugindir=/usr/local/lib/sasl2 –enable-login
[root@mailsvr cyrus-sasl-2.1.12]# make
[root@mailsvr cyrus-sasl-2.1.12]# make install

”※※saslauthedがあることを確認。”

[user@mailsvr cyrus-sasl-2.1.12]$ ls /usr/local/sbin/sasl
saslauthd sasldblistusers2 saslpasswd2
sasldblistusers saslpasswd

-[シンボリックリンク/usr/lib/sasl2作成]

[root@mailsvr cyrus-sasl-2.1.20]# ln -s /usr/local/lib/sasl2/ /usr/lib/sasl2
[root@mailsvr cyrus-sasl-2.1.20]# cd /usr/lib/sasl2
[root@mailsvr sasl2]# pwd
/usr/lib/sasl2
[root@mailsvr cyrus-sasl-2.1.20]# cd /usr/lib
[root@mailsvr lib]# ls -al | grep sasl
lrwxrwxrwx 1 root root 16 Mar 12 2004 libsasl.so.7 ->
libsasl.so.7.1.8*
-rwxr-xr-x 1 root root 49097 Jul 4 2002 libsasl.so.7.1.8*
drwxr-xr-x 2 root root 4096 Mar 11 2004 sasl/
lrwxrwxrwx 1 root root 21 Jan 6 18:20 sasl2 -> /usr/local/lib/sasl2//
[root@mailsvr lib]#

-[sasl2ディレクトリにsmtpd.confを作成]

[root@mailsvr cyrus-sasl-2.1.20]# cd /usr/lib/sasl2/
[root@mailsvr sasl2]# pwd
/usr/lib/sasl2
[root@mailsvr sasl2]# touch smtpd.conf
[root@mailsvr sasl2]# vi smtpd.conf

”《記載内容》”

pwcheck_method:saslauthd
method: login plain

***3)saslauthdの実行環境を設定 [#j9101dba]

3−1:[ディレクトリ/var/state/saslauthdを作成]
    saslauthd実行時のpidファイルが入る。

[root@mailsvr /root]# mkdir -p /var/state/saslauthd
[root@mailsvr /root]# ls -al /var/state/saslauthd/
total 8
drwxr-xr-x 2 root root 4096 Jan 6 18:25 ./
drwxr-xr-x 3 root root 4096 Jan 6 18:25 ../
[root@mailsvr /root]#

3−2:[認証テスト用スクリプト作成]
    saslauthdの確認テストにはtestsaslauthdというスクリプトを使用する。
    これは展開したcyrus-sasl-2.1.20以下にあるsaslauthdディレクトリで
    コンパイルする。

[root@mailsvr /root]# cd /usr/local/src/cyrus-sasl-2.1.20
[root@mailsvr cyrus-sasl-2.1.20]# ls -al | grep auth
drwxr-xr-x 6 root root 4096 Jan 6 18:28 saslauthd/
[root@mailsvr cyrus-sasl-2.1.20]#
[root@mailsvr cyrus-sasl-2.1.20]# cd saslauthd/
[root@mailsvr saslauthd]# make testsaslauthd
[root@mailsvr saslauthd]# ls -al | grep test
-rwxr-xr-x 1 root root 53732 Jan 6 18:28 testsaslauthd*
-rw-r–r– 1 root root 7579 Jan 22 2004 testsaslauthd.c
-rw-r–r– 1 root root 33364 Jan 6 18:28 testsaslauthd.o
[root@mailsvr saslauthd]#

3−3:プロセス起動

[root@mailsvr saslauthd]# /usr/local/sbin/saslauthd -a shadow

    オプション“-a”で対象とするパスワードを指定できる。
    上記は認証に/etc/shadowを使用する。

”《プロセス確認》”

[root@mailsvr saslauthd]# ps -aef | grep sasl
root 23507 1 0 18:33 ? 00:00:00 /usr/local/sbin/saslauthd -a shadow
root 23508 23507 0 18:33 ? 00:00:00 /usr/local/sbin/saslauthd -a shadow
root 23509 23507 0 18:33 ? 00:00:00 /usr/local/sbin/saslauthd -a shadow
root 23510 23507 0 18:33 ? 00:00:00 /usr/local/sbin/saslauthd -a shadow
root 23511 23507 0 18:33 ? 00:00:00 /usr/local/sbin/saslauthd -a shadow
root 23518 10147 0 18:34 pts/2 00:00:00 grep sasl
[root@mailsvr saslauthd]#

3−4:動作テスト

    saslauthd起動後、テストスクリプトで実行。
    /etc/shadowパスワードで起動しているので
    UNIXパスワードでテストする。

書式:./testsaslauthd -u username -p password

[root@mailsvr saslauthd]# ./testsaslauthd -u user -p ******
0: OK “Success.” ←OK “Success.”が出ればOK。

3−5:プロセスの停止

    動作確認できたらプロセスを一旦停止する。
    saslauthdにはプロセス停止のコマンドが無いため
    killコマンドで停止する。オプションは-15(正常終了)でOK。

[root@mailsvr saslauthd]# kill -15 23507
[root@mailsvr saslauthd]# ps -aef | grep sasl
root 23599 10147 0 18:37 pts/2 00:00:00 grep sasl
[root@mailsvr saslauthd]#

[補足]自動起動

 OS起動にあわせて/etc/rc.d/rc.localに起動コマンドを追記しておくとGOOD。
 というかpostfixと同時に起動しないと送信が出来なくなるため
 必ず自動起動にすること。
 chkconfigへ追加してもいいかも。

[root@mailsvr saslauthd]# cd /etc/rc.d/
[root@mailsvr rc.d]# vi rc.local

”《以下をrc.localへ追記》”
## SMTP authentication config SASL
# mailsvr
# 2004/12/27
/usr/local/sbin/saslauthd -a shadow

***4)postfixの再コンパイル [#a93f34bf]

4−1:現在のバージョンを確認

[root@mailsvr postfix]# postconf | grep version
disable_mime_output_conversion = no
mailsvr_version = 2.0.16
[root@mailsvr postfix]#

4−2:オプションつきで再コンパイルを開始
    再コンパイルする際は最初にmake tidyを実行する。

[root@mailsvr postfix]# cd /usr/local/src/postfix-2.0.16
[root@mailsvr postfix-2.0.16]#
[root@mailsvr postfix-2.0.16]# make tidy
[root@mailsvr postfix-2.0.16]# make makefiles CCARGS=”-DUSE_SASL_AUTH
-I/usr/local/include/sasl” AUXLIBS=”-L/usr/local/lib -lsasl2″
[root@mailsvr postfix-2.0.16]# make
[root@mailsvr postfix-2.0.16]# make install

”《エラー発生》”

make install時、コンフィグの確認画面で
config_directoryの段階で以下のようなエラーが出る。

config_directory: [] /etc/postfix
bin/postconf: error while loading shared libraries: libsasl2.so.2: cannot
open shared object file: No such file or directory
bin/postconf: error while loading shared libraries: libsasl2.so.2: cannot
open shared object file: No such file or directory
bin/postconf: error while loading shared libraries: libsasl2.so.2: cannot
open shared object file: No such file or directory
bin/postconf: error while loading shared libraries: libsasl2.so.2: cannot
open shared object file: No such file or directory
〜〜以下ずらずらと出る〜〜

原因を調べたところ、/usr/local/lib/libsasl2.so.2ではなく
/usr/lib/libsasl2.so.2を見に行って“No such”となっていたので
リンクを張ってみる。

[root@mailsvr postfix-2.0.16]# ln – s /usr/local/lib/libsasl2.so.2 /usr/lib/libsasl2.so.2
[root@mailsvr postfix-2.0.16]# updatedb
[root@mailsvr postfix-2.0.16]# locate libsasl2.so.2
/usr/lib/libsasl2.so.2
/usr/local/lib/libsasl2.so.2.0.12
/usr/local/lib/libsasl2.so.2
/usr/local/src/cyrus-sasl-2.1.12/lib/.libs/libsasl2.so.2.0.12
/usr/local/src/cyrus-sasl-2.1.12/lib/.libs/libsasl2.so.2

※このトラブルの参照サイト:
[[http://66.102.7.104/search?q=cache:o720_iOPLEIJ:otanoshike.com/postfix_install.html+libsasl2.so.2+postfix&hl=ja&lr=lang_ja]]

リンクを確認したところで再度インストールを試す。
今度は問題なし。

[root@mailsvr postfix-2.0.16]# make tidy
[root@mailsvr postfix-2.0.16]# make makefiles CCARGS=”-DUSE_SASL_AUTH \
-I/usr/local/include/sasl” AUXLIBS=”-L/usr/local/lib -lsasl2″
[root@mailsvr postfix-2.0.16]# make
[root@mailsvr postfix-2.0.16]# make install

[src/postfix]以下で
”make: Nothing to be done for `update’.”というエラーが出まくったが
その後の確認項目で順調に進めたのでとりあえずそのまま完了する。

※ファイルの更新確認
[root@mailsvr postfix-2.0.16]# ls -al /etc/postfix/

”《更新されたファイル》”
-rw-r–r– 1 root root 26231 Jan 7 11:36 main.cf
-rw-r–r– 1 root root 10672 Jan 7 11:36 main.cf.default
-rw-r–r– 1 root root 8646 Jan 7 11:36 postfix-files
-rw-r–r– 1 root root 7767 Jan 7 11:36 sample-auth.cf
-rw-r–r– 1 root root 9388 Jan 7 11:36 sample-smtp.cf
-rw-r–r– 1 root root 25692 Jan 7 11:36 sample-smtpd.cf

”《追加されたファイル》”
-rw-r–r– 1 root root 24025 Jan 7 11:36 sample-tls.cf

4−3:main.cf確認
    main.cfに追記したsasl用ディレクティブを
    コメントアウトして有効にする。

↓下記をコメントアウト。

# smtp-AUTH configure
# 2004/12/27
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $mydomain
smtpd_recipient_restrictions = permit_mynetworks, \
permit_sasl_authenticated,reject_unauth_destination
broken_sasl_auth_clients = yes
smtpd_sasl_security_options = noanonymous

# smtp-AUTH configure END

4−4:postfix再起動
    ログを流しながら、更新後も異常が無いか
    確認しながらの再起動を行う。

順番は
1 saslauthd起動

[root@mailsvr postfix]# /usr/local/sbin/saslauthd -a shadow

2 postfix再起動

[root@mailsvr postfix]# postfix reload
postfix/postfix-script: refreshing the Postfix mailsvr system

***5)smtp-AUTHの確認 [#ca7110c1]

確認作業は以下のとおり。
1:送受信確認 ・素のまま送る
        ・メーラーを一旦閉じた後、再度起動して行う
2:telnet接続での応答確認
3:postconfでコンフィグを確認

上記1、2を社内・社外から行う。

”《結果》”

2:telnet接続確認
  認証にはAUTH PLAINで確認を行う(こちらが確実な気がしたので)

”書式:”
# perl -MMIME::Base64 -e ‘print encode_base64(“user\0usr\0pass”);’
でユーザー名とパスワードをMINEエンコードしてtelnet接続時にたたく。

[root@mailsvr postfix]# telnet localhost 25
Trying 127.0.0.1…
Connected to localhost.localdomain (127.0.0.1).
Escape character is ‘^]’.
220 example.com ESMTP Postfix
EHLO localhost ←入力
250-example.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH PLAIN DIGEST-MD5 CRAM-MD5 ←確認OK!
250-AUTH=PLAIN DIGEST-MD5 CRAM-MD5 ←確認OK!
250 8BITMIME
AUTH PLAIN ←入力
334
c2FpdG8Ac2FpdG8ATTE3anpwdDQ= ←入力
235 Authentication successful ←認証成功!
quit
221 Bye
Connection closed by foreign host.

ちなみに失敗すると下記のエラーが出る。

AUTH PLAIN
334
c2FpdG8Ac2FpdG8ATTE3anpwdDQ=
535 Error: authentication failed

3:postconfでコンフィグを確認

[root@mailsvr postfix]# postconf | grep sasl
broken_sasl_auth_clients = yes
lmtp_sasl_auth_enable = no
lmtp_sasl_password_maps =
lmtp_sasl_security_options = noplaintext, noanonymous
smtp_sasl_auth_enable = no
smtp_sasl_password_maps =
smtp_sasl_security_options = noplaintext, noanonymous
smtp_sasl_tls_security_options = $var_smtp_sasl_opts
smtp_sasl_tls_verified_security_options = $var_smtp_sasl_tls_opts
smtpd_recipient_restrictions = permit_mynetworks, \
permit_sasl_authenticated,reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $mydomain
smtpd_sasl_security_options = noanonymous
smtpd_sasl_tls_security_options = $smtpd_sasl_security_options

※smtp_sasl_auth_enableなど、いくつかのコンフィグが重複しているので
 main.cfなどによって変更された箇所だけ確認↓

[root@mailsvr postfix]# postconf -n | grep sasl
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_mynetworks,\
permit_sasl_authenticated,reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $mydomain
smtpd_sasl_security_options = noanonymous

↑main.cfの設定がそのまま反映されている。

※あとは自宅(そのほか社外ネットワーク)からexample.comアカウントの
 送受信テストを行って完了。

▼送信ログ確認

smtp-authで認証を受けたアカウントには以下のようなログが出力される。

Dec 27 16:23:12 s_sys@example postfix/smtpd[31995]: 9B4E0BC3B:
client=unknown[
10.10.1.85], sasl_method=LOGIN, sasl_username=user@example.com

***6)Outlookexpressからの送受信確認 [#te8e7f3a]

社外からの送信をする際、smtp-authの設定を行わないと
メール送信時にエラーが発生するため
メーラーにsmtp-auth対応の設定を追加する。

○Outlookexpressの設定変更
 送信時のパスワード認証を有効にするため、以下の設定変更を行う
1)ツールバーの“ツール”→“アカウント”をクリック。
“インターネットアカウント”ダイアログが開く。
2)“メール”タブを開き、該当のアカウントを選択し
“プロパティ”をクリック。プロパティのダイアログが開く。
3)“サーバー”タブをクリックし、一番下にある“送信メールサーバー”欄の
“このサーバは認証が必要”にチェックをつけ、“詳細”ボタンをクリックする。
“送信メールサーバー”のダイアログが開く。
4)“ログオン情報”の“受信メールサーバーと同じ設定を使用する”にチェックを入れ
“OK”をクリックする。
→“送信メールサーバー”のダイアログが閉じる。
5)“プロパティ”ダイアログで“OK”をクリックし、ダイアログを閉じる。
6)“インターネットアカウント”ダイアログの“閉じる”をクリック。

上記で設定は終了。
一度OutlookExpressを終了し、再度起動して送受信テストを行う。

”【エラー内容】”

○smtp-AUTHに失敗した場合のOutlookExpressのエラーは以下のとおり。
エラー番号0x800CCC79が認証失敗のエラーコード。

受信者の 1 人がサーバーによって拒否されたため、メッセージを送信できませんで
した。 拒否された電子メール アドレス : testuser@example.co.jp 件名 ‘tset’, アカ
ウント : ’10.**.**.**’, サーバー : ’10.**.**.**’, プロトコル : SMTP, サーバ
ーの応答 : ‘554 : Relay access denied’, ポート : 25, セキ
ュリティ (SSL): なし, サーバー エラー : 554, エラー番号 : 0x800CCC79

○サーバー側には以下のようなエラーログが出る。

Dec 27 16:20:47 s_sys@example postfix/smtpd[31994]: NOQUEUE: reject: RCPT
from unknown[10.**.**.**]: 554 : Relay access denied;
from= to= proto=SMTP helo=

[/pukiwiki]

-GNU/Linux, infra, MAIL, postfix, サーバー
-,

執筆者:


comment

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA


関連記事

no image

trafshow

[pukiwiki] #topicpath #contents *trafshow [#u9455f3e] トラフィック・モニターtrafshowのインストールと動作具合をテスト。 //ググっても情報 …

no image

net-snmp snmpd.logの設定を追加、変更

[pukiwiki] 某VPSサービスで借りた仮想サーバーでsnmpdを動かしたところ、ログがどこにも出ていなかったのでログ出力設定を追加。 たまたまだと思いつつ、設定状況は環境によって様々だと思うの …

no image

[ssh].shostsによる認証許可メモ

[pukiwiki] .shostsによる認証許可。 設置場所:各ユーザーのホームディレクトリ ユーザーのホームディレクトリに.shostという隠しファイルを作成し 接続を許可する外部ホストのIPない …

nagios​/plugin​/SNMP​/mem監視

  [pukiwiki] *snmpでのメモリ監視(物理メモリ、仮想メモリ) [#h1ad6570] メモリの監視用プラグインは軒並みRAMとSwapのステータスを同時に取得するタイプばかりで RAM …

no image

ZABBIXインストール(1.0)

[pukiwiki]   システム監視ツールzabbixのインストールドキュメント。 【本家サイト】 http://www.zabbix.com/ 日本語の情報はほとんどないので、サイトからダウンロー …

宅麺