完全な仮想メールサーバー/ 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 55% 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を使用してください。

USE flags for dev-libs/cyrus-sasl The Cyrus SASL (Simple Authentication and Security Layer)

authdaemond Add Courier-IMAP authdaemond unix socket support (net-mail/courier-imap, mail-mta/courier)
berkdb Add support for sys-libs/db (Berkeley DB for MySQL)
gdbm Add support for sys-libs/gdbm (GNU database libraries)
kerberos Add kerberos support
ldapdb Enable ldapdb plugin
mysql Add mySQL Database support
openldap Add ldap support for saslauthd
pam Add support for PAM (Pluggable Authentication Modules) - DANGEROUS to arbitrarily flip
postgres Add support for the postgresql database
sample Enable sample client and server
selinux !!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur
sqlite Add support for sqlite - embedded sql database
srp Enable SRP authentication
ssl Add support for SSL/TLS connections (Secure Socket Layer / Transport Layer Security)
static-libs Build static versions of dynamic libraries as well
urandom Use /dev/urandom instead of /dev/random

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

Configuring postfix with cyrus-sasl

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

ファイル /etc/postfix/main.cfAdd sasl support to postfix.
# Postfix to SASL authentication
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での認証に使用されるユーザー名を出力します。 公にアーカイブされたメーリングリストに行くメールにとって特に危険で、このヘッダーは世界中で見られます。 ここではテスト目的で有効になっています。

Configuring cyrus-sasl

With authdaemond

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

root #gpasswd -a postfix mail

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

ファイル /etc/sasl2/smtpd.confAuthenticate with authdaemond
pwcheck_method: authdaemond
mech_list: LOGIN PLAIN
sql_select: dummy 
authdaemond_path: /var/lib/courier/authdaemon/socket
 
log_level: 5

With postgresql

ファイル /etc/sasl2/smtpd.confDirect database authentication
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.

Wrapping it up

Once everything is working as expected, debugging can be disabled (or the line can be removed entirely):

ファイル /etc/sasl2/smtpd.confDisable debugging
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.cfAdd sasl support to postfix
smtpd_sasl_authenticated_header = no