2014年1月26日日曜日

Postfix Tips: 外部へのメール送信に配送制限をかけるには

今回は、お行儀の悪いユーザがいるメールサーバの管理者に向けてのTipsです。

具体的には、
  1. 特定ドメインに対して(短時間に)大量のメールを送信する(怒)
  2. その結果、特定ドメインにペナルティを科せられてメールを受け取ってもらえなくなる
  3. いつまでも配送できないキューが溜まりまくる
といった状況な時に使います。
※もしくはそういう状況に陥らない為に使います

つまり、特定ドメインに対して短時間に大量のメールを送ろうとしても、ゆっくりと配送するように制限をかけてしまいます。



以下、gmailへの送信を例に実際の設定例です。

1./etc/postfix/master.cfに新しいtransportを作成(定義)
 →ここで作成したtransportの名前がmain.cfで指定するパラメータ名の一部になります

slow      unix  -       -       n       -       -       smtp
     -o syslog_name=postfix-slow


2./etc/postfix/main.cfを編集
 →master.cfに指定したtransport名を使って設定します

# 配送制限をかけるドメインをtransportに指定
transport_maps = hash:/etc/postfix/transport

# 1コネクションでのメール制限
slow_initial_destination_concurrency = 2
slow_destination_concurrency_limit = 10


# 配送制限(ここでは10秒で指定)
slow_destination_rate_delay = 10s


3./etc/postfix/transportの編集
 →編集後、postmap /etc/postfix/transport を実行する必要があります

gmail.com  slow:

4.postfix reloadを実行



これでどんなに大量にメールを送信しようとしても10秒ごとにしかメールが配送できなくなります。
※下記は、ローカルからgmail宛てに1秒間に10通のメールを送信した際のログです
  →ぴったり10秒にはなりませんでしが、delay=19 → delay=30 → delay=41 と一気に送信したのにもかかわらずゆっくりと配送されているのがわかると思います

Jan 26 00:20:34 mailsv postfix/smtpd[1413]: connect from localhost.localdomain[127.0.0.1]
Jan 26 00:20:34 mailsv postfix/smtpd[1413]: 6BB6540275: client=localhost.localdomain[127.0.0.1]
Jan 26 00:20:34 mailsv postfix/cleanup[1416]: 6BB6540275: message-id=<0582.0003.0009@mailsv.example.com>
Jan 26 00:20:34 mailsv postfix/qmgr[1398]: 6BB6540275: from=<foo@mailsv.example.com>, size=867, nrcpt=1 (queue active)
Jan 26 00:20:34 mailsv postfix/smtpd[1413]: disconnect from localhost.localdomain[127.0.0.1]
Jan 26 00:20:34 mailsv postfix/smtpd[1413]: connect from localhost.localdomain[127.0.0.1]
Jan 26 00:20:34 mailsv postfix/smtpd[1413]: 70AB840C80: client=localhost.localdomain[127.0.0.1]
Jan 26 00:20:34 mailsv postfix/cleanup[1416]: 70AB840C80: message-id=<0582.0003.0008@mailsv.example.com>
Jan 26 00:20:34 mailsv postfix/qmgr[1398]: 70AB840C80: from=<foo@mailsv.example.com>, size=867, nrcpt=1 (queue active)
Jan 26 00:20:34 mailsv postfix/smtpd[1413]: disconnect from localhost.localdomain[127.0.0.1]
Jan 26 00:20:34 mailsv postfix/smtpd[1413]: connect from localhost.localdomain[127.0.0.1]
Jan 26 00:20:34 mailsv postfix/smtpd[1413]: 74B9040C81: client=localhost.localdomain[127.0.0.1]
Jan 26 00:20:34 mailsv postfix/cleanup[1418]: 74B9040C81: message-id=<0582.0003.0007@mailsv.example.com>
Jan 26 00:20:34 mailsv postfix/qmgr[1398]: 74B9040C81: from=<foo@mailsv.example.com>, size=867, nrcpt=1 (queue active)
Jan 26 00:20:34 mailsv postfix/smtpd[1413]: disconnect from localhost.localdomain[127.0.0.1]
Jan 26 00:20:34 mailsv postfix/smtpd[1413]: connect from localhost.localdomain[127.0.0.1]
Jan 26 00:20:34 mailsv postfix/smtpd[1413]: 792E840C84: client=localhost.localdomain[127.0.0.1]
Jan 26 00:20:34 mailsv postfix/cleanup[1416]: 792E840C84: message-id=<0582.0003.0006@mailsv.example.com>
Jan 26 00:20:34 mailsv postfix/qmgr[1398]: 792E840C84: from=<foo@mailsv.example.com>, size=867, nrcpt=1 (queue active)
Jan 26 00:20:34 mailsv postfix/smtpd[1413]: disconnect from localhost.localdomain[127.0.0.1]
Jan 26 00:20:34 mailsv postfix/smtpd[1413]: connect from localhost.localdomain[127.0.0.1]
Jan 26 00:20:34 mailsv postfix/smtpd[1413]: 79E6940C85: client=localhost.localdomain[127.0.0.1]
Jan 26 00:20:34 mailsv postfix/cleanup[1418]: 79E6940C85: message-id=<0582.0003.0005@mailsv.example.com>
Jan 26 00:20:34 mailsv postfix/qmgr[1398]: 79E6940C85: from=<foo@mailsv.example.com>, size=867, nrcpt=1 (queue active)
Jan 26 00:20:34 mailsv postfix/smtpd[1413]: disconnect from localhost.localdomain[127.0.0.1]
Jan 26 00:20:34 mailsv postfix/smtpd[1413]: connect from localhost.localdomain[127.0.0.1]
Jan 26 00:20:34 mailsv postfix/smtpd[1413]: 7CD8641272: client=localhost.localdomain[127.0.0.1]
Jan 26 00:20:34 mailsv postfix/cleanup[1416]: 7CD8641272: message-id=<0582.0003.0004@mailsv.example.com>
Jan 26 00:20:34 mailsv postfix/qmgr[1398]: 7CD8641272: from=<foo@mailsv.example.com>, size=867, nrcpt=1 (queue active)
Jan 26 00:20:34 mailsv postfix/smtpd[1413]: disconnect from localhost.localdomain[127.0.0.1]
Jan 26 00:20:34 mailsv postfix/smtpd[1413]: connect from localhost.localdomain[127.0.0.1]
Jan 26 00:20:34 mailsv postfix/smtpd[1413]: 7F67F41273: client=localhost.localdomain[127.0.0.1]
Jan 26 00:20:34 mailsv postfix/cleanup[1418]: 7F67F41273: message-id=<0582.0003.0003@mailsv.example.com>
Jan 26 00:20:34 mailsv postfix/qmgr[1398]: 7F67F41273: from=<foo@mailsv.example.com>, size=867, nrcpt=1 (queue active)
Jan 26 00:20:34 mailsv postfix/smtpd[1413]: disconnect from localhost.localdomain[127.0.0.1]
Jan 26 00:20:34 mailsv postfix/smtpd[1413]: connect from localhost.localdomain[127.0.0.1]
Jan 26 00:20:34 mailsv postfix/smtpd[1413]: 8302441274: client=localhost.localdomain[127.0.0.1]
Jan 26 00:20:34 mailsv postfix/cleanup[1416]: 8302441274: message-id=<0582.0003.0002@mailsv.example.com>
Jan 26 00:20:34 mailsv postfix/qmgr[1398]: 8302441274: from=<foo@mailsv.example.com>, size=867, nrcpt=1 (queue active)
Jan 26 00:20:34 mailsv postfix/smtpd[1413]: disconnect from localhost.localdomain[127.0.0.1]
Jan 26 00:20:34 mailsv postfix/smtpd[1413]: connect from localhost.localdomain[127.0.0.1]
Jan 26 00:20:34 mailsv postfix/smtpd[1413]: 8884141275: client=localhost.localdomain[127.0.0.1]
Jan 26 00:20:34 mailsv postfix/cleanup[1418]: 8884141275: message-id=<0582.0003.0001@mailsv.example.com>
Jan 26 00:20:34 mailsv postfix/qmgr[1398]: 8884141275: from=<foo@mailsv.example.com>, size=867, nrcpt=1 (queue active)
Jan 26 00:20:34 mailsv postfix/smtpd[1413]: disconnect from localhost.localdomain[127.0.0.1]
Jan 26 00:20:34 mailsv postfix/smtpd[1413]: connect from localhost.localdomain[127.0.0.1]
Jan 26 00:20:34 mailsv postfix/smtpd[1413]: 8C31D41276: client=localhost.localdomain[127.0.0.1]
Jan 26 00:20:34 mailsv postfix/cleanup[1416]: 8C31D41276: message-id=<0582.0003.0000@mailsv.example.com>
Jan 26 00:20:34 mailsv postfix/qmgr[1398]: 8C31D41276: from=<foo@mailsv.example.com>, size=867, nrcpt=1 (queue active)
Jan 26 00:20:34 mailsv postfix/smtpd[1413]: disconnect from localhost.localdomain[127.0.0.1]
Jan 26 00:20:53 mailsv postfix-slow/smtp[1417]: 6BB6540275: to=<fuga@gmail.com>, relay=gmail-smtp-in.l.google.com[74.125.25.26]:25, delay=19, delays=0.02/0.01/0.36/18, dsn=2.0.0, status=sent (250 2.0.0 OK 1390663253 yh9si5084332pab.5 - gsmtp)
Jan 26 00:20:53 mailsv postfix/qmgr[1398]: 6BB6540275: removed
Jan 26 00:21:04 mailsv postfix-slow/smtp[1417]: 70AB840C80: to=<fuga@gmail.com>, relay=gmail-smtp-in.l.google.com[74.125.25.26]:25, delay=30, delays=0.02/29/0.45/0.95, dsn=2.0.0, status=sent (250 2.0.0 OK 1390663264 s7si5004113pae.243 - gsmtp)
Jan 26 00:21:04 mailsv postfix/qmgr[1398]: 70AB840C80: removed
Jan 26 00:21:15 mailsv postfix-slow/smtp[1417]: 74B9040C81: to=<fuga@gmail.com>, relay=gmail-smtp-in.l.google.com[74.125.25.27]:25, delay=41, delays=0.02/40/0.37/0.89, dsn=2.0.0, status=sent (250 2.0.0 OK 1390663275 if4si5018201pbc.256 - gsmtp)
Jan 26 00:21:15 mailsv postfix/qmgr[1398]: 74B9040C81: removed
Jan 26 00:21:27 mailsv postfix-slow/smtp[1417]: 792E840C84: to=<fuga@gmail.com>, relay=gmail-smtp-in.l.google.com[173.194.79.26]:25, delay=53, delays=0/51/0.36/1.2, dsn=2.0.0, status=sent (250 2.0.0 OK 1390663287 ef2si5024111pbb.251 - gsmtp)
Jan 26 00:21:27 mailsv postfix/qmgr[1398]: 792E840C84: removed
Jan 26 00:21:38 mailsv postfix-slow/smtp[1417]: 79E6940C85: to=<fuga@gmail.com>, relay=gmail-smtp-in.l.google.com[173.194.79.26]:25, delay=64, delays=0.01/63/0.36/0.82, dsn=2.0.0, status=sent (250 2.0.0 OK 1390663298 vb2si2342207pbc.157 - gsmtp)
Jan 26 00:21:38 mailsv postfix/qmgr[1398]: 79E6940C85: removed
Jan 26 00:21:49 mailsv postfix-slow/smtp[1417]: 7CD8641272: to=<fuga@gmail.com>, relay=gmail-smtp-in.l.google.com[74.125.129.27]:25, delay=75, delays=0.01/74/0.34/0.69, dsn=2.0.0, status=sent (250 2.0.0 OK 1390663309 ye6si5033450pbc.200 - gsmtp)
Jan 26 00:21:49 mailsv postfix/qmgr[1398]: 7CD8641272: removed
Jan 26 00:22:00 mailsv postfix-slow/smtp[1417]: 7F67F41273: to=<fuga@gmail.com>, relay=gmail-smtp-in.l.google.com[74.125.129.27]:25, delay=86, delays=0.01/85/0.35/0.71, dsn=2.0.0, status=sent (250 2.0.0 OK 1390663320 xu6si5070591pab.80 - gsmtp)
Jan 26 00:22:00 mailsv postfix/qmgr[1398]: 7F67F41273: removed
Jan 26 00:22:11 mailsv postfix-slow/smtp[1417]: 8302441274: to=<fuga@gmail.com>, relay=gmail-smtp-in.l.google.com[74.125.25.26]:25, delay=97, delays=0.02/96/0.38/0.71, dsn=2.0.0, status=sent (250 2.0.0 OK 1390663331 r7si5013931pbk.267 - gsmtp)
Jan 26 00:22:11 mailsv postfix/qmgr[1398]: 8302441274: removed
Jan 26 00:22:22 mailsv postfix-slow/smtp[1417]: 8884141275: to=<fuga@gmail.com>, relay=gmail-smtp-in.l.google.com[74.125.25.27]:25, delay=108, delays=0.01/107/0.36/0.71, dsn=2.0.0, status=sent (250 2.0.0 OK 1390663342 s4si5028494pbg.213 - gsmtp)
Jan 26 00:22:22 mailsv postfix/qmgr[1398]: 8884141275: removed
Jan 26 00:22:34 mailsv postfix-slow/smtp[1417]: 8C31D41276: to=<fuga@gmail.com>, relay=gmail-smtp-in.l.google.com[74.125.25.27]:25, delay=119, delays=0.03/118/0.36/0.7, dsn=2.0.0, status=sent (250 2.0.0 OK 1390663354 sj5si5023288pab.197 - gsmtp)
Jan 26 00:22:34 mailsv postfix/qmgr[1398]: 8C31D41276: removed

1 件のコメント: