メールフィルタ(Rspamd)
なにか入れておかないと迷惑メールまみれになりそうなので、https://server-recipe.com/1533/ を参考に、Rspamd を動かしてみます。web からの設定もできるようです。以前は、ベイジアンフィルタを元にした bsfilter を使っていました。
インストール
$ sudo apt-get install -y redis rspamd
設定
設定用のコマンドで初期設定をします。
$ sudo rspamadm configwizard
connect [fe80::8dc5:4d7b:9d41:3cef]:53 failed: 22, '無効な引数です'
cannot open connection to nameserver at address fe80::8dc5:4d7b:9d41:3cef: 無効な引数です
____ _
| _ \ ___ _ __ __ _ _ __ ___ __| |
| |_) |/ __|| '_ \ / _` || '_ ` _ \ / _` |
| _ < \__ \| |_) || (_| || | | | | || (_| |
|_| \_\|___/| .__/ \__,_||_| |_| |_| \__,_|
|_|
Welcome to the configuration tool
We use /etc/rspamd/rspamd.conf configuration file, writing results to /etc/rspamd
Modules enabled: fuzzy_check, hfilter, phishing, dkim_signing, asn, settings, chartable, arc, trie, bayes_expiry, elastic, rspamd_update, ip_score, metadata_exporter, rbl, regexp, mid, multimap, dkim, surbl, mime_types, maillist, emails, once_received, dmarc, forged_recipients, milter_headers, whitelist, force_actions, spf
Modules disabled (explicitly): url_tags, url_reputation, spamtrap, dcc, mx_check, neural
Modules disabled (unconfigured): spamassassin, reputation, metric_exporter, dynamic_conf, clustering, antivirus, fuzzy_collect, maps_stats, clickhouse
Modules disabled (no Redis): greylist, url_redirector, ratelimit, replies, history_redis
Modules disabled (experimental):
Modules disabled (failed):
Do you wish to continue?[Y/n]:
Setup WebUI and controller worker:
Controller password is not set, do you want to set one?[Y/n]: n
Redis servers are not set:
The following modules will be enabled if you add Redis servers:
* greylist
* url_redirector
* ratelimit
* replies
* history_redis
Do you wish to set Redis servers?[Y/n]:
Input read only servers separated by `,` [default: localhost]:
Input write only servers separated by `,` [default: localhost]:
Do you have any password set for your Redis?[y/N]:
Do you have any specific database for your Redis?[y/N]:
Do you want to setup dkim signing feature?[y/N]:
You have 1 sqlite classifiers
Expire time for new tokens [100d]:
Reset previous data?[y/N]:
Do you wish to convert them to Redis?[Y/n]:
Convert spam tokens
Convert ham tokens
Migrated 0 tokens for 2 users for symbols (BAYES_SPAM, BAYES_HAM)
Converted classifier to the from sqlite to redis
File: /etc/rspamd/local.d/classifier-bayes.conf, changes list:
backend => redis
new_schema => true
expire => 8640000
File: /etc/rspamd/local.d/redis.conf, changes list:
write_servers => localhost
read_servers => localhost
Apply changes?[Y/n]:
Create file /etc/rspamd/local.d/classifier-bayes.conf
Create file /etc/rspamd/local.d/redis.conf
2 changes applied, the wizard is finished now
*** Please reload the Rspamd configuration ***
パスワードは後で設定するので、「Controller password is not set, do you want to set one?」には N を答えて、後はデフォルトでいいです。
パスワードの設定
web からの閲覧用と管理用のパスワードを設定します。rspamadm を 2 回実行して、パスワードに対するハッシュを計算します。このハッシュを利用します。
$ rspamadm pw
このハッシュを /etc/rspamd/local.d/worker-controller.inc に書きます。
$ sudo vi /etc/rspamd/local.d/worker-controller.inc
password = “閲覧用ハッシュ";
enable_password = “管理用ハッシュ";
その他
$ sudo vi /etc/rspamd/local.d/redis.conf
write_servers = “127.0.0.1:6379";
read_servers = “127.0.0.1:6379";
到着したメールのヘッダに「X-Spam-Level」などの情報を追加するための設定をします。
$ sudo vi /etc/rspamd/local.d/milter_headers.conf
use = ["spam-header", "x-spam-level", "x-spam-status", "x-virus", "authentication-results"];
skip_local = false;
skip_authenticated = true;
extended_spam_headers = true;
routines {
spam-header {
header = "X-Spam-Flag";
remove = 1;
value = "YES";
}
x-spam-level {
header = "X-Spam-Level";
remove = 1;
char = "*";
}
x-spam-status {
header = "X-Spam-Status";
remove = 1;
}
x-virus {
header = "X-Virus-Check";
remove = 1;
symbols = ["CLAM_VIRUS"];
}
authentication-results {
header = "Authentication-Results";
remove = 1;
add_smtp_user = false;
spf_symbols {
pass = "R_SPF_ALLOW";
fail = "R_SPF_FAIL";
softfail = "R_SPF_SOFTFAIL";
neutral = "R_SPF_NEUTRAL";
temperror = "R_SPF_DNSFAIL";
none = "R_SPF_NA";
permerror = "R_SPF_PERMFAIL";
}
dkim_symbols {
pass = "R_DKIM_ALLOW";
fail = "R_DKIM_REJECT";
temperror = "R_DKIM_TEMPFAIL";
none = "R_DKIM_NA";
permerror = "R_DKIM_PERMFAIL";
}
dmarc_symbols {
pass = "DMARC_POLICY_ALLOW";
permerror = "DMARC_BAD_POLICY";
temperror = "DMARC_DNSFAIL";
none = "DMARC_NA";
reject = "DMARC_POLICY_REJECT";
softfail = "DMARC_POLICY_SOFTFAIL";
quarantine = "DMARC_POLICY_QUARANTINE";
}
}
}
web で管理
web から閲覧/管理できるように設定します。Apache の mod_proxy, mod_proxy_http を有効にして、mod_rewrite で書き換えます。外部からもアクセスできてしまうので対策が必要です。
$ sudo a2enmod proxy
$ sudo a2enmod proxy_http
$ vi /etc/apache2/sites-available/サイト設定
以下を追加します。
<Location /rspamd>
Require ip 192.168.0
Order allow,deny
Allow from all
</Location>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^/rspamd$ /rspamd/ [R,L]
RewriteRule ^/rspamd/(.*) http://sirius10.net:11334/$1 [P,L]
</IfModule>
Require ip で内部ネットワークからのみ許可しています。Apache を再起動します。
$ sudo service apache2 restart
localhost 以外からもつながるように設定します。
$ sudo vi /etc/rspamd/local.d/worker-controller.inc
次の 1 行を追加しました。
bind_socket = “*:11334";
rspamd を再起動します。
$ sudo service rspamd restart
postfix の設定
/etc/postfix/main.cf に以下を追記します。
#rspamd
smtpd_milters = inet:localhost:11332
milter_default_action = accept
milter_protocol = 6
postfix を再起動します。
$ service postfix restart
これで送受信するメールをチェックするようです。

ホワイトリストの作成
Rspamd でホワイトリストの作成方法は次のようになります。
$ cd /etc/rspamd/local.d
$ sudo vi multimap.conf
IP_WHITELIST {
type = "ip";
prefilter = "true";
map = "${LOCAL_CONFDIR}/local.d/ip_whitelist.map";
action = "accept";
}
WHITELIST_SENDER_DOMAIN {
type = "from";
filter = "email:domain";
map = "${LOCAL_CONFDIR}/local.d/sender_domain_whitelist.map";
score = -6.0
}
$ sudo touch ip_whitelist.map sender_domain_whitelist.map
$ sudo chown -R _rspamd:_rspamd .
後は、web の管理画面で、受け取りたい IP アドレスなら、ip_whitelist.map へ、ドメインなら sender_domain_whitelist.map へ追加すればいいです。
ディスカッション
コメント一覧
まだ、コメントがありません