Applied Mathematics 8 (2008)
授業資料/第08回
をテンプレートにして作成
開始行:
#contents
* RFC について [#sd791364]
メールサーバの話を書く前に,ここで RFC(Request For Commen...
RFC とは,IETF (Internet Engineering Task Force)((http:/...
&ref(./warning.png); 現在 使われているネットワークプロト...
ただし,規格そのものがバージョンアップされると新しい RFC ...
以下,メールの規格について記すときに RFC について時おり触...
なお,ネットワーク上では親切にも日本語に翻訳して置いてく...
* メールサーバ [#t403e0b5]
メールサーバと一口に言ってもその仕事は様々だ.
その説明を行う前に,電子メールがどのように配達されていく...
** メールの送信,転送,受信 [#z9b7c89e]
メールの配信過程はおよそ送信,転送,受信という段階に分か...
このうち,送信(これも一種の転送と見なせる)と転送は SMTP (...
ユーザビリティに直結することもあって受信の仕方はいくつも...
これらの役割分担をまとめると,
: MTA = Message Transfer Agent | メールの転送を行うソフト...
: MDA = Message Derivery Agent | 届いたメールをローカルユ...
: MUA = Mail/Message User Agent | メールの読み書き,サー...
というソフトウェア同士が, 典型的な場合は以下のように繋が...
CENTER:&ref(./mail-transfer-simple_s2.png);
CENTER:(電子メールのおおよその配信図)
よって,メールサーバの管理とはおおまかに
- MTA の管理
- POP, IMAP 等 MUA の手前のサーバソフトウェアの管理
の二つに分類できることになる.
* メール送受信のセキュリティ(安全性) [#n7970903]
メールの送信,転送,配信は基本的に「平文」でネットワーク...
そのため,各種パスワードもメール本文も同じネットワークに...
そのもっともよく使われる技術が, 前回紹介した TLS/SSL を使...
また,TLS/SSL を使うことで,改竄検出も可能となる.
// これは,ネットワークの通信経路を暗号化する目的にかなり...
// より詳細を述べると(web サーバのところでも簡単に説明し...
&ref(./warning.png); TLS 1.0 は SSL 3.0 にほぼ等しく,RFC...
//SSL は Netscape Communications の開発したものであったが...
//実質的には SSL ver3.0 と TLS ver 1.0 がほぼ同等であると...
前回も述べたように,* over TLS/SSL にはいろんなものがある.
あまり見掛けないところでは FTP over TLS/SSL RFC4217((http...
** SMTP/POP/IMAP over TLS/SSL [#p98a7c76]
上の図の緑色の経路は基本的にネットワーク上をデータが流れ...
具体的には,MTA として関係する SMTP over TLS (RFC3207)((h...
ちなみに,TLS/SSL の原理だけ考えれば,*** over TLS/SSL を...
* spam 対策 : 加害者になるのを防ぐ : 送信ポートのブロック...
現在,ネットワークのメールにおいて spam (=受取り手の意図...
&ref(./warning.png); ちなみに spam の語源は面白い. 調べて...
これを防ぐ,減少させるための仕組みは様々なものがあるが,...
他にも "Outbound Port25 Blocking" なども同じ目的の技術で...
これらは,自分の管理するメールサーバ(MTA)が spam 送信に使...
** SMTP Auth [#z12aaff4]
RFC2554((http://www.ietf.org/rfc/rfc2554.txt ))に規定され...
つまり,「SMTP 通信したいんですけど」「あんた誰?」「◯◯で...
肝心の認証は,実質的に SASL(Simple Authentication and Sec...
この技術は主に,メール送信(実質的にメール転送に相当する)...
** Message Submission [#cfbc01fe]
RFC2476((http://www.ietf.org/rfc/rfc2476.txt )) に規定さ...
通常はメールの送信と転送の両方が port 25 で受けられるので...
分けただけではセキュリティ上の意味はそんなにないので(^-^)...
例えば,送信受付口 submission port では smtp auth をかけ...
より分かり易く示すと,MTA からみたときに基本的に
- 送信してくる相手は MUA
- 転送してくる相手は MTA
であり,メールに関する仕事の内容によって相手が異なるので...
そこで,仕事の内容に応じて port を分けて,相手毎に対応を...
具体的には,MTA はそれなりのサーバであるのできちんとした...
* spam 対策 : 被害者になるのを防ぐ : 受信時のブロック [#c...
spam の「被害者にならないためには」,基本的に転送/送信さ...
: 接続してきた相手をチェックして,ダメなら接続そのものを...
:: 利点 | そもそもメールを受け取らずに済むので,virus な...
::| メールの内容に依存しないので「内容に依存する検閲では...
:: 欠点 | 相手が実は問題ないときでも誤って排除してしまう...
:|そこで,実際には
-- 正しいSMTP 接続以外は拒絶する
-- 相手が MTA の◯◯の機能を持っている場合に限り接続を許可...
-- (全世界で集められている)ブラックリストに載っている相手...
:|というような手法がとられる.
: とりあえずメールを受け取り,内容をチェックしてダメなら…...
:: 利点 | 例えばユーザ毎になど, 柔軟な設定が可能.
::| 内容に依存する高度なチェックが可能. 具体的には,近年...
:: 欠点 | 内容をチェックするので,サーバで行った場合は「...
::|負荷が高い.
というものに分けられる. いずれもそれなりの欠点を抱えるた...
今回はこれらについて詳しく述べないが,一度勉強しておくと...
&ref(./warning.png); 例えば,(教官の経験では)サーバ側で「...
&ref(./notes.png); 「spam 被害を減らすために」実際にどの...
* MTA : Postfix [#b89422e3]
さて,ではメールサーバソフトウェアの本質である MTA をイン...
上に書いたように MTA の有名どころは sendmail, postfix, qm...
無難なところで Postifx をインストールし,設定を行ってみよ...
&ref(./notes.png); sendmail の設定がどのように難しいのか...
&ref(./notes.png); sendmail, postfix, qmail の各々の特徴...
* Postfix のインストール,設定 [#f334eeb0]
** 上に述べた技術との関係 [#eb98dcc9]
まず,Postfix と上のセキュリティ,spam 対策との関係を述べ...
&ref(./warning.png); そもそも Postfix は上に述べたような...
*** SMTP over TLS/SSL について [#e0d12563]
現時点での FreeBSD で Postfix を ports からインストールし...
*** SMTP Auth について [#x6e3d5f9]
原則として Postfix インストール「前」に認証のために用いら...
しかし,現時点では ports からインストールしようとした時に...
** インストール [#q35c6b16]
*** sendmail が既に動いていないかチェック [#m9bd0225]
まず,多くの OS でデフォルトで動いていることが多い sendma...
具体的には,前回の授業で Web サーバが既に動いているかどう...
&ref(./notes.png); そこで,以下のようにして sendmail が動...
- まず,/etc/rc.conf を読んで sendmail についての記述がな...
sendmail_enable="YES" などとあったら sendmail が起動して...
もし sendmail に関する記述が rc.conf になければ,/etc/def...
&ref(./warning.png); /etc/defaults/rc.conf に sendmail_en...
&ref(./notes.png); /etc/rc.conf に特に sendmail に関する...
> sendmail_enable="NONE"
と書きこんでおこう.
- 次に,
ps -axuww | grep -i sendmail
の出力結果を見て,sendmail が動いていないかチェック(sendm...
- 次に,
lsof -i4 | grep -i mail
として mail とか post とか drop とかいう文字列を含む daem...
//また,/etc/rc.conf を見て,
// sendmail_enable = "NONE"
//という文字列が"無かったら" sendmail が動いている可能性...
- また,
telnet localhost 25
として
> Trying 127.0.0.1...
> Connected to localhost.
> Escape character is '^]'.
> 220 &color(blue){ホスト名}; ESMTP Sendmail 8.14.2/8.14...
というように,SMTP を受け付けているよという返事が来て接続...
&ref(./warning.png); 上で telnet を用いて sendmail に接続...
さて,これまでのチェックでもし sendmail が動いているよう...
/etc/rc.d/sendmail stop
として sendmail を停めよう.
念の為にリブートして,sendmail がもはや最初から動かないよ...
*** インストール作業 [#ec20c985]
まずいつものように ports コレクションを更新しておこう.
portsnap fetch
portsnap update
//次に,これからの作業のログが取れるように portupgrade を...
//というのも,途中で何回か大事なメッセージが出てくるので...
//まず,ログファイルの置き場を用意する.
// cd /var/log; mkdir ports
//次に,portupgrade の設定を書き換えておく. 具体的には,/...
// PORTUPGRADE_ARGS = ENV['PORTUPGRADE'] || \
// '-v -L /var/log/ports/%s::%s.log'
//などと修正しておこう(portupgrade のマニュアル(man portu...
//こうしておけば,これからは portupgrade, portinstall な...
では,ports から postfix をインストールする. インストール...
ただし,ports コレクションをざっとみただけでも ver.1系, v...
さて,
cd /usr/ports
portinstall mail/postfix
でインストールが始まるだろう((ちなみに,この時点でインス...
ports からインストールする際,途中で選択/決定 を迫られる...
たぶん最初に
&ref(postfix-option-1.png);
のような画面が出て,postfix のインストールオプションを聞...
これに対しては,上に述べたように "Cyrus SASLv2", "Enable ...
すると,最初に cyrus-sasl2 のインストール作業が行われ,そ...
そしてしばらくすると,
> Added group "postfix".
> Added group "maildrop".
> Added user "postfix".
> You need user "postfix" added to group "mail".
> Would you like me to add it [y]?
と聞かれるだろう.
これはソフトウェア postfix を動かす特別なユーザ postfix ...
また,
> Would you like to activate Postfix in /etc/mail/mailer...
とも聞かれるだろう.
これは mail 関連のソフトウェア対応表とでもいうべき /etc/m...
&ref(./warning.png); デフォルトが "n" となっているので,...
ちなみに,書き換え前の mailer.conf は
> sendmail /usr/libexec/sendmail/sendmail
> send-mail /usr/libexec/sendmail/sendmail
> mailq /usr/libexec/sendmail/sendmail
> newaliases /usr/libexec/sendmail/sendmail
> hoststat /usr/libexec/sendmail/sendmail
> purgestat /usr/libexec/sendmail/sendmail
となっているが,書き換え後は
> sendmail /usr/local/sbin/sendmail
> send-mail /usr/local/sbin/sendmail
> mailq /usr/local/sbin/sendmail
> newaliases /usr/local/sbin/sendmail
となる.
この /usr/local/sbin/sendmail は名前こそ sendmail だが,...
さて,あとは放っておけばインストール作業そのものは終了する.
** 設定 [#d598ebf4]
*** インストールログのチェック [#b1d4724e]
さて,インストール途中に出てくるメッセージを注意深く見て...
以前の設定通りにしていれば,今回のログファイルは /var/log...
&ref(./warning.png); このファイルがない,名前が違う,とい...
ログファイルからまず見つかるメッセージ等は
> *** Added group `cyrus' (id 60)
> *** Added user `cyrus' (id 60)
という部分で,これにより,cyrus というユーザとグループが...
次にライブラリに関して利用したければ云々…といういつものメ...
> You can use sasldb2 for authentication, to add users u...
> &br;
> saslpasswd2 -c username
> &br;
> If you want to enable SMTP AUTH with the system Sendma...
> Sendmail.README
> &br;
> NOTE: This port has been compiled with a default pwche...
> auxprop. If you want to authenticate your user ...
> PAM or LDAP, install ports/security/cyrus-sasl2-...
> set sasl_pwcheck_method to saslauthd after insta...
> Cyrus-IMAPd 2.X port. You should also check the
> /usr/local/lib/sasl2/*.conf files for the correct
> pwcheck_method.
というメッセージがある.
これは SMTP Auth がどのようにインストールされているかとそ...
よく分からない人も英語は読めるだろうから一応読んでおこう(...
ちなみに,ここで書いてある Sendmail.README というファイル...
だから,通常ならば /usr/ports/security/cyrus-sasl2/files ...
ただし,今回は sendmail ではなくて postfix を使うので,こ...
さて,次に見つかるメッセージは
> Warning: you still need to edit myorigin/mydestina...
> parameter settings in /usr/local/etc/postfix/main....
> &br;
> See also http://www.postfix.org/STANDARD_CONFIGURA...
> for information about dialup sites or about sites ...
> firewalled network.
> &br;
> BTW: Check your /etc/aliases file and be sure to s...
> that send mail for root and postmaster to a real p...
> run /usr/local/bin/newaliases.
である.
これは,postfix インストール後にどのような設定が必要か,...
/usr/local/etc/postfix/main.cf を書き換えろよ, dialup す...
また,次のようなメッセージが含まれている.
> To enable postfix startup script please add postfix_en...
> your rc.conf
> &br;
> If you not need sendmail anymore, please add in your r...
> &br;
> sendmail_enable="NO"
> sendmail_submit_enable="NO"
> sendmail_outbound_enable="NO"
> sendmail_msp_queue_enable="NO"
> &br;
> And you can disable some sendmail specific daily maint...
> /etc/periodic.conf file:
> &br;
> daily_clean_hoststat_enable="NO"
> daily_status_mail_rejects_enable="NO"
> daily_status_include_submit_mailq="NO"
> daily_submit_queuerun="NO"
&ref(./warning.png); これは重要なメッセージである.
まず,起動時に postfix が動くようにするにはどうしたらよい...
すぐ次にこのメッセージが続く.
> If you are using SASL, you need to make sure that post...
> the sasldb file. This is accomplished by adding postf...
> making the /usr/local/etc/sasldb* file(s) readable by ...
> be the default for new installs).
このメッセージからは先のインストール時の質問
> You need user "postfix" added to group "mail".
> Would you like me to add it [y]?
に "y" と答えないといけなかった理由が分かる. 先に言え,と...
それから御丁寧にも
> If you are upgrading from postfix version prior to 2.0...
> files for recommended changes to your configuration.
というメッセージがあり,古い postfix からバージョンアップ...
その後に
> This port has installed the following binaries w...
> increased privileges.
> /usr/local/sbin/postdrop
> /usr/local/sbin/postqueue
> &br;
> This port has installed the following files whic...
> servers and may therefore pose a remote security...
> /usr/local/libexec/postfix/nqmgr
> /usr/local/libexec/postfix/qmgr
> /usr/local/libexec/postfix/showq
> /usr/local/libexec/postfix/master
> /usr/local/libexec/postfix/error
> /usr/local/libexec/postfix/scache
> /usr/local/libexec/postfix/qmqpd
> /usr/local/libexec/postfix/anvil
> /usr/local/libexec/postfix/cleanup
> /usr/local/libexec/postfix/pickup
> /usr/local/libexec/postfix/discard
> /usr/local/libexec/postfix/virtual
> /usr/local/libexec/postfix/oqmgr
> /usr/local/libexec/postfix/verify
> /usr/local/libexec/postfix/spawn
> /usr/local/libexec/postfix/local
> /usr/local/libexec/postfix/flush
> /usr/local/libexec/postfix/tlsmgr
> /usr/local/libexec/postfix/bounce
> /usr/local/libexec/postfix/smtpd
> /usr/local/libexec/postfix/pipe
> /usr/local/libexec/postfix/smtp
> /usr/local/libexec/postfix/proxymap
> /usr/local/libexec/postfix/trivial-rewrite
> /usr/local/libexec/postfix/lmtp
> &br;
> This port has installed the following startup sc...
> these network services to be started at boot time.
> /usr/local/etc/rc.d/postfix
> &br;
> If there are vulnerabilities in these programs t...
> risk to the system. FreeBSD makes no guarantee a...
> ports included in the Ports Collection. Please t...
> to deinstall the port if this is a concern.
> &br;
> For more information, and contact details about ...
> status of this software, see the following webpa...
> http://www.postfix.org/
というメッセージがあり,特権をもつプログラムがインストー...
*** 最低限の設定 [#r6a33d0a]
さて,postfix に関して最低限の設定を行おう.
先のログファイルのメッセージを一通り読んだ今となっては,...
&br;
まずは,デフォルトの sendmail に関する設定を全て無効にし...
&ref(./notes.png); それには,ログファイルの "To enable po...
&ref(./warning.png); ただし,sendmail_enable="NO" から始...
//これを読むと,/etc/rc.conf に記述を 5行加えないといけな...
//また,/etc/periodic.conf にも 4行加えるべきだということ...
//早速この二つの作業を行おう.
&br;
さて,次に,メールサーバとして最低限の設定(SMTP Auth も S...
これは /usr/local/etc/postfix/main.cf を編集するだけでよい.
cd /usr/local/etc/postfix/
// cp main.cf main.cf.ORG
emacs main.cf
などとして編集しよう.
&ref(./warning.png); この main.cf のバックアップも忘れな...
&ref(./notes.png); 以下に修正した箇所のみ抜き出した例を書...
なお,デフォルト値が気になる設定は /usr/local/etc/postfix...
> myhostname = q17.cl.math.sci.osaka-u.ac.jp &color(blu...
> mydomain = cl.math.sci.osaka-u.ac.jp
> alias_maps = hash:/etc/aliases
> alias_database = hash:/etc/aliases
> home_mailbox = Maildir/
&ref(./warning.png); home_mailbox の設定値の最後の /(スラ...
&ref(./warning.png); ただし,変数の依存関係があることがあ...
&br;
次に,これもやはり先のログファイル中のメッセージに従い,"...
&ref(./notes.png); 具体的には,/etc/aliases を編集して,...
> root : (自分のメールアドレス)
を修正し,その後,同じファイルの適当な場所に(uucp: root ...
> cyrus: root
> postfix: root
を付け加えればよい. ただし,これだけでは変更は反映されな...
rehash
newaliases
&ref(./warning.png); 上の rehash は重要だ. なぜなら,newa...
さて,ここで念の為リブートしよう. 設定が正しければこれで ...
*** postfix の起動確認 [#t55ff26c]
&ref(./notes.png); まず,先に sendmail が動いているかどう...
> ps -axuww | grep postfix
として,何か動いているか,
> lsof -i4 -P | grep 25
として,ポート25番で誰かきちんと待ち受けているか,を見よう.
&ref(./warning.png); postfix の場合,25番ポートで待ち受け...
動いていないようならこれまでの作業を再チェックし,動くま...
&br;
&ref(./notes.png); 動いているようならば,先と同様に telne...
> telnet localhost 25
として,
> Trying 127.0.0.1...
> Connected to localhost.
> Escape character is '^]'.
> 220 &color(blue){ホスト名}; ESMTP Postfix
と出るはずなので,ここで
> EHLO localhost
と入力してみよう. すると,
> 250-&color(blue){ホスト名};
> 250-PIPELINING
> 250-SIZE 10240000
> 250-VRFY
> 250-ETRN
> 250-ENHANCEEDSTATUSCODES
> 250-8BITMIME
> 250 DSN
という返事が返ってくるはずだ(このあとは ^], quit で抜けら...
これは postfix が正常にメールのやり取りをしようとしている...
&ref(./notes.png); では次に,自分宛にメールを出してみてチ...
やり方は簡単で,&color(blue){通常のユーザになってから};
mail -s "test" 自分のユーザ名
として,それから何でもいいので入力する(これがメールの本文...
メールの本文をうち終わったら,「ピリオド一つのみからなる...
例えば,ユーザ名が taro の場合は次のような感じだ.
> >mail -s "test" taro
> This is a test mail.
> .
> EOT &color(blue){← 上で . だけの行を入力するとこうい...
こうしてから自分のディレクトリの Maildir/new というディレ...
それが今送ったメールならば,今送ったメールが無事に届いた...
例えば上のケースだと以下のような感じのファイルになってい...
> Return-Path: <taro@&color(blue){ホスト名};>
> X-Original-To: taro
> Delivered-To: taro@&color(blue){ホスト名};
> Received: by &color(blue){ホスト名}; (Postfix, from us...
> id 552561D1B6; Thu, 11 Dec 2008 21:56:22 +0900...
> To: taro@&color(blue){ホスト名};
> Subject: test
> Message-Id: <20081211125622.552561D1B6@&color(blue){ホ...
> Date: Thu, 11 Dec 2008 21:56:22 +0900 (JST)
> From: taro@&color(blue){ホスト名}; (Taro Yamada)
> &br;
> This is a test mail.
これがうまくいっていなければ何かおかしいので,スーパーユ...
&ref(./notes.png); さて次に,「存在しないユーザ宛に」メー...
これは上とほぼ同様の作業で,(念の為に通常ユーザになって)
mail -s "test2" 存在しないユーザ名
として,あとは適当に本文入力後に「ピリオド一つのみからな...
例えば, usotaro というユーザが居ないとして次のような感じ...
> >mail -s "test2" usotaro
> This is a test mail to nonexistent user.
> .
> EOT &color(blue){← 上で . だけの行を入力するとこうい...
さてこれもまた自分のディレクトリの Maildir/new というディ...
具体的には,この場合はメール中に
> This is the mail system at host &color(blue){ホスト名};
> &br;
> I'm sorry to have to inform you that your message coul...
> be delivered to one or more recipients. It's attached ...
> &br;
> For further assistance, please send mail to postmaster.
> &br;
> If you do so, please include this problem report. You ...
> delete your own text from the attached returned message.
> &br;
> The mail system
> &br;
> <usotaro@&color(blue){ホスト名};> (expanded from <usot...
> user: "usotaro"
というように,そんなユーザ居ないよ,というメッセージが書...
&br;
今回の説明は少し長くなったので,このあたりで一旦停めてお...
* レポート [#l51d2454]
メール送受信の際に,「安全性(暗号化)」「SPAM対策」につい...
また,本日行った作業について報告せよ.
もちろん各自の
+ 所属(学部,学科)
+ 学籍番号
+ 学年
+ 氏名
+ 日時
+ 肝心のレポート内容(得た知見,作業について気づいたこと等)
を書くのを忘れないように.
*** about Icons [#v3d7ae04]
Some icons in this page are downloadable at [[ICONFINDER:...
The "note" icon designed by [[Marco Martin:http://www.not...
and the "warning" icon designed by [[Alexandre Moore:http...
終了行:
#contents
* RFC について [#sd791364]
メールサーバの話を書く前に,ここで RFC(Request For Commen...
RFC とは,IETF (Internet Engineering Task Force)((http:/...
&ref(./warning.png); 現在 使われているネットワークプロト...
ただし,規格そのものがバージョンアップされると新しい RFC ...
以下,メールの規格について記すときに RFC について時おり触...
なお,ネットワーク上では親切にも日本語に翻訳して置いてく...
* メールサーバ [#t403e0b5]
メールサーバと一口に言ってもその仕事は様々だ.
その説明を行う前に,電子メールがどのように配達されていく...
** メールの送信,転送,受信 [#z9b7c89e]
メールの配信過程はおよそ送信,転送,受信という段階に分か...
このうち,送信(これも一種の転送と見なせる)と転送は SMTP (...
ユーザビリティに直結することもあって受信の仕方はいくつも...
これらの役割分担をまとめると,
: MTA = Message Transfer Agent | メールの転送を行うソフト...
: MDA = Message Derivery Agent | 届いたメールをローカルユ...
: MUA = Mail/Message User Agent | メールの読み書き,サー...
というソフトウェア同士が, 典型的な場合は以下のように繋が...
CENTER:&ref(./mail-transfer-simple_s2.png);
CENTER:(電子メールのおおよその配信図)
よって,メールサーバの管理とはおおまかに
- MTA の管理
- POP, IMAP 等 MUA の手前のサーバソフトウェアの管理
の二つに分類できることになる.
* メール送受信のセキュリティ(安全性) [#n7970903]
メールの送信,転送,配信は基本的に「平文」でネットワーク...
そのため,各種パスワードもメール本文も同じネットワークに...
そのもっともよく使われる技術が, 前回紹介した TLS/SSL を使...
また,TLS/SSL を使うことで,改竄検出も可能となる.
// これは,ネットワークの通信経路を暗号化する目的にかなり...
// より詳細を述べると(web サーバのところでも簡単に説明し...
&ref(./warning.png); TLS 1.0 は SSL 3.0 にほぼ等しく,RFC...
//SSL は Netscape Communications の開発したものであったが...
//実質的には SSL ver3.0 と TLS ver 1.0 がほぼ同等であると...
前回も述べたように,* over TLS/SSL にはいろんなものがある.
あまり見掛けないところでは FTP over TLS/SSL RFC4217((http...
** SMTP/POP/IMAP over TLS/SSL [#p98a7c76]
上の図の緑色の経路は基本的にネットワーク上をデータが流れ...
具体的には,MTA として関係する SMTP over TLS (RFC3207)((h...
ちなみに,TLS/SSL の原理だけ考えれば,*** over TLS/SSL を...
* spam 対策 : 加害者になるのを防ぐ : 送信ポートのブロック...
現在,ネットワークのメールにおいて spam (=受取り手の意図...
&ref(./warning.png); ちなみに spam の語源は面白い. 調べて...
これを防ぐ,減少させるための仕組みは様々なものがあるが,...
他にも "Outbound Port25 Blocking" なども同じ目的の技術で...
これらは,自分の管理するメールサーバ(MTA)が spam 送信に使...
** SMTP Auth [#z12aaff4]
RFC2554((http://www.ietf.org/rfc/rfc2554.txt ))に規定され...
つまり,「SMTP 通信したいんですけど」「あんた誰?」「◯◯で...
肝心の認証は,実質的に SASL(Simple Authentication and Sec...
この技術は主に,メール送信(実質的にメール転送に相当する)...
** Message Submission [#cfbc01fe]
RFC2476((http://www.ietf.org/rfc/rfc2476.txt )) に規定さ...
通常はメールの送信と転送の両方が port 25 で受けられるので...
分けただけではセキュリティ上の意味はそんなにないので(^-^)...
例えば,送信受付口 submission port では smtp auth をかけ...
より分かり易く示すと,MTA からみたときに基本的に
- 送信してくる相手は MUA
- 転送してくる相手は MTA
であり,メールに関する仕事の内容によって相手が異なるので...
そこで,仕事の内容に応じて port を分けて,相手毎に対応を...
具体的には,MTA はそれなりのサーバであるのできちんとした...
* spam 対策 : 被害者になるのを防ぐ : 受信時のブロック [#c...
spam の「被害者にならないためには」,基本的に転送/送信さ...
: 接続してきた相手をチェックして,ダメなら接続そのものを...
:: 利点 | そもそもメールを受け取らずに済むので,virus な...
::| メールの内容に依存しないので「内容に依存する検閲では...
:: 欠点 | 相手が実は問題ないときでも誤って排除してしまう...
:|そこで,実際には
-- 正しいSMTP 接続以外は拒絶する
-- 相手が MTA の◯◯の機能を持っている場合に限り接続を許可...
-- (全世界で集められている)ブラックリストに載っている相手...
:|というような手法がとられる.
: とりあえずメールを受け取り,内容をチェックしてダメなら…...
:: 利点 | 例えばユーザ毎になど, 柔軟な設定が可能.
::| 内容に依存する高度なチェックが可能. 具体的には,近年...
:: 欠点 | 内容をチェックするので,サーバで行った場合は「...
::|負荷が高い.
というものに分けられる. いずれもそれなりの欠点を抱えるた...
今回はこれらについて詳しく述べないが,一度勉強しておくと...
&ref(./warning.png); 例えば,(教官の経験では)サーバ側で「...
&ref(./notes.png); 「spam 被害を減らすために」実際にどの...
* MTA : Postfix [#b89422e3]
さて,ではメールサーバソフトウェアの本質である MTA をイン...
上に書いたように MTA の有名どころは sendmail, postfix, qm...
無難なところで Postifx をインストールし,設定を行ってみよ...
&ref(./notes.png); sendmail の設定がどのように難しいのか...
&ref(./notes.png); sendmail, postfix, qmail の各々の特徴...
* Postfix のインストール,設定 [#f334eeb0]
** 上に述べた技術との関係 [#eb98dcc9]
まず,Postfix と上のセキュリティ,spam 対策との関係を述べ...
&ref(./warning.png); そもそも Postfix は上に述べたような...
*** SMTP over TLS/SSL について [#e0d12563]
現時点での FreeBSD で Postfix を ports からインストールし...
*** SMTP Auth について [#x6e3d5f9]
原則として Postfix インストール「前」に認証のために用いら...
しかし,現時点では ports からインストールしようとした時に...
** インストール [#q35c6b16]
*** sendmail が既に動いていないかチェック [#m9bd0225]
まず,多くの OS でデフォルトで動いていることが多い sendma...
具体的には,前回の授業で Web サーバが既に動いているかどう...
&ref(./notes.png); そこで,以下のようにして sendmail が動...
- まず,/etc/rc.conf を読んで sendmail についての記述がな...
sendmail_enable="YES" などとあったら sendmail が起動して...
もし sendmail に関する記述が rc.conf になければ,/etc/def...
&ref(./warning.png); /etc/defaults/rc.conf に sendmail_en...
&ref(./notes.png); /etc/rc.conf に特に sendmail に関する...
> sendmail_enable="NONE"
と書きこんでおこう.
- 次に,
ps -axuww | grep -i sendmail
の出力結果を見て,sendmail が動いていないかチェック(sendm...
- 次に,
lsof -i4 | grep -i mail
として mail とか post とか drop とかいう文字列を含む daem...
//また,/etc/rc.conf を見て,
// sendmail_enable = "NONE"
//という文字列が"無かったら" sendmail が動いている可能性...
- また,
telnet localhost 25
として
> Trying 127.0.0.1...
> Connected to localhost.
> Escape character is '^]'.
> 220 &color(blue){ホスト名}; ESMTP Sendmail 8.14.2/8.14...
というように,SMTP を受け付けているよという返事が来て接続...
&ref(./warning.png); 上で telnet を用いて sendmail に接続...
さて,これまでのチェックでもし sendmail が動いているよう...
/etc/rc.d/sendmail stop
として sendmail を停めよう.
念の為にリブートして,sendmail がもはや最初から動かないよ...
*** インストール作業 [#ec20c985]
まずいつものように ports コレクションを更新しておこう.
portsnap fetch
portsnap update
//次に,これからの作業のログが取れるように portupgrade を...
//というのも,途中で何回か大事なメッセージが出てくるので...
//まず,ログファイルの置き場を用意する.
// cd /var/log; mkdir ports
//次に,portupgrade の設定を書き換えておく. 具体的には,/...
// PORTUPGRADE_ARGS = ENV['PORTUPGRADE'] || \
// '-v -L /var/log/ports/%s::%s.log'
//などと修正しておこう(portupgrade のマニュアル(man portu...
//こうしておけば,これからは portupgrade, portinstall な...
では,ports から postfix をインストールする. インストール...
ただし,ports コレクションをざっとみただけでも ver.1系, v...
さて,
cd /usr/ports
portinstall mail/postfix
でインストールが始まるだろう((ちなみに,この時点でインス...
ports からインストールする際,途中で選択/決定 を迫られる...
たぶん最初に
&ref(postfix-option-1.png);
のような画面が出て,postfix のインストールオプションを聞...
これに対しては,上に述べたように "Cyrus SASLv2", "Enable ...
すると,最初に cyrus-sasl2 のインストール作業が行われ,そ...
そしてしばらくすると,
> Added group "postfix".
> Added group "maildrop".
> Added user "postfix".
> You need user "postfix" added to group "mail".
> Would you like me to add it [y]?
と聞かれるだろう.
これはソフトウェア postfix を動かす特別なユーザ postfix ...
また,
> Would you like to activate Postfix in /etc/mail/mailer...
とも聞かれるだろう.
これは mail 関連のソフトウェア対応表とでもいうべき /etc/m...
&ref(./warning.png); デフォルトが "n" となっているので,...
ちなみに,書き換え前の mailer.conf は
> sendmail /usr/libexec/sendmail/sendmail
> send-mail /usr/libexec/sendmail/sendmail
> mailq /usr/libexec/sendmail/sendmail
> newaliases /usr/libexec/sendmail/sendmail
> hoststat /usr/libexec/sendmail/sendmail
> purgestat /usr/libexec/sendmail/sendmail
となっているが,書き換え後は
> sendmail /usr/local/sbin/sendmail
> send-mail /usr/local/sbin/sendmail
> mailq /usr/local/sbin/sendmail
> newaliases /usr/local/sbin/sendmail
となる.
この /usr/local/sbin/sendmail は名前こそ sendmail だが,...
さて,あとは放っておけばインストール作業そのものは終了する.
** 設定 [#d598ebf4]
*** インストールログのチェック [#b1d4724e]
さて,インストール途中に出てくるメッセージを注意深く見て...
以前の設定通りにしていれば,今回のログファイルは /var/log...
&ref(./warning.png); このファイルがない,名前が違う,とい...
ログファイルからまず見つかるメッセージ等は
> *** Added group `cyrus' (id 60)
> *** Added user `cyrus' (id 60)
という部分で,これにより,cyrus というユーザとグループが...
次にライブラリに関して利用したければ云々…といういつものメ...
> You can use sasldb2 for authentication, to add users u...
> &br;
> saslpasswd2 -c username
> &br;
> If you want to enable SMTP AUTH with the system Sendma...
> Sendmail.README
> &br;
> NOTE: This port has been compiled with a default pwche...
> auxprop. If you want to authenticate your user ...
> PAM or LDAP, install ports/security/cyrus-sasl2-...
> set sasl_pwcheck_method to saslauthd after insta...
> Cyrus-IMAPd 2.X port. You should also check the
> /usr/local/lib/sasl2/*.conf files for the correct
> pwcheck_method.
というメッセージがある.
これは SMTP Auth がどのようにインストールされているかとそ...
よく分からない人も英語は読めるだろうから一応読んでおこう(...
ちなみに,ここで書いてある Sendmail.README というファイル...
だから,通常ならば /usr/ports/security/cyrus-sasl2/files ...
ただし,今回は sendmail ではなくて postfix を使うので,こ...
さて,次に見つかるメッセージは
> Warning: you still need to edit myorigin/mydestina...
> parameter settings in /usr/local/etc/postfix/main....
> &br;
> See also http://www.postfix.org/STANDARD_CONFIGURA...
> for information about dialup sites or about sites ...
> firewalled network.
> &br;
> BTW: Check your /etc/aliases file and be sure to s...
> that send mail for root and postmaster to a real p...
> run /usr/local/bin/newaliases.
である.
これは,postfix インストール後にどのような設定が必要か,...
/usr/local/etc/postfix/main.cf を書き換えろよ, dialup す...
また,次のようなメッセージが含まれている.
> To enable postfix startup script please add postfix_en...
> your rc.conf
> &br;
> If you not need sendmail anymore, please add in your r...
> &br;
> sendmail_enable="NO"
> sendmail_submit_enable="NO"
> sendmail_outbound_enable="NO"
> sendmail_msp_queue_enable="NO"
> &br;
> And you can disable some sendmail specific daily maint...
> /etc/periodic.conf file:
> &br;
> daily_clean_hoststat_enable="NO"
> daily_status_mail_rejects_enable="NO"
> daily_status_include_submit_mailq="NO"
> daily_submit_queuerun="NO"
&ref(./warning.png); これは重要なメッセージである.
まず,起動時に postfix が動くようにするにはどうしたらよい...
すぐ次にこのメッセージが続く.
> If you are using SASL, you need to make sure that post...
> the sasldb file. This is accomplished by adding postf...
> making the /usr/local/etc/sasldb* file(s) readable by ...
> be the default for new installs).
このメッセージからは先のインストール時の質問
> You need user "postfix" added to group "mail".
> Would you like me to add it [y]?
に "y" と答えないといけなかった理由が分かる. 先に言え,と...
それから御丁寧にも
> If you are upgrading from postfix version prior to 2.0...
> files for recommended changes to your configuration.
というメッセージがあり,古い postfix からバージョンアップ...
その後に
> This port has installed the following binaries w...
> increased privileges.
> /usr/local/sbin/postdrop
> /usr/local/sbin/postqueue
> &br;
> This port has installed the following files whic...
> servers and may therefore pose a remote security...
> /usr/local/libexec/postfix/nqmgr
> /usr/local/libexec/postfix/qmgr
> /usr/local/libexec/postfix/showq
> /usr/local/libexec/postfix/master
> /usr/local/libexec/postfix/error
> /usr/local/libexec/postfix/scache
> /usr/local/libexec/postfix/qmqpd
> /usr/local/libexec/postfix/anvil
> /usr/local/libexec/postfix/cleanup
> /usr/local/libexec/postfix/pickup
> /usr/local/libexec/postfix/discard
> /usr/local/libexec/postfix/virtual
> /usr/local/libexec/postfix/oqmgr
> /usr/local/libexec/postfix/verify
> /usr/local/libexec/postfix/spawn
> /usr/local/libexec/postfix/local
> /usr/local/libexec/postfix/flush
> /usr/local/libexec/postfix/tlsmgr
> /usr/local/libexec/postfix/bounce
> /usr/local/libexec/postfix/smtpd
> /usr/local/libexec/postfix/pipe
> /usr/local/libexec/postfix/smtp
> /usr/local/libexec/postfix/proxymap
> /usr/local/libexec/postfix/trivial-rewrite
> /usr/local/libexec/postfix/lmtp
> &br;
> This port has installed the following startup sc...
> these network services to be started at boot time.
> /usr/local/etc/rc.d/postfix
> &br;
> If there are vulnerabilities in these programs t...
> risk to the system. FreeBSD makes no guarantee a...
> ports included in the Ports Collection. Please t...
> to deinstall the port if this is a concern.
> &br;
> For more information, and contact details about ...
> status of this software, see the following webpa...
> http://www.postfix.org/
というメッセージがあり,特権をもつプログラムがインストー...
*** 最低限の設定 [#r6a33d0a]
さて,postfix に関して最低限の設定を行おう.
先のログファイルのメッセージを一通り読んだ今となっては,...
&br;
まずは,デフォルトの sendmail に関する設定を全て無効にし...
&ref(./notes.png); それには,ログファイルの "To enable po...
&ref(./warning.png); ただし,sendmail_enable="NO" から始...
//これを読むと,/etc/rc.conf に記述を 5行加えないといけな...
//また,/etc/periodic.conf にも 4行加えるべきだということ...
//早速この二つの作業を行おう.
&br;
さて,次に,メールサーバとして最低限の設定(SMTP Auth も S...
これは /usr/local/etc/postfix/main.cf を編集するだけでよい.
cd /usr/local/etc/postfix/
// cp main.cf main.cf.ORG
emacs main.cf
などとして編集しよう.
&ref(./warning.png); この main.cf のバックアップも忘れな...
&ref(./notes.png); 以下に修正した箇所のみ抜き出した例を書...
なお,デフォルト値が気になる設定は /usr/local/etc/postfix...
> myhostname = q17.cl.math.sci.osaka-u.ac.jp &color(blu...
> mydomain = cl.math.sci.osaka-u.ac.jp
> alias_maps = hash:/etc/aliases
> alias_database = hash:/etc/aliases
> home_mailbox = Maildir/
&ref(./warning.png); home_mailbox の設定値の最後の /(スラ...
&ref(./warning.png); ただし,変数の依存関係があることがあ...
&br;
次に,これもやはり先のログファイル中のメッセージに従い,"...
&ref(./notes.png); 具体的には,/etc/aliases を編集して,...
> root : (自分のメールアドレス)
を修正し,その後,同じファイルの適当な場所に(uucp: root ...
> cyrus: root
> postfix: root
を付け加えればよい. ただし,これだけでは変更は反映されな...
rehash
newaliases
&ref(./warning.png); 上の rehash は重要だ. なぜなら,newa...
さて,ここで念の為リブートしよう. 設定が正しければこれで ...
*** postfix の起動確認 [#t55ff26c]
&ref(./notes.png); まず,先に sendmail が動いているかどう...
> ps -axuww | grep postfix
として,何か動いているか,
> lsof -i4 -P | grep 25
として,ポート25番で誰かきちんと待ち受けているか,を見よう.
&ref(./warning.png); postfix の場合,25番ポートで待ち受け...
動いていないようならこれまでの作業を再チェックし,動くま...
&br;
&ref(./notes.png); 動いているようならば,先と同様に telne...
> telnet localhost 25
として,
> Trying 127.0.0.1...
> Connected to localhost.
> Escape character is '^]'.
> 220 &color(blue){ホスト名}; ESMTP Postfix
と出るはずなので,ここで
> EHLO localhost
と入力してみよう. すると,
> 250-&color(blue){ホスト名};
> 250-PIPELINING
> 250-SIZE 10240000
> 250-VRFY
> 250-ETRN
> 250-ENHANCEEDSTATUSCODES
> 250-8BITMIME
> 250 DSN
という返事が返ってくるはずだ(このあとは ^], quit で抜けら...
これは postfix が正常にメールのやり取りをしようとしている...
&ref(./notes.png); では次に,自分宛にメールを出してみてチ...
やり方は簡単で,&color(blue){通常のユーザになってから};
mail -s "test" 自分のユーザ名
として,それから何でもいいので入力する(これがメールの本文...
メールの本文をうち終わったら,「ピリオド一つのみからなる...
例えば,ユーザ名が taro の場合は次のような感じだ.
> >mail -s "test" taro
> This is a test mail.
> .
> EOT &color(blue){← 上で . だけの行を入力するとこうい...
こうしてから自分のディレクトリの Maildir/new というディレ...
それが今送ったメールならば,今送ったメールが無事に届いた...
例えば上のケースだと以下のような感じのファイルになってい...
> Return-Path: <taro@&color(blue){ホスト名};>
> X-Original-To: taro
> Delivered-To: taro@&color(blue){ホスト名};
> Received: by &color(blue){ホスト名}; (Postfix, from us...
> id 552561D1B6; Thu, 11 Dec 2008 21:56:22 +0900...
> To: taro@&color(blue){ホスト名};
> Subject: test
> Message-Id: <20081211125622.552561D1B6@&color(blue){ホ...
> Date: Thu, 11 Dec 2008 21:56:22 +0900 (JST)
> From: taro@&color(blue){ホスト名}; (Taro Yamada)
> &br;
> This is a test mail.
これがうまくいっていなければ何かおかしいので,スーパーユ...
&ref(./notes.png); さて次に,「存在しないユーザ宛に」メー...
これは上とほぼ同様の作業で,(念の為に通常ユーザになって)
mail -s "test2" 存在しないユーザ名
として,あとは適当に本文入力後に「ピリオド一つのみからな...
例えば, usotaro というユーザが居ないとして次のような感じ...
> >mail -s "test2" usotaro
> This is a test mail to nonexistent user.
> .
> EOT &color(blue){← 上で . だけの行を入力するとこうい...
さてこれもまた自分のディレクトリの Maildir/new というディ...
具体的には,この場合はメール中に
> This is the mail system at host &color(blue){ホスト名};
> &br;
> I'm sorry to have to inform you that your message coul...
> be delivered to one or more recipients. It's attached ...
> &br;
> For further assistance, please send mail to postmaster.
> &br;
> If you do so, please include this problem report. You ...
> delete your own text from the attached returned message.
> &br;
> The mail system
> &br;
> <usotaro@&color(blue){ホスト名};> (expanded from <usot...
> user: "usotaro"
というように,そんなユーザ居ないよ,というメッセージが書...
&br;
今回の説明は少し長くなったので,このあたりで一旦停めてお...
* レポート [#l51d2454]
メール送受信の際に,「安全性(暗号化)」「SPAM対策」につい...
また,本日行った作業について報告せよ.
もちろん各自の
+ 所属(学部,学科)
+ 学籍番号
+ 学年
+ 氏名
+ 日時
+ 肝心のレポート内容(得た知見,作業について気づいたこと等)
を書くのを忘れないように.
*** about Icons [#v3d7ae04]
Some icons in this page are downloadable at [[ICONFINDER:...
The "note" icon designed by [[Marco Martin:http://www.not...
and the "warning" icon designed by [[Alexandre Moore:http...
ページ名: