「Postfix」+「Cyrus-SASL」の設定

「Postfix」を普通に外部から利用出来るようにしてしまうと不正中継に利用されてしまいます。
そこで、不正中継を行わないように「Cyrus-SASL」を利用してSMTP-AUTHの導入を行います。

「Postfix」の再インストール

「Postfix」のインストール時にSMTP-AUTHに対応させてコンパイルしていない場合は、Postfixの再インストールが必要です。
それにはUSEフラグを編集する必要があります。

Gentoo ~ # vi /etc/make.conf
USE = "sasl" <= 追加

SMTP-AUTH対応でコンパイルされるか確認します。

Gentoo ~ # emerge -pv postfix

These are the packages that I would merge, in order:

Calculating dependencies ...done!
[ebuild   R   ] mail-mta/postfix-2.2.10  -cdb -hardened +ipv6 -ldap -mailwrapp
er -mbox -mysql -nis +pam -postgres +sasl* (-selinux) +ssl -vda 0 kB

Total size of downloads: 0 kB

コンパイルオプションにsaslがあれば問題ありません。

「Postfix」のインストール

Gentoo ~ # emerge postfix

なお、「Cyrus-SASL」も同時にインストールされます。

「Postfix」の設定
Gentoo ~ # vi /etc/postfix/main.cf <= 設定ファイルの編集
SMTP認証の為に以下を追加
smtpd_sasl_auth_enable = yes <= SMTP認証を有効にする
smtpd_sasl_local_domain = $mydomain <= SMTP認証するローカルドメインの指定
smtpd_sasl_security_options = noanonymous, noplaintext
	・noanonymous <= 匿名を許可しない
	・noplaintext <= 暗号化されないパスワードを許可しない
broken_sasl_auth_clients = yes <= AUTHコマンドのサポートを認識できないクライアントへの対応
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
 <= SMTP認証の要求(リレーするものを設定)
	・permit_mynetworks <= mynetworksで指定されたネットワークからのリレーを許可
	・permit_sasl_authenticated <= SMTP認証を通過したものは許可
	・reject_unauth_destination <= 上記以外拒否

「Postfix」を再起動し、設定を反映させます。

Gentoo ~ # /etc/init.d/postfix restart
SMTP認証の為のSASLの設定

SMTP認証にはシステムアカウントを利用する方法と、sasldb2を利用する方法があります。
sasldb2を利用すれば、システムアカウントとは異なるパスワードを設定できますので、 こちらの方がセキュリティは高くなります。

1.システムアカウントを利用した認証(pamを利用)

pamを利用する場合、CRAM-MD5等の暗号化したパスワードが利用できない為、上記の「Postfix」の設定を変更します。

Gentoo ~ # vi /etc/postfix/main.cf <= 設定ファイルの編集
smtpd_sasl_security_options = noanonymous, noplaintext
↓
smtpd_sasl_security_options = noanonymous <= 「noplaintext」の削除

「saslauthd」の設定

認証メカニズムはPLAIN方式とLOGIN方式に限定します。

Gentoo ~ # vi /etc/sasl2/smtpd.conf <= 設定ファイルの編集
pwcheck_method:pam
↓
pwcheck_method:saslauthd <= 変更
mech_list: plain login <= 追加

SASL認証デーモンを起動します。

Gentoo ~ # /etc/init.d/saslauthd start

Gentoo起動時にSASL認証デーモンを起動するようにします。

Gentoo ~ # rc-update add saslauthd default

2.sasldb2による認証

認証方式をCRAM-MD5、DIGEST-MD5方式に限定します。

Gentoo ~ # vi /etc/sasl2/smtpd.conf <= 設定ファイルの編集
pwcheck_method:pam
↓
pwcheck_method:auxprop <= 変更
mech_list: cram-md5 digest-md5 <= 追加

SASLのデータベースにユーザを追加します。

・新規登録
Gentoo ~ # saslpasswd2 -u crimson-snow.net -c kaz <= ユーザ kaz を追加
Password: <= パスワード
Again (for verification): <= パスワード(確認)

・パスワード変更
Gentoo ~ # saslpasswd2 -u crimson-snow.net kaz <= ユーザ kaz のパスワードを変更
Password: <= パスワード
Again (for verification): <= パスワード(確認)

・ユーザ削除
Gentoo ~ # saslpasswd2 -u crimson-snow.net -d kaz <= ユーザ kaz を削除

・ユーザ確認
Gentoo ~ # sasldblistusers2

SALSのデータベースをPostfixから参照できるようにします。

Gentoo ~ # chgrp postfix /etc/sasl2/sasldb2 <= 所属グループをpostfixに変更

Gentoo ~ # chmod 640 /etc/sasl2/sasldb2 <= パーミッションを変更
▲ページのトップへ