回答編集履歴

2

#3 Postfix設定のブラッシュアップ

2023/11/17 06:05

投稿

ikedas
ikedas

スコア4357

test CHANGED
@@ -58,3 +58,45 @@
58
58
  - 最後の`reject_unauth_destination`でオープンリレーも防げています。
59
59
  - このあとに今回のルールを追加しています。ここまででsenderが自分のドメインであるようなものは上のいずれかのルールでokになっているはずなので、このルールまでたどり着いたものはrejectします。
60
60
 
61
+ ### \#3
62
+
63
+ 上の\#2で当初の目的は達しているのですが、設定内容について若干補足します。
64
+
65
+ 1. `smtpd_client_restrictions`、`smtpd_helo_restrictions`、`smtpd_sender_restrictions`、`smtpd_recipient_restrictions`のルールはそれぞれコネクション確立、EHLO (HELO) コマンド、MAILコマンド、RCPTコマンドの実行時に評価されるように見えますが、実際は`smtpd_delay_reject = yes` (初期値ではそうなっています) のときは4つともRCPTコマンドの実行時に評価されます。
66
+ (この動作がデフォルトになっているのは、かつてRCPTコマンドより前で拒否しても気づかずに通信を続けようとするクライアントがあったためだそうです。今日でもこの動作は、スパム送信者からのメッセージを拒否する前に少しだけ時間を無駄にさせる〔=スパム送信の能率が落ちる〕という効果が期待できるので望ましいです。)
67
+ とにかく、上記4つのルールは`smtpd_recipient_restrictions`にまとめて書くことができます。
68
+ * ただし`check_client_access`で、テーブル引きの結果が`OK`となる場合、それ以降のルールが無視されてしまいますから修正が必要です。`OK`となるエントリは取り除くか`DUNNO`に書き換える必要があります。
69
+
70
+ 2. 実は、`smtpd_recipient_restrictions`に書いてある`reject_unauth_destination`は実行されません。Postfix 2.10以降、`smtpd_relay_restrictions`が導入されて`smtpd_recipient_restrictions`の直前に実行されるようになりました。`smtpd_relay_restrictions`の初期値は`permit_mynetworks, permit_sasl_authenticated, defer_unauth_destination`であるため、オープンリレーの試みには`reject_unauth_destination`による永続的エラー (554) ではなく`defer_unauth_destination`による一時エラー (454) が返されます。554にしたいのなら修正が必要です。
71
+ 3. 上でも述べたように、`permit_sasl_authenticated`だけでは認証成功したユーザがなりすましし放題ですから、`reject_sender_login_mismatch`などを使って防ぐ必要があります。
72
+
73
+
74
+ 結果として、つぎのようになります (3. は除く)。
75
+ ```
76
+ ...
77
+ # オープンリレーの試みを一時エラー (454) ではなく永続的エラー (554) で拒否する場合
78
+ smtpd_relay_restrictions =
79
+ permit_mynetworks
80
+ permit_sasl_authenticated
81
+ reject_unauth_destination
82
+
83
+ #smtpd_client_restrictions =
84
+ #smtpd_helo_restrictions =
85
+ #smtpd_sender_restrictions =
86
+ smtpd_recipient_restrictions =
87
+ permit_mynetworks
88
+ check_client_access cidr:/etc/postfix/reject_client.cidr
89
+ reject_unknown_reverse_client_hostname
90
+ reject_invalid_helo_hostname
91
+ reject_non_fqdn_sender
92
+ reject_unknown_sender_domain
93
+ permit_sasl_authenticated
94
+ reject_non_fqdn_recipient
95
+ #reject_unauth_destination #上記参照
96
+ check_sender_access hash:/etc/postfix/reject_final_destinations.hash
97
+ #上行は Postfix 3.x以降では次のようにも書ける
98
+ check_sender_access inline:{ mail.example.org = reject, ... }
99
+ ...
100
+
101
+ ```
102
+

1

つづき

2023/11/14 03:29

投稿

ikedas
ikedas

スコア4357

test CHANGED
@@ -20,3 +20,41 @@
20
20
 
21
21
  上記のようなものではなく、当面「自ドメインの送信者を騙るものだけを拒否できればいい」ということなら、Postfixの設定だけで可能だと思います。(書きかけ。しばらくお待ちください)
22
22
 
23
+ (つづき)
24
+
25
+ ちょっと考えすぎだったようで、次のようにしてできました。
26
+
27
+ ```reject_final_destinations.hash
28
+ mail.example.org reject
29
+ ...
30
+ ```
31
+
32
+ ```main.cf
33
+ ...
34
+ smtpd_recipient_restrictions =
35
+ permit_mynetworks,
36
+ permit_sasl_authenticated,
37
+ reject_non_fqdn_recipient,
38
+ reject_unauth_destination
39
+ check_sender_access hash:/etc/postfix/reject_final_destinations.hash
40
+ ...
41
+ ```
42
+ `mail.example.org`は自分のドメインです。自分のドメインが複数あるときは行を追加します。
43
+
44
+ Postfix 3.x以降ならインラインテーブルを使って次のようにも書けると思います。
45
+ ```main.cf
46
+ ...
47
+ smtpd_recipient_restrictions =
48
+ permit_mynetworks,
49
+ permit_sasl_authenticated,
50
+ reject_non_fqdn_recipient,
51
+ reject_unauth_destination
52
+ check_sender_access inline:{ mail.example.org = reject, ... }
53
+ ...
54
+ ```
55
+
56
+ - `permit_mynetworks`で、自サイト内のリレーには制限がありません。
57
+ - `permit_sasl_authenticated`で、認証が成功したユーザによる送信も制限がありません (ただし、このままだと認証できたユーザはなりすましが可能なので`reject_sender_login_mismatch`などでチェックしたほうがいいと思いますが)。
58
+ - 最後の`reject_unauth_destination`でオープンリレーも防げています。
59
+ - このあとに今回のルールを追加しています。ここまででsenderが自分のドメインであるようなものは上のいずれかのルールでokになっているはずなので、このルールまでたどり着いたものはrejectします。
60
+