CONTENTS


Lastmodified 2023-10-17 (火) 15:31:56


SMTP認証

【参考URL】FreeBSD 12 で自宅サーバ作成 メールサーバ編
【参考URL】Postfixのセキュリティ対策
【参考URL】FreeBSD、Apacheでサーバを構築して公開する

cyrus-saslのインストール

SMTP認証にsasl認証を使用する。

# portinstall security/cyrus-sasl2
# portinstall security/cyrus-sasl2-saslauthd

cyrus-sasl2 インストール時に、オプションで OTP を外してないと、

postfix/smtpd[27109]: OTP unavailable because can't read/write key database /etc/opiekeys: Permission denied

と言うログが残ります。 Postfix logging some OTP related permission denied messages

cyrus-sasl2-saslauthd.PNG

Updated user `cyrus'.

You can use sasldb2 for authentication, to add users use:

       saslpasswd2 -c username

If you want to enable SMTP AUTH with the system Sendmail, read
Sendmail.README

NOTE: This port has been compiled with a default pwcheck_method of
     auxprop.  If you want to authenticate your user by /etc/passwd,
     PAM or LDAP, install ports/security/cyrus-sasl2-saslauthd and
     set sasl_pwcheck_method to saslauthd after installing the
     Cyrus-IMAPd 2.X port.  You should also check the
     /usr/local/lib/sasl2/*.conf files for the correct
     pwcheck_method.
     If you want to use GSSAPI mechanism, install
     ports/security/cyrus-sasl2-gssapi.
     If you want to use SRP mechanism, install
     ports/security/cyrus-sasl2-srp.
     If you want to use LDAP auxprop plugin, install
     ports/security/cyrus-sasl2-ldapdb.

cyrus-sasl2-saslauthd

====> Compressing man pages (compress-man)
===> Staging rc.d startup script(s)
===>  Installing for cyrus-sasl-saslauthd-2.1.28
===>  Checking if cyrus-sasl-saslauthd is already installed
===>   Registering installation for cyrus-sasl-saslauthd-2.1.28
Installing cyrus-sasl-saslauthd-2.1.28...
To run saslauthd from startup, add saslauthd_enable="YES" in your
/etc/rc.conf.

===> SECURITY REPORT:
      This port has installed the following files which may act as network
      servers and may therefore pose a remote security risk to the system.
/usr/local/sbin/saslauthd  

     If there are vulnerabilities in these programs there may be a security
     risk to the system. FreeBSD makes no guarantee about the security of
     ports included in the Ports Collection. Please type 'make deinstall'
     to deinstall the port if this is a concern.

     For more information, and contact details about the security
     status of this software, see the following webpage:
https://www.cyrusimap.org/sasl/
===>  Cleaning for heimdal-7.8.0_6
===>  Cleaning for cyrus-sasl-2.1.28
===>  Cleaning for cyrus-sasl-saslauthd-2.1.28

/etc/rc.conf

saslauthd_enable="YES"
saslauthd_flags="-a sasldb"

saslauthd起動

/usr/local/etc/rc.d/saslauthd start

SMTP AUTH設定

/usr/local/lib/sasl2/smtpd.conf

pwcheck_method: auxprop

元記事はこうなっているが、現状、/usr/local/lib/sasl2/Sendmail.conf というファイルがあって、中身は

pwcheck_method: auxprop

となってて、同じ内様。両方設置しておくことにした。

SMTP AUTHユーザー追加

# saslpasswd2 -c -u Host_name user_name
Password:
Again (for verification):
sasldblistusers2
user_name@hobbit.ddo.jp: userPassword

この操作で /usr/local/etc/sasldb2.db が生成されるが、Host_name は、# postconf -h myhostname の値を用いると、エラーせず認証されるようである。

/usr/local/etc/sasldb2.db所有権変更

/>chown cyrus:mail /usr/local/etc/sasldb2.db
/>chmod 640 /usr/local/etc/sasldb2.db

Postfix

BDB BLACKLISTD と SASL にチェック追加 ← とすると、****.db などのハッシュファイルが不良ファイルとなるケースがあったので、

Postfix_show_config.PNG

今度は、BLACKLISTD と SASL にチェック追加 でやってみる。

postfix_smtp_auth.PNG
# portupgrade -rf --batch postfix
If you are using SASL, you need to make sure that postfix has access to read
the sasldb file.  This is accomplished by adding postfix to group mail and
making the /usr/local/etc/sasldb* file(s) readable by group mail (this should
be the default for new installs).

===> SECURITY REPORT:
     This port has installed the following binaries which execute with
     increased privileges.
/usr/local/sbin/postlog

     This port has installed the following files which may act as network
     servers and may therefore pose a remote security risk to the system.
/usr/local/lib/postfix/libpostfix-util.so

     If there are vulnerabilities in these programs there may be a security
     risk to the system. FreeBSD makes no guarantee about the security of
     ports included in the Ports Collection. Please type 'make deinstall'
     to deinstall the port if this is a concern.

     For more information, and contact details about the security
     status of this software, see the following webpage:
https://www.postfix.org/

この段階で、postconf -a は

# postconf -a
cyrus
dovecot

となります。

【付記】BDBオプションを追加した場合、Postfixの最初のnewaliasesコマンドでDBの作成時に

# newaliases
BDB0210 /etc/mail/aliases.db: metadata page checksum error
BDB1581 File handles still open at environment close
BDB1582 Open file handle: /etc/mail/aliases.db
BDB1582 Open file handle: /etc/mail/aliases.db
BDB1582 Open file handle: /etc/mail/aliases.db
BDB1582 Open file handle: /etc/mail/aliases.db
         :          :         :
BDB1582 Open file handle: /etc/mail/aliases.db
BDB0210 /usr/local/mailman/data/aliases.db: metadata page checksum error
BDB1581 File handles still open at environment close
BDB1582 Open file handle: /usr/local/mailman/data/aliases.db
BDB1582 Open file handle: /usr/local/mailman/data/aliases.db
BDB1582 Open file handle: /usr/local/mailman/data/aliases.db
           :           :           :
BDB1582 Open file handle: /usr/local/mailman/data/aliases.db
BDB1582 Open file handle: /usr/local/mailman/data/aliases.db
BDB1582 Open file handle: /usr/local/mailman/data/aliases.db
#

のような出力があった。postfix reload して再度 newaliases したら、すぐにプロンプトが戻って来た。 多分、正常な動作だったのだろうけど、ちと焦った。(^_^;

main.cf 設定

myhostname = mail.smb.net   # コメント解除でホスト名指定
mydomain = smb.net          # コメント解除でドメイン名指定
myorigin = $myhostname      # コメント解除(送信元メール)
inet_interfaces = all       # コメント解除(受信するネットワークアドレスを指定)
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain  # コメント解除(ローカル配送先)
mynetworks = 192.168.1.0/24, 127.0.0.0/8 # リレーを許可するIPアドレス
relay_domains = $mydestination  # コメント解除(リレーを許可するドメインを指定)
alias_maps = hash:/etc/aliases  # コメント解除(エイリアスを設定)
alias_database = hash:/etc/aliases # コメント解除(エイリアスを設定)
 
# Cyrus-SASL configuration  # 下記を追加(SASLによるSMTP認証を使用)
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_security_options = noanonymous
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
broken_sasl_auth_clients = yes

起動

# service saslauthd start
Starting saslauthd.

# service postfix start
postfix/postfix-script: starting the Postfix mail system

SMTP-AUTH の確認

【参考URL】Postfix で SMTP-AUTH を実現 SMTP-AUTH が正常に動作しているかを確認します。 具体的には Telnet で 25 番ポートにアクセスして確認します。

$ telnet localhost 25 <-- 入力し、エンター
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 www.miloweb.net ESMTP Postfix
EHLO localhost <-- EHLO localhostと入力
250-zdnet.hoge.org
250-PIPELINING
250-SIZE 10240000
250-ETRN
250-AUTH SCRAM-SHA-512 SCRAM-SHA-384 SCRAM-SHA-256 SCRAM-SHA-224 SCRAM-SHA-1 DIGEST-MD5 CRAM-MD5 NTLM LOGIN PLAIN
250-AUTH=SCRAM-SHA-512 SCRAM-SHA-384 SCRAM-SHA-256 SCRAM-SHA-224 SCRAM-SHA-1 DIGEST-MD5 CRAM-MD5 NTLM LOGIN PLAIN <-- この行があればオッケーです
250 8BITMIME
QUIT <-- 確認できたので、QUITコマンドで切断します

もし「 250-AUTH PLAIN LOGIN 」と表示されていれば、SMTP-AUTH が上手く行っていないので、 Postfix のインストール手順を見直して、やり直さなければならない。

更に確認を進める

http://linux.kororo.jp/cont/server/smtp_auth.php

# printf 'ユーザー名\0ユーザー名\0パスワード' | mmencode

で得られるBase64を用いてAUTH PLAIN (平文認証)認証出来るか確認する。
予め main.cf で

#smtp_sasl_security_options = noplaintext 

とコメントアウトしておく。

$ telnet localhost 25 <-- 入力し、エンター
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 www.miloweb.net ESMTP Postfix
EHLO localhost <-- EHLO localhostと入力
250-zdnet.hoge.org
250-PIPELINING
250-SIZE 10240000
250-ETRN
250-AUTH SCRAM-SHA-512 SCRAM-SHA-384 SCRAM-SHA-256 SCRAM-SHA-224 SCRAM-SHA-1 DIGEST-MD5 CRAM-MD5 NTLM LOGIN PLAIN
250-AUTH=SCRAM-SHA-512 SCRAM-SHA-384 SCRAM-SHA-256 SCRAM-SHA-224 SCRAM-SHA-1 DIGEST-MD5 CRAM-MD5 NTLM LOGIN PLAIN <-- この行があればオッケーです
250 8BITMIME
AUTH PLAIN a29yb3JvAGtvcm9ybwBrb3JvMTgxNQ==   <-- # printf 'ユーザー名\0ユーザー名\0パスワード' | mmencode の結果を入力
235 Authentication successful
QUIT
221 Bye
Connection closed by foreign host.

/var/log/all.log

postfix/smtpd[66015]: E4D824E6061: client=gw.kuji-clinic.net[210.255.122.209], sasl_method=CRAM-MD5, sasl_username=hoge@FQDN

Total access 355:本日 3:昨日 0

Counter: 355, today: 3, yesterday: 0

添付ファイル: filecyrus-sasl2-saslauthd.PNG 57件 [詳細] filepostfix_smtp_auth.PNG 60件 [詳細] filePostfix_show_config.PNG 66件 [詳細]

トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2023-10-17 (火) 15:31:56