我使用 Postfix 作为 MTA 和中继。希望从远程系统发送电子邮件的用户需要进行身份验证,然后 Postfix 将其交给 Dovecot,这种方法很有效。但是,如何限制哪些用户可以使用 SMTP+身份验证,而不限制对 POP 或 IMAP 的访问?
对我来说,该块是否在 Dovecot 的 SASL 身份验证中,或者通过 Postfix 在表中查找它都无关紧要。
使用 Postfix 2.9.6 作为 SMTP,使用 Dovecot 2.0.19 作为 POP、IMAP 和 SASL。虚拟用户存储在 MySQL 5.5.40 中。
root@mx1:~# postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
append_dot_mydomain = no
biff = no
config_directory = /etc/postfix
home_mailbox = Maildir/
inet_interfaces = all
mailbox_size_limit = 0
message_size_limit = 51200000
mydestination = localhost, mx1.mydomain.tld
myhostname = virtmx.mydomain.tld
mynetworks = /etc/postfix/mynetworks
myorigin = /etc/mailname
policy-spf_time_limit = 3600s
readme_directory = no
recipient_delimiter = +
relay_domains = proxy:mysql:/etc/postfix/mysql_relay_domains_maps.cf
setgid_group = vmail
smtp_tls_mandatory_ciphers = medium
smtp_tls_mandatory_protocols = !SSLv2,!SSLv3
smtp_tls_note_starttls_offer = yes
smtp_tls_protocols = !SSLv2,!SSLv3
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_banner = $myhostname ESMTP $mail_name
smtpd_client_restrictions = permit_mynetworks, permit_sasl_authenticated
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_non_fqdn_hostname, reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unauth_destination, reject_unauth_pipelining, check_policy_service unix:private/policy-spf, reject_rbl_client zen.spamhaus.org, reject_rhsbl_reverse_client dbl.spamhaus.org, reject_rhsbl_helo dbl.spamhaus.org, reject_rhsbl_sender dbl.spamhaus.org
smtpd_sasl_auth_enable = yes
smtpd_sasl_authenticated_header = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_path = private/auth
smtpd_sasl_security_options = noanonymous
smtpd_sasl_tls_security_options = $smtpd_sasl_security_options
smtpd_sasl_type = dovecot
smtpd_sender_restrictions = reject_unknown_sender_domain
smtpd_tls_auth_only = yes
smtpd_tls_cert_file = /etc/postfix/mydomain.tld-virtmx.pem
smtpd_tls_key_file = /etc/postfix/mydomain.tld-virtmx.key
smtpd_tls_loglevel = 1
smtpd_tls_mandatory_protocols = !SSLv2,!SSLv3
smtpd_tls_protocols = !SSLv2,!SSLv3
smtpd_tls_received_header = yes
smtpd_tls_security_level = may
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtpd_use_tls = yes
tls_medium_cipherlist = AES128+EECDH:AES128+EDH
transport_maps = proxy:mysql:/etc/postfix/mysql_transports_maps.cf
virtual_alias_maps = proxy:mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_gid_maps = static:88
virtual_mailbox_base = /srv/mailbox
virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_minimum_uid = 999
virtual_transport = virtual
virtual_uid_maps = proxy:mysql:/etc/postfix/mysql_virtual_uid_maps.cf
如果有帮助的话,这些是使用的 SQL 查询:
mysql_mynetworks.cf
query = SELECT address FROM mailnetworks WHERE address='%s' and active='Y'
mysql_relay_domains_maps.cf
query = SELECT domain FROM maildomains WHERE domain='%s' AND backupmx = 1 AND active = 1
mysql_sender_maps.cf
query = SELECT address FROM mailsender WHERE username='%s'
mysql_transports_maps.cf
query = SELECT transport FROM maildomains WHERE domain='%s' AND transport != '' AND active=1
mysql_virtual_alias_maps.cf
query = SELECT goto FROM mailaliases AS a LEFT JOIN maildomains AS dom ON dom.domain=a.domain WHERE address='%s' AND dom.active=1 and a.active=1
mysql_virtual_domains_maps.cf
query = SELECT domain FROM maildomains WHERE domain='%s' AND backupmx='0' AND active=1
mysql_virtual_mailbox_maps.cf
query = SELECT maildir FROM mailboxes AS box LEFT JOIN maildomains AS dom ON dom.domain=box.domain WHERE username='%s' AND dom.active=1 AND box.active=1
mysql_virtual_uid_maps.cf
query = SELECT uid FROM mailboxes AS box LEFT JOIN maildomains AS dom ON box.domain=dom.domain WHERE username='%s' AND box.active=1 and dom.active=1
答案1
该功能适用于 Postfix 2.11 版本。
您可以使用check_sasl_access
参数来强制执行基于 SASL 用户名的限制。当然您需要将其放在上面permit_sasl_authenticated
。请参考man 5 postconf以获得完整的文档。
示例配置,取自Postfix SASL 操作指南
# main.cf
smtpd_relay_restrictions =
...,
check_sasl_access hash:/etc/postfix/sasl_blacklist,
permit_sasl_authenticated,
...
和
# sasl_blacklist
# Use this when smtpd_sasl_local_domain is empty.
username REJECT
# Use this when smtpd_sasl_local_domain=example.com.
[email protected] REJECT
答案2
针对 postfix < 2.11 的一些解决方法
作者建议您需要reject_sender_login_mismatch
和的组合check_sender_access
。
范围拒绝发送者登录不匹配如果发件人未定义其允许的用户名,则会拒绝。看起来您已经在 中对此进行了查询
mysql_sender_maps.cf
。参数
check_sender_access
将根据发件人拒绝电子邮件。
所以你需要类似的东西
smtpd_sender_login_maps = mysql:/etc/postfix/mysql_sender_maps.cf
smtpd_relay_restriction = ...
...
reject_sender_login_mismatch
check_sender_access hash:/etc/postfix/sasl_reject
...
和
#sasl_reject
[email protected] REJECT
替代方案使用轻量级后发对 SASL 用户名执行某种限制。您可以使用sasl_username
参数来控制此行为。请参阅此postfwd 的文档页面了解更多信息。