Postfix 错误地检查已通过身份验证的提交邮件客户端的 SPF 策略

Postfix 错误地检查已通过身份验证的提交邮件客户端的 SPF 策略

我在 Ubuntu 23.10 上运行 Postfix 3.8.1。Postfix 使用端口 25 接收来自其他 MTA 的来信,使用端口 587 接收经过身份验证的 MUA。

Postfix 应该通过 SPF 检查端口 25 上来自其他 MTA 的邮件,但不会通过 SPF 检查端口 587 上来自经过身份验证的 MUA 的邮件。但是,Postfix 错误地对经过身份验证的 MUA 进行了此操作,导致 SPF 失败(因为 MUA 未被列为允许的邮件服务器)。

我感觉好像 Postfix 只是忽略了 MUA 的特殊规则,但我没有发现我的配置错误。

我的master.cnf

# ==========================================================================
# service type  private unpriv  chroot  wakeup  maxproc command + args
#               (yes)   (yes)   (no)    (never) (100)
# ==========================================================================
smtp      inet  n       -       y       -       -       smtpd
submission inet n       -       y       -       -       smtpd
  -o syslog_name=postfix/submission
  -o smtpd_tls_security_level=encrypt
  -o smtpd_sasl_auth_enable=yes
  -o cleanup_service_name=header_cleanup
  -o smtpd_client_restrictions=$mua_client_restrictions
  -o smtpd_helo_restrictions=$mua_helo_restrictions
  -o smtpd_sender_restrictions=$mua_sender_restrictions
  -o smtpd_relay_restrictions=$mua_relay_restrictions
header_cleanup unix n   -       -       -       0       cleanup
  -o header_checks=regexp:/etc/postfix/submission_header_cleanup.cf

上述配置的想法是smtpd在端口 587(submission)上应该使用一些特殊配置。

我的main.cf

smtpd_delay_reject = yes

smtpd_client_restrictions =
  reject_unauth_pipelining,
  reject_unknown_client_hostname
mua_client_restrictions =
  reject_unauth_pipelining

smtpd_helo_required = yes

smtpd_helo_restrictions =
  reject_invalid_helo_hostname,
  reject_non_fqdn_helo_hostname,
  reject_unknown_helo_hostname
mua_helo_restrictions =
  reject_invalid_helo_hostname

strict_rfc821_envelopes = yes

smtpd_sender_restrictions =
  reject_non_fqdn_sender,
  reject_unknown_sender_domain
mua_sender_restrictions =
  reject_non_fqdn_sender,
  reject_unknown_sender_domain
  reject_plaintext_session,
  reject_sender_login_mismatch

smtpd_relay_restrictions =
  reject_non_fqdn_recipient,
  reject_unknown_recipient_domain,
  reject_unauth_destination
mua_relay_restrictions =
  reject_non_fqdn_recipient,
  reject_unknown_recipient_domain,
  permit_sasl_authenticated,
  reject

smtpd_recipient_restrictions =
  check_policy_service unix:private/policyd-spf,
  permit

policyd-spf_time_limit = 3600

smtpd_sasl_type=dovecot
smtpd_sasl_path=private/auth
smtpd_sasl_auth_enable=no

这个想法是,在步骤 1 中,经过身份验证的客户端将无条件被允许,而其他客户端将被拒绝。这意味着对于经过身份验证的客户端,访问控制应该到此为止。这也是为什么只有端口 25 上的客户端mua_relay_restrictions才有 而没有相应的 的原因,因为 Postfix 永远不应该达到这一点。smtpd_recipient_restrictionsmua_recipient_restriction

但是,如果我使用邮件客户端通过我的 Postfix 邮件服务器向我的另一个邮箱(外部托管)发送邮件,我会在我的邮件服务器上看到以下日志:

postfix/submission/smtpd[515502]: Anonymous TLS connection established from pd9ecf27b.dip0.t-ipconnect.de[217.236.242.123]: TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-sign>
policyd-spf[515508]: : prepend Received-SPF: Softfail (mailfrom) identity=mailfrom; client-ip=217.236.242.123; helo=my-touchpad.localnet; [email protected]; receiver=other-domain.tld

SPF 必定会失败,这是显而易见的。MUA 是拨号线路 (pd9ecf27b.dip0.t-ipconnect.de[217.236.242.123]) 上的客户端 (my-touchpad.localnet),该线路未列入 SPF 策略中my-domain.tld。当然,这不是因为 SPF 策略只列出了邮件服务器本身。

不过,我很奇怪 Postfix 为什么要执行该检查。SPF 检查只是其中的一部分,smtpd_recipient_restrictions不应该应用于经过身份验证的 MUA。

答案1

检查 SPF 只是smtpd_recipient_restrictions其中的一部分,不应应用于经过身份验证的 MUA。

这是一个错误的假设。smtpd_recipient_restrictions仅当配置为在检查 SPF 策略之前允许经过身份验证的 MUA 时才会执行此操作,例如,

smtpd_recipient_restrictions =
  permit_sasl_authenticated,
  check_policy_service unix:private/policyd-spf,
  permit

因为...

限制按照指定的顺序应用;第一个匹配的限制获胜。

您当前拥有一个针对所有 smtpd 实例的全局设置,包括检查 SPF 的提交并允许任何消息通过 SPF 检查:

smtpd_recipient_restrictions =
  check_policy_service unix:private/policyd-spf,
  permit

为了不将其应用于经过身份验证的 MUA,此参数在提交时应该有所不同,这是通过覆盖以下参数来实现的master.cf

submission inet n       -       y       -       -       smtpd
  . . .
  -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject

或者,如果你遵循使用自定义变量的模式(即不是Postfix 配置参数) 定义为mua_*_restrictions在您的中main.cf并将它们用作中的变量master.cf,您将拥有:

  • main.cf

    mua_recipient_restrictions =
       permit_sasl_authenticated,
       reject
    
  • master.cf

    submission inet n       -       y       -       -       smtpd
       . . .
       -o smtpd_recipient_restrictions=$mua_recipient_restrictions
    

答案2

我没有看到-o smtpd_recipient_restrictions=$mua_recipient_restrictions你的任何一行master.cf这将覆盖你的 main.cf 全局默认值。

这不应该适用于经过身份验证的 MUA

您认为不应该应用的内容并非专门为端口 25 实例配置的。由于您将其放在 main.cf 中,因此它作为两个实例的默认设置。Postfix 为两个smtpd实例(服务于 MX 角色和处理经过身份验证的提交)应用相同的收件人限制类,因为您修改了全局默认值,并且没有将其改回用于该特殊提交服务。

您可以(虽然这不是唯一的解决方案,但似乎是一种一致且可读的方式,可以达到您想要的效果)像对待其他限制类一样覆盖它。

mua_recipient_restrictions = permit_sasl_authenticated, reject

相关内容