完全な仮想メールサーバ/SMTP認証

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page Complete Virtual Mail Server/SMTP Authentication and the translation is 89% complete.
Other languages:

はじめに

これまでのところ、ローカルホストのみがメールの送信を許可されています。 残念ながら、postfixはcourier-authlibと直接連携できません。 ただし、中間解決策としてdev-libs/cyrus-saslがあります。 cyrus-saslが認証情報を取得する方法は3つあります。 データベースから直接、ローカルまたはリモートで。 このアプローチを使用した設定は次のようになります。

  courier-imap -> courier-authlib --\
                                     +--> database 
  postfix ------> cyrus-sasl -------/

少し複雑にするだけで、cyrus-saslを使用してcourier-authlibを介して通信し、courier-authlibに認証を任せることができます。

  courier-imap -----------\
                           +-> courier-authlib -> database
  postfix -> cyrus-sasl --/

理想的には、1つの認証バックエンドcourier-authlibが使用されるため、最後のオプションが使用されるソリューションです。 ただし、courier-authlibと通信するためのcyrus-saslプラグインは、UNIXソケット経由でのみ機能するため、courier-authlibがcyrus-saslと同じホストで実行されていない場合は機能しません。 したがって、最初のアプローチは、courier-authlibを使用できない場合にのみ使用してください。

cyrus-saslのインストール

必要なcyrus-saslの重要な機能は、crypt USEフラグです。 有効にする必要があるか、データベースからの暗号化されたパスワードを認証できません。 正しいUSEフラグが設定されたCyrus-saslは、postfixが出現する間、以前に組み込まれているはずです。

重要
データベースから直接暗号化されたパスワードをサポートするGentooパッチは、>cyrus-sasl-2.1.23では利用できないため、そのようなバージョンを使用する場合は、net-libs/courier-authlibを使用してください。

Cannot load package information. Is the atom dev-libs/cyrus-sasl correct?

メモ
以前にどのデータベースを選択した場合でも、そのサポートはここでも構築されます。 何らかの理由で、ほとんどの場合セキュリティで、追加のデータベースコードが不要な場合、データベースのuseflagsを設定せずに出現する可能性があります。
cyrus-saslは、SQLサポートを使用してコンパイルすると、それを使用するように構成されていない場合、エラーを継続的にログに記録するため、データベースに直接アクセスするのではなく、courier-authlibを経由する場合、データベースのUSEフラグも削除する必要があります。

cyrus-sasl を使用するように postfix を設定する

Postfixがmain.cfでsaslを使用するように指示するには、いくつかのオプションが必要です。 これらはデフォルトの構成ファイルには記載されていないため、追加する必要があります。

ファイル /etc/postfix/main.cfpostfix に sasl サポートを追加する
# Postfix SASL 認証
broken_sasl_auth_clients = no
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain =
smtpd_sasl_authenticated_header = yes
smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination
警告
smtpd_sasl_authenticated_headerは、メールをメールヘッダーに送信するときにcyrusでの認証に使用されるユーザー名を出力します。 公にアーカイブされたメーリングリストに行くメールにとって特に危険で、このヘッダーは世界中で見られます。 ここではテスト目的で有効になっています。

cyrus-sasl を設定する

authdaemond を使用する

Postfixはauthdaemondによって作成されたソケットをクエリします。このソケットはメールユーザーとグループによって保護されているため、Postfixにアクセスを許可する必要があります。

root #gpasswd -a postfix mail

次のcyrus-saslはauthdaemondで認証するように指示される必要があります:

ファイル /etc/sasl2/smtpd.confauthdaemond での認証
pwcheck_method: authdaemond
mech_list: LOGIN PLAIN
sql_select: dummy 
authdaemond_path: /var/lib/courier/authdaemon/socket
 
log_level: 5

postgresql を使用する

ファイル /etc/sasl2/smtpd.conf直接データベース認証
sasl_pwcheck_method: auxprop
sasl_auxprop_plugin: pgsql
password_format: crypt
mech_list: LOGIN PLAIN
 
sql_engine: pgsql
#sql_hostnames: localhost
sql_database: postfix
sql_user: postfix
sql_passwd: $password
sql_select: SELECT password FROM mailbox WHERE local_part='%u' AND active='1'

テスト

saslサポートを確認するには、Telnetを使用してAUTHステートメントを確認します:

user $telnet foo.example.com 25
220 foo.example.com ESMTP Postfix
EHLO example.com
250-foo.example.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
quit
221 2.0.0 Bye
Connection closed by foreign host.
メモ
If a mail-client is being used that does not work properly, broken_sasl_auth_clients = yes can be used in postfix's main.cf to get an additional entry here, 250-AUTH=LOGIN PLAIN.

次のテストは、リモートホストを使用してログインし、テストメッセージを送信することです。

警告
Although it is quite common to authenticate against mail servers (pop/imap/webmail/smtp) through plain text logins it is incredibly insecure (and can be protected against, which is described later in this guide). When sending plain text login data (it is base64 encoded data so very easy to decode) over the big bad Internet, only use a testuser or at least a test password.

If perl with the base64 module is installed, it can be used to generate base64 encoded data. Otherwise base64 conversion can be done online. Again, be very careful when using production data on untrusted sites.

user $perl -MMIME::Base64 -e 'print encode_base64("testuser");'
dGVzdHVzZXI=
user $telnet foo.example.com 25
Trying 1.2.3.4...
Connected to foo.example.com.
Escape character is '^]'.
220 foo.example.com ESMTP Postfix
HELO example.com
250 foo.example.com
AUTH LOGIN
334 VXNlcm5hbWU6 (base64 decode: 'Username:')
dGVzdHVzZXI= (base64 encoded from: 'testuser')
334 UGFzc3dvcmQ6 (base64 decode: 'Password:')
c2VjcmV0 (base64 encoded from: 'secret')
235 2.7.0 Authentication successful
mail from:me@you.com
250 2.1.0 Ok
rcpt to:<validuser>@<validexternaldomain>.<tld>
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
Subject: Test message
Test message to ensure Postfix is only relaying with smtp authorization.
.
250 2.0.0 Ok: queued as 82F97606
quit
221 2.0.0 Bye
Connection closed by foreign host.

まとめ

一度すべてが想定通りに機能したら、デバッグを無効化することができます (下の行を完全に削除しても構いません):

ファイル /etc/sasl2/smtpd.confデバッグを無効化する
log_level: 0

Optionally smtpd_sasl_authenticated_header can be disabled again. It is very handy for tracking down mailing issues from users. It can however be potentially a security issue, as mentioned above, the users login name is written in the header. On the other hand, if the login name is the local_part of the e-mail address or even the e-mail address then the login name is already known anyway so no big harm there, right? Some caution is advised, but it shouldn't be a huge issue.

ファイル /etc/postfix/main.cfpostfix に sasl サポートを追加する
smtpd_sasl_authenticated_header = no