Postfix smtp拒绝未经身份验证的用户

Postfix smtp拒绝未经身份验证的用户

我已经配置了带有 postfix、dovecot 等的邮件服务器。问题是:每个人都可以连接到我的服务器并发送电子邮件而无需身份验证。我该如何配置 postfix,以便拒绝所有未经身份验证的连接。

我的配置main.cf是:

##
## TLS Einstellungen
###

tls_ssl_options = NO_COMPRESSION
tls_high_cipherlist = EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA256:EECDH:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!IDEA:!ECDSA:kEDH:CAMELLIA128-SHA:AES128-SHA

### Ausgehende SMTP-Verbindungen (Postfix als Sender)

smtp_tls_security_level = dane
smtp_dns_support_level = dnssec
smtp_tls_policy_maps = mysql:/etc/postfix/sql/tls-policy.cf
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtp_tls_protocols = !SSLv2, !SSLv3
smtp_tls_ciphers = high
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

smtpd_sasl_auth_enable = yes

### Eingehende SMTP-Verbindungen

smtpd_tls_security_level = may
smtpd_tls_protocols = !SSLv2, !SSLv3
smtpd_tls_ciphers = high
smtpd_tls_dh1024_param_file = /etc/myssl/dh2048.pem
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache

smtpd_tls_cert_file=/etc/letsencrypt/live/xxxxx/fullchain.pem
smtpd_tls_key_file=/etc/letsencrypt/live/xxxxx/privkey.pem


##
## Milter: DKIM-Signaturen durch OpenDKIM-Milter
## und Mail-Filter mit Amavis (via amavisd-milter)
##

milter_default_action = accept
milter_protocol = 2
smtpd_milters = unix:/var/run/amavis/amavisd-milter.sock,
                unix:/var/run/opendkim/opendkim.sock
non_smtpd_milters = unix:/var/run/opendkim/opendkim.sock

##
## Server Restrictions für Clients, Empfänger und Relaying
## (im Bezug auf S2S-Verbindungen. Mailclient-Verbindungen werden in master.cf im Submission-Bereich konfiguriert)
##

## Sender
smtpd_sender_restrictions = permit_sasl_authenticated


### Bedingungen, damit Postfix als Relay arbeitet (für Clients)
smtpd_relay_restrictions =      reject_non_fqdn_recipient
                                reject_unknown_recipient_domain
                                permit_mynetworks
                                reject_unauth_destination


### check_recipient_access prüft, ob ein account sendonly ist
smtpd_recipient_restrictions = permit_sasl_authenticated,
                               #reject_unauth_destination, 
                               check_recipient_access mysql:/etc/postfix/sql/recipient-access.cf


### Bedingungen, die SMTP-Clients erfüllen müssen (sendende Server)
smtpd_client_restrictions =     permit_mynetworks
                                check_client_access hash:/etc/postfix/without_ptr
                                reject_unknown_client_hostname

# Clients blockieren, wenn sie versuchen zu früh zu senden
smtpd_data_restrictions = reject_unauth_pipelining

我在 master.cf 中为邮件客户端配置:

###
### Postscreen-Service: Prüft eingehende SMTP-Verbindungen auf Spam-Server
###
smtp      inet  n       -       n       -       1       postscreen
    -o smtpd_sasl_auth_enable=no
###
### manual from me (viet)
###
#smtps     inet  n       -       n       -       -       smtpd
#     -o smtpd_sasl_auth_enable=yes
###
### SMTP-Daemon hinter Postscreen: Schleift E-Mails zur Filterung durch Amavis 
###
smtpd     pass  n       -       n       -       -       smtpd
    -o smtpd_sasl_auth_enable=no
###
### dnsblog führt DNS-Abfragen für Blocklists durch
###
dnsblog   unix  -       -       n       -       0       dnsblog
###
### tlsproxy gibt Postscreen TLS support
###
tlsproxy  unix  -       -       n       -       0       tlsproxy
###
### Submission-Zugang für Clients: Für Mailclients gelten andere Regeln, als für andere Mailserver (siehe smtpd_ in main.cf) 
###
submission inet n       -       n       -       -       smtpd
    -o syslog_name=postfix/submission
    -o smtpd_tls_security_level=encrypt
    -o smtpd_sasl_auth_enable=yes
    -o smtpd_sasl_type=dovecot
    -o smtpd_sasl_path=private/auth
    -o smtpd_sasl_security_options=noanonymous
    -o smtpd_relay_restrictions=reject_non_fqdn_recipient,reject_unknown_recipient_domain,permit_mynetworks,permit_sasl_authenticated,reject
    -o smtpd_sender_login_maps=mysql:/etc/postfix/sql/sender-login-maps.cf
    -o smtpd_sender_restrictions=permit_mynetworks,reject_non_fqdn_sender,reject_sender_login_mismatch,permit_sasl_authenticated,reject
    -o smtpd_client_restrictions=permit_mynetworks,permit_sasl_authenticated,reject
    -o smtpd_helo_required=no
    -o smtpd_helo_restrictions=
    -o milter_macro_daemon_name=ORIGINATING
    -o cleanup_service_name=submission-header-cleanup

在 dovecot 中我已经配置了用于身份验证的服务:

service auth {
    ### Auth socket für Postfix
    unix_listener /var/spool/postfix/private/auth {
        mode = 0660
        user = postfix
        group = postfix
    }

    ### Auth socket für LMTP-Dienst
    unix_listener auth-userdb {
        mode = 0660
        user = vmail
        group = vmail
    }
}

无需身份验证发送邮件时的日志如下:

Aug 23 11:25:15 mail postfix/postscreen[4014]: CONNECT from [xx.xxx.xxx.xxx]:xxxx to [x.x.x.x]:25
Aug 23 11:25:15 mail postfix/postscreen[4014]: WHITELISTED [x.x.x.x]:xxxx
Aug 23 11:25:15 mail postfix/postscreen[4014]: warning: cannot connect to service private/smtpd: Connection refused
Aug 23 11:34:36 mail postfix/submission/smtpd[4100]: connect from gate.xxxxx.xxxx.de[x.x.x.x]
Aug 23 11:34:36 mail postfix/submission/smtpd[4100]: 5A60B400CF: client=gate.xxxxx.xxxx.de[x.x.x.x]
Aug 23 11:34:36 mail postfix/cleanup[4103]: 5A60B400CF: message-id=<abcb10b6-96b1-06e9-0e25-2c477a9631ae@mydomain>
Aug 23 11:34:36 mail amavis[3384]: (03384-02) Passed CLEAN {AcceptedOutbound}, AM.PDP-SOCK/ORIGINATING LOCAL [x.xx.x.x] [x.x.x.x] <myemail@mydomain> -> <receicer@email>, Queue-ID: 5A60B400CF, Message-ID: <[email protected]>, mail_id: 8qu_TyPN6ZBY, Hits: -, size: 516, 16 ms
Aug 23 11:34:36 mail opendkim[2794]: 5A60B400CF: gate.xxxxx.xxxx.de [x.x.x.x] not internal
Aug 23 11:34:36 mail opendkim[2794]: 5A60B400CF: not authenticated
Aug 23 11:34:36 mail postfix/qmgr[3371]: 5A60B400CF: from=<myemail@mydomain>, size=357, nrcpt=1 (queue active)
Aug 23 11:34:36 mail postfix/submission/smtpd[4100]: disconnect from gate.xxxxx.xxxx.de[x.x.x.x] ehlo=2 starttls=1 mail=1 rcpt=1 data=1 quit=1 commands=7
Aug 23 11:34:37 mail postfix/smtp[4105]: 5A60B400CF: to=<myemail@mydomain>, relay=receiver.server[x.x.x.x]:25, delay=1.1, delays=0.16/0.03/0.36/0.54, dsn=2.0.0, status=sent (250 2.0.0 from MTA(smtp:[127.0.0.1]:10035): 250 2.0.0 Ok: queued as 56FEC80008E)
Aug 23 11:34:37 mail postfix/qmgr[3371]: 5A60B400CF: removed

更新

现在它起作用了,当我删除permit_mynetworksin时-o smtpd_sender_restrictionspermit_mynetworks不仅适用于本地主机

执行后postconf -d | grep mynetworks我得到:

mynetworks = 127.0.0.0/8 172.31.16.0/20 [::1]/128 [fe80::]/64

答案1

问题是您还没有为 postfix 上的 sasl 身份验证配置用户后端。

smtpd_sasl_type = dovecot

这告诉 postfix 使用 dovecot 进行用户身份验证。

在 dovecot 中,你必须为 postfix 启用一个新的服务监听器

# vim /etc/dovecot/conf.d/10-master.conf

并添加如下内容:

service auth {
    unix_listener /var/spool/postfix/private/auth {
        group = postfix
        mode = 0660
        user = postfix
   }
}

重新启动两个服务并测试它

相关内容