Postfix

Postfix smtp 拒絕未經身份驗證的使用者

  • August 23, 2016

我已經配置了一個帶有 postfix、dovecot 的郵件伺服器……問題是:每個人都可以連接到我的伺服器並發送電子郵件而無需身份驗證。如何配置後綴,以便拒絕所有未經身份驗證的連接。

我的配置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: <abcb10b6-96b1-06e9-0e25-2c477a9631ae@qvpham.com>, 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_restrictions。不僅permit_mynetworks適用於localhost

執行後postconf -d | grep mynetworks我得到:

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

問題是您沒有為 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
  }
}

重新啟動兩個服務並測試它

引用自:https://serverfault.com/questions/798529