Spamassassin デーモン ===================== The purpose of this program is to provide a daemonized version of the spamassassin executable. The goal is improving throughput performance for automated mail checking. This document is a brief synopsis of how spamc/spamd work, and how to use them effectively. このプログラムの目的はデーモン化されたバージョンのspamassassinの提供で す。目標はメールの自動チェックの為、スループットのパフォーマンスの改善 です。このドキュメントはどのようにして spamc/spamd が動いているのか、 そしてこれらをどうやって効果的に使うか、の簡単な要約となっています。 Spamd ----- Spamd is the workhorse of the spamc/spamd pair -- it loads an instance of the spamassassin filters, and then listens as a daemon for incoming requests to process messages. By default, spamd listens on port 783, but this is specifiable on the command line. spamdはspamc/spamdの二頭立ての馬車のうちの1頭です−spamassassinフィル タのインスタンスを起動し、やって来るリクエストをデーモンとして受け取っ てメッセージを処理します。通常、spamdはport783で待ち受けていますが、こ れはコマンドラインから指定可能です。 When spamd receives a connection, it spawns a child to handle the request. spamdは接続要求を受け取った際、処理の為に子プロセスを生成します。 The child will expect to read an email message from the network socket, which should then be closed for writing on the other end (so spamd receives an EOF). 子プロセスはネットワークソケットからメール文を読み取り、ソケットは向こ う側への書き込みのために閉じられます(そしてspamdはEOFを受け取ります)。 spamd will then use SA to rewrite the message, and dump the processed message back to the socket before closing the connection. The child process then dies. 次にspamdはspamassassinを使いメッセージを書き換え、接続を閉じる前にソ ケットに処理したメッセージを吐き戻します。そして子プロセスは死にます。 In theory, this child-forking should be quite efficient, since on most OSes the fork will not actually copy any memory until the child attempts to write to a memory page, and then only the dirty page(s) will be copied. 殆どのOS上ではforkでは子プロセスがメモリページに書き込むまでは実際にメ モリコピーは実行されず、dirty pageだけがコピーされる為、理論上この子プ ロセスの生成(child-forking)は大変効果的です。 This means the entire perl engine and the SA regular expressions, etc. will only be loaded once and then be reused by all the children, saving a lot of overhead. これはperlのエンジン部分とspamassassinの正規表現などは一度だけ実行され、 全ての子プロセスから利用されることになり、オーバーヘッドが大きく削減さ れる事を意味します。 Spamc ----- Spamc is the client half of the pair. It should be used in place of 'spamassassin' in scripts to process mail. It will read the mail from stdin, and spool it to its connection to spamd, then read the result back and print it to stdout. Spamc has extremely low overhead in loading, so it should be much faster to load than the whole spamassassin program (and a perl VM). spamcはペアの片割れのクライアントです。メールを処理するスクリプトの中 で'spamassassin'の所で利用されることになります。標準入力(stdin)からメ ールを読み取り、spamdへの接続へスプールし、そして返された結果を読み取 って標準出力(stdout)へ書き出します。spamcは実行の際のオーバーヘッドが 極端に少ないため、spamassassinプログラム(とperl VM)全体を実行するのと 比較してとても速くなります。 インストール作業 ---------------- Simply copy the two executables to where you want them. Then, configure your system to run spamd in the background, and where your mailer invokes 'spamassassin' instead invoke 'spamc'. It's that easy! 単に二つの実行ファイルを好きなところにコピーしてください。次に、spamd をバックグラウンドで実行するようにシステムを設定し、メーラーが'spamassassin' を起動するところを'spamc'を起動するようにします。簡単です! There's a Red Hat/Mandrake-style startup script called 'spamassassin' in this directory, suitable for installation in /etc/rc.d/init.d . Red Hat/Mandrake形式の'spamassassin'という名前の起動スクリプトがこの ディレクトリにあるので、合っている方を /etc/rc.d/init.d にインストー ルします。 セキュリティ ------------ Since spamd effectively has both read and write access on all of the mail which passes through it , you may want to keep security in mind. Depending on the nature of your set-up. If you are installing it on a site-wide basis at least some caution is advisable. spamdがその中を通過する全てのメールを読み書きする権限をもっているも同 然である為、あなたはセキュリティの維持について考えておきたいと思うかも しれません。これはあなたの設定次第です。システム全体に対してインストー ルを行う場合、少なくとも幾分かは用心するのが賢明です。 システムでのセキュリティ ------------------------ Spamd has the facility to run as a non-root user, this has potential security payoffs. If a fault is found in spamd or spamassassin code, any third party linked-libraries or imported perl modules there is the potential for abuse of both the running uid of spamd, and the uid of the username supplied by spamc (and this could be any user). spamdはroot以外のユーザとして実行する機能を持っていますが、これは潜在 的なセキュリティ問題への保険です。spamdかspamassassinのコードの中やサ ードパーティ製のリンクしたライブラリやインポートされたperlモジュールに 問題が見つかった場合、spamdを実行しているuidやspamcによって提供される ユーザ名のuid(これは任意のユーザ)での潜在的な悪用の可能性があります。 When run as root, spamd will change uid's to the user invoking spamc in order to read and write to their configurations. This functionality is not possible if spamd does not run as root and is a disadvantage if you rely on this. If you use mysql for per-user configuration there is no reason in the world to run as root, and this remains fully functional. rootとして実行した場合、spamdは設定ファイルを読むためにspamcを実行する ユーザのuidに変更します。この機能はspamdをrootとして実行させなければな らず、この機能に頼ることは不便な事になります。mysqlをユーザ毎の設定で 使用している場合、rootで動作させる理由は何処にも無く、しかも全ての機能 は損なわれません。 If you do not need to let your users define their own rules, maintain their own whitelists, or have non-world-readable home and ~/.spamassassin directories, then just set spamd up to run with the "-u username" option. Since spamd can use auto-whitelisting, which requires it maintain a database of email addresses on-disk, you should use a non-"root" but non-"nobody" user: "mailnull" or "mail" are good choices, or even create a "spamd" user. ユーザ各々にルールを設定・whitelistをメンテナンスさせなくても良い場合 や homeディレクトリや ~/.spamassassinディレクトリがworld readableでは ない場合、単にspamdを"-u username"オプションで実行します。spamdがauto-whitelisting を使えるためには、ディスク上にメールアドレスのデータベースを維持する必 要があるので、"root"以外かつ"nobody"以外のユーザを使うべきです:"mailnull" や"mail"は良い選択ですし、"spamd"ユーザを作るのもよいでしょう。 If you plan to use Razor or Pyzor, please note that they both rely on their external configuration files in ~/.razor and ~/.pyzor being readable, and Razor will try to write to a log file in ~/.razor/razor-agent.log that must be writable (Razor will complain about 'unblessed references' in this case). You may find the -H switch to spamd to be useful; it allows you to set a 'helper home directory' that will be used as $HOME when external helpers like Razor, Pyzor and DCC are run. RazorやPyzorの利用を考えている場合、~/.razorや ~/.pyzorにある外部設定 ファイルが読み込み可能なことが必要になり、Razorは ~/.razor/razor-agent.log にログファイルを書き出そうとする為にこのファイルは書き込み可能である 必要があります(この場合、Razorは'unblessed references'とエラーを吐きます)。 spamdを-H スイッチつきで使うのが便利なことに気付くかもしれません:これ によって、RazorやPyzorやDCCのような外部ヘルパープログラムが動いている 場合に'helper home directory'を$HOMEとして設定可能になります。 ベイズ式識別法 -------------- If you plan to use Bayesian classification (the BAYES rules) with spamd, you will need to either spamdでベイズ式分類法(ベイジアンルール)を利用しようとする場合、以下の どちらかが必要になります 1. modify /etc/spamassassin/local.cf to use a shared database of tokens, by setting the 'bayes_path' setting to a path all users can read and write to. You will also need to set the 'bayes_file_mode' setting to 0666 so that created files are shared, too.  1. /etc/spamassassin/local.cfで、'bayes_path'設定を全てのユーザが読   書き可能なパスへ変更することによってトークン共有データベースを利用   するように変更します。また、作成されたファイルも共有されるように   'bayes_file_mode'を0666に設定することが必要になるでしょう。 2. Alternatively, let the users train their individual Bayes database.  2. もう一つの方法は、ユーザに各自のベイズデータベースをトレーニング    させる事です。 We have implemented an auto-learning algorithm (option 'bayes_auto_learn', on by default) which can use high-scoring and low-scoring (options 'bayes_auto_learn_threshold_spam' and 'bayes_auto_learn_threshold_nonspam') mails to improve classification efficiency. 我々は効果的に識別を改善するため、高いスコアと低いスコア('bayes_auto_learn_threshold_spam' ・'bayes_auto_learn_threshold_nonspam'オプション)が付いたメールを自動 学習するアルゴリズム('bayes_auto_learn'オプション、デフォルトで有効) を実装しています。 セキュリティとクライアントのユーザ詐称 -------------------------------------- Since spamd makes no effort to authenticate the username supplied by spamc, it is easily possible for malicious users invoking modified spamc clients to make spamd: spamdはspamcから与えられるユーザ名を認証する際にチェックを行っていない 為、容易に悪意あるユーザが変更を加えたspamcクライアントを起動し、spamd を利用して: (1.) read (and hence determine) the contents of other users configurations (2.) change the contents of other users configurations (whitelisting) (3.) grab CPU time as that user -- this is an issue on ulimit'd systems (1.) 他のユーザの設定の内容を読む(決定する) (2.) 他のユーザの設定(whitelisting)を変更する (3.) CPUをそのユーザとして占有する -- これは ulimit によって制限が されているシステムにおいて問題となります。 以上のようなことが可能です。 If users do not have the opportunity to invoke spamc themselves, and the network is secure, running spamd as root is the preferred option, Be clear that the issues above dont affect you. Note: if you use mysql for per-user configuration on systems, you will remain vulnerable to (1.) and (2.). ユーザがspamcを起動する機会が無く、ネットワークがセキュアである場合、 spamdをrootとして動作させるのは良い選択です。上のような問題で影響を 受けないと確信していただいて結構です。注意:mysqlをシステム上でユー ザごとの設定で利用する場合、(1)と(2)については脆弱なままです。 設定: Mysql .spamassassin/user_prefs / \ / \ / \ / \ ユーザが接続可能?: はい いいえ はい いいえ | | / | | | / | 非安全 | / rootが推奨 | / root以外で実行の為安全 | | いくつか問題あり If you use spamd across a network and spamc connects from other hosts, you should ensure (as with all services) the security of your network segments. Mail is sent as plaintext, and is prone to packet sniffing and spoofing techniques if you are on an insecure network. If you cannot avoid this consider using an encrypted transport layer, such as a VPN, ssh tunnel or similar, or using an SSL-enabled spamc (see 'SSL Support' below). spamdをネットワーク越しに利用して他のホストからspamcが接続する場合、 (他のサービス同様に)ネットワークセグメントのセキュリティを確保しなけ ればなりません。メールは平文で送られ、その為セキュアでないネットワー クにいる場合、パケットを読み取られたり詐称されるなどの恐れがあります。 もしこの様な状況を避けられない場合は暗号化された経路、つまりVPNやssh トンネルやそれに類するもの、またはSSLが有効になったspamcを利用(下記の 'SSL Support'を参照)する事を検討してください。 パフォーマンス -------------- So how much faster is this than just using 'spamassassin'? Well, on my 400MHz K6-2 mail server, spamassassin process a 11689 byte message in about 3.36 seconds, spamc/spamd processes the same message in about 0.86 seconds, or about 4 times faster. With bigger messages, the difference is less pronounced; a 115855 byte message takes about 5 seconds with spamassassin, and 2.5 seconds with spamc/spamd, or about 2 times faster. However, if many messages are being processed in parallel, the spamc/spamd combination will likely be much more efficient, since spamassassin has much higher overhead starting up, and will consume more non-shared memory than will spamc/spamd. For example, on the 115855 byte message, spamc consumes *no* heap memory (and very little on the stack), where spamassassin uses over 15MB of heap space and a peak of 3.5M. In processing the 115855 byte message 10 times in parallel, spamd uses just 22M of heap, with a peak of only 2.5M spamassassin would have used 150M total, and a peak of up to 35M to do this same job. さて、単に'spamassassin'を利用するよりもこれでどの程度速くなるのでしょ うか?私のK6-2 400MHzのメールサーバでは、spamassassinは11689byteのメッ セージを約3.36秒で処理し、spamc/spamdでは同じメッセージを処理するのに 0.86秒、約4倍速くなりました。より大きなメッセージでは、違いは少なくな ります:115855byteのメッセージはspamassassinでは約5秒かかり、spamc/spamd では2.5秒かかりますので、約2倍速くなっています。しかし、大量のメッセー ジを平行で処理する場合、spamassassinは起動により多くのオーバーヘッドが かかり、さらにspamc/spamdよりも多くの非共有メモリを消費するので、spamc/spamd の組み合わせはより効率的でしょう。例えば、115855byteのメッセージでは、 spamassassinは15MB以上のheapメモリとpeak時に3.5MBを使用するところ、spamc はheapメモリを「全く」消費しません(そしてstack上はとても小さなものです)。 115855byteのメッセージを10回並行して処理する場合、spamdは22MBのheapメモ リを使用し、たったの2.5MBをピーク時に消費するのに対し、spamassassinは150M をトータルで利用し、同じ処理をする為にピーク時に35MB以上を消費します。 Regarding how much resources to allocate for spamd, Francesco Potorti reports 'On a Sun Ultra60 with 512MB memory, I found that 20 is a reasonable number (for --max-children), and maybe it could be increased. In fact, the memory footprint of a single Perl interpreter for spamd is about 20MB, but the total memory occupied by several concurrent spamd processes is not much higher. In peak activity periods, with load average around 15, more than 13 spamd processes running or sleeping, and many other amavis and sendmail processes active, the total memory used was around 350MB, plus about 200MB on swap.' どの程度のリソースをspamdに割り当てるかについては、Francesco Potorti さんが以下のような報告を寄せています:"512MBメモリを積んだSun Ultra60 で、(--max-childrenで)20が適切な数だと考えており、もしかしたらさらに 増やせるかもしれません。実際、spamdを動かしている際のperlインタプリタ のメモリ使用量は約20MBですが、同時に動いている複数のspamdプロセスが占 めているメモリ量の総計はそんなに多くありません。ピーク時の活動状態で、 load averageは15付近を示し、13以上のspamdプロセスが走るかsleepして、 他のamavisやsendmailのプロセスが動いており、トータルのメモリ消費量は 350MB付近でswapが約200MB程度です。" バグ ---- There are no known bugs with this setup. Several reasonable sized sites are now running it on their production mail systems. However, you should still test it completely in *your environment* before trusting all your mail to it. If you discover compilation, runtime, or load-performance bugs, please notify the SpamAssassin-Talk mailing list (SpamAssassin-Talk@lists.sourceforge.net) この設定で知られているバグはありません。現在幾つかそれなりの大きさの サイトにて実際のメールシステムで利用されています。しかしながら、メー ル全てを任せる前に貴方はちゃんと「貴方の環境で」試してみるべきです。 コンパイル時や実行時のバグ、または高負荷時のパフォーマンスに関するバグ などを見つけた場合、SpamAssassin-Talkメーリングリスト(SpamAssassin-Talk@lists.sourceforge.net) までお知らせください。 ネットワークプロトコル ---------------------- The protocol for communication between spamc/spamd is somewhat HTTP like. The conversation looks like: spamc/spamd間のやり取り用のプロトコルはややHTTPライクなものとなっています。 以下のようなやり取りです: spamc --> PROCESS SPAMC/1.2 spamc --> Content-length: (オプション) spamc --> User: spamc --> \r\n [blank line] spamc --> --message sent here-- spamd --> SPAMD/1.1 0 EX_OK spamd --> Content-length: spamd --> \r\n [blank line] spamd --> --processed message sent here-- After each side is done writing, it shuts down its side of the connection. それぞれ書き終わったら、コネクションを切断します。 The first line from spamc is the command for spamd to execute (PROCESS a message is the command in protocol<=1.2) followed by the protocol version. spamcからの最初の行はspamdに対して実行コマンド(PROCESSはprotocol1.2以 上でのコマンド)の命令とプロトコルバージョンが続いています。 The first line of the response from spamd is the protocol version (note this is SPAMD here, where it was SPAMC on the other side) followed by a response code from sysexits.h followed by a response message string which describes the error if there was one. If the response code is not 0, then the processed message will not be sent, and the socket will be closed after the first line is sent. spamdからの返答の最初の行はプロトコルのバージョン(ここにSPAMDが、もう 片方にSPAMCがある事に注意)、続いて sysexits.h の返答コード、エラーが あった場合にその旨を記述する返答メッセージ文字です。返答コードが0で無 かった際,処理されたメッセージは送信されず、ソケットは最初の行が送ら れたあとに閉じられます。 Commands The following commands are defined as of protocol 1.2: CHECK -- Just check if the passed message is spam or not and reply as described below SYMBOLS -- Check if message is spam or not, and return score plus list of symbols hit REPORT -- Check if message is spam or not, and return score plus report REPORT_IFSPAM -- Check if message is spam or not, and return score plus report if the message is spam SKIP -- Ignore this message -- client opened connection then changed its mind PROCESS -- Process this message as described above and return modified message コマンド プロトコル1.2では以下のようなコマンドが定義されています: CHECK -- 単にメッセージがspamかどうかを判別して以下のような返答をします SYMBOLS -- メッセージがspamかどうかを判別し、該当したプラススコアのシンボルのリストを返します REPORT -- メッセージがspamかどうかを判別し、プラススコアのレポートを返します REPORT_IFSPAM -- メッセージがspamかどうかを判別し、spamだった場合にプラススコアのレポートを返します SKIP -- メッセージを無視 -- クライアントは接続後状態を変更します PROCESS -- 上記のようにメッセージを処理し、変更したメッセージを返します CHECK command returns just a header (terminated by "\r\n\r\n") with the first line as for PROCESS (ie a response code and message), and then a header called "Spam:" with value of either "True" or "False", then a semi-colon, and then the score for this message, " / " then the threshold. So the entire response looks like either: CHECKコマンドは最初の行でPROCESSのように単にヘッダ("\r\n\r\n"で終了)を 返します(例えばレスポンスコードとメッセージ)、そして"Spam:"というヘッダ と"True"か"False"という値、次にセミコロン、このメッセージのスコア、" / " 、 閾値となります。つまりレスポンスの全容は以下のような形になります: SPAMD/1.1 0 EX_OK Spam: True ; 15 / 5 または SPAMD/1.1 0 EX_OK Spam: False ; 2 / 5 となります。 SYMBOLS command returns the same as CHECK, followed by a line listing all the rule names, separated by commas. Note that some versions of the protocol terminate this line with "\r\n", and some do not, due to an oversight; so clients should be flexible on whether or not a CR-LF pair follows the symbol text, and how many CR-LFs there are. SYMBOLSコマンドはCHECKコマンドと同様に返し、コンマによって区切られた 全てのルール名が並べられた行が続きます。幾つかのプロトコルバージョン によって行が"\r\n"で終わるものと見落としによってそうではないものがあ る事に注意してください;つまりクライアントはCR-LFがシンボル文に続くか どうか、どの程度CR-LFがあるのかについて柔軟に対処するべきです。 REPORT command returns the same as CHECK, followed immediately by the report generated by spamd: REPORTコマンドはCHECKと同様に返し、即座にspamdが生成したレポートが続き ます: SPAMD/1.1 0 EX_OK Spam: False ; 2 / 5 This mail is probably spam. The original message has been attached along with this report, so you can recognize or block similar unwanted mail in future. See http://spamassassin.org/tag/ for more details. [....] このメールは恐らくspamです。オリジナルのメッセージがこのレポートに添付 されるので、今後望まないメールを識別または防ぐことができます。より詳細 は http://spamassassin.org/tag/ を参照してください。 [....] Note that the superfluous-score/threshold-line bug that appeared in SpamAssassin 2.5x is fixed. spamassassin 2.5xにあった superfluous-score/threshold-line バグは修正 されていることに注意してください。 Clients should be flexible on whether or not a CR-LF pair follows the report text, and how many CR-LFs there are. クライアントはレポート文にCR-LFが続くかどうか、どのくらいCR-LFがある のかについて柔軟に対処するべきです。 REPORT_IFSPAM returns the same as REPORT if the message is spam, or nothing at all if the message is non-spam. REPORT_IFSPAMはメッセージがspamである場合REPORTと同様に返し、spamでは ない場合は何もしません。 共有ライブラリ -------------- spamc can now be used as libspamc.so; simply run "make spamd/libspamc.so" at the top level. Thanks to Liam Widdowson for this patch. spamcはlibspamc.soとして利用可能になっています:一番上のディレクトリで "make spamd/libspamc.so"と単に実行してください。 このパッチを提供してくれた Liam Widdowson に感謝します。 SSLのサポート ------------- If you have the OpenSSL headers and libraries installed, you can build an SSL-enabled version of spamc or the spamc shared library by running "make spamd/sslspamc" or "make spamd/libsslspamc.so". Thanks to Nate for this patch. OpenSSLのヘッダやライブラリがインストールされていれば、SSLが有効になっ たバージョンのspamcかspamcの共有ライブラリを "make spamd/sslspamc" か "make spamd/libsslspamc.so" と実行することでビルド可能です。 このパッチを提供してくれた Nate に感謝します。 -- this translation was written by Hideki Yamane