温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么在postfix服务器上配置SASL认证

发布时间:2021-11-16 11:57:37 来源:亿速云 阅读:572 作者:iii 栏目:大数据

这篇文章主要介绍“怎么在postfix服务器上配置SASL认证”,在日常操作中,相信很多人在怎么在postfix服务器上配置SASL认证问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”怎么在postfix服务器上配置SASL认证”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

简介:如果客户端与postfix没有处在同一个网络,则需要通过SASL机制进行认证授权,授权后客户端就可以与处在同一网络的客户端一样拥有相同的权限了。postfix本身并不实现 SASL,而是采用一个第三方的实现来作为postfix的一个模块,所以sasl相关的配置有些是属于postfix,有些属于第三方模块。

在postfix服务器上配置SASL认证的步骤:

  • sasl实现可以提供一系列认证机制,通过配置来选择使用哪些认证方式。

  • 配置postfix启用sasl认证并授权客户端发送邮件或者控制信封上的发件人地址。

postfix通过插件的方式来支持多种不同的sasl实现,比如:Cyrus SASL and Dovecot SASL,可以通过以下命令来查看当前哪些实现编译进了postfix:

% postconf -a (SASL support in the SMTP server)
% postconf -A (SASL support in the SMTP+LMTP client)

配置Dovecot SASL:

1 conf.d/10-master.conf:
 2     service auth {
 3       ...
 4       unix_listener /var/spool/postfix/private/auth {
 5         mode = 0660
 6         # Assuming the default Postfix user and group
 7         user = postfix
 8         group = postfix        
 9       }
10       ...
11     }
12 
13 conf.d/10-auth.conf
14     auth_mechanisms = plain login

第4行:采用unix-domain socket

第5-8行:配置了只允许postfix用户和组有读写权限

第14行:提供了plain,login两种认证机制

Cyrus SASL配置:

第一步需要确定配置文件的名称和位置,配置文件名是postfix smtp服务发送给Cyrus SASL库的值再加上.conf后缀, postfix发送的值为采用Cyrus SASL的组件名称,默认为smtpd,所以配置文件名默认为smtpd.conf:

/etc/postfix/main.cf:
    # Postfix 2.3 and later
    smtpd_sasl_path = smtpd

    # Postfix < 2.3
    smtpd_sasl_application_name = smtpd

Cyrus SASL会搜寻配置文件的位置,具体需要看Cyrus的版本和一些postfix的发行版本身的规则。

postfix链接cyrus sasl 的库libsasl,通过调用sasl库来与cyrus通信。sasl库可以使用外部的密码校验服务或者通过内部插件连接到后端的认证服务来认证客户端:

authentication backendpassword verification service / plugin
/etc/shadowsaslauthd
PAMsaslauthd
IMAP serversaslauthd
sasldbsasldb
MySQL, PostgreSQL, SQLitesql
LDAPldapdb

saslauthd:postfix通过unix-domain socket与saslauthd服务进行通信。

在postfix中启用sasl认证:

postfix默认采用Cyrus sasl实现,可以通过配置改为dovecot:

/etc/postfix/main.cf:
    smtpd_sasl_type = dovecot

指定dovecot的访问unix-domain socket地址:

/etc/postfix/main.cf:
    smtpd_sasl_path = private/auth

如果采用tcp socket通信,可以这样配置:

/etc/postfix/main.cf:
    smtpd_sasl_path = inet:127.0.0.1:12345

启用sasl认证:

/etc/postfix/main.cf:
    smtpd_sasl_auth_enable = yes

启用了sasl之后,postfix会在ehlo指令的结果中告诉客户端不前支持哪些认证机制,但是,有些比较旧的客户端不能识别这些格式,这时可以配置postfix以兼容格式重复输出一次以便让旧的客户端了能识别:

/etc/postfix/main.cf:
    broken_sasl_auth_clients = yes

postfix可以配置一些限制策略还允许或禁止某些sasl机制,其选项如下:

PropertyDescription
noanonymousDon't use mechanisms that permit anonymous authentication.
noplaintextDon't use mechanisms that transmit unencrypted username and password information.
nodictionaryDon't use mechanisms that are vulnerable to dictionary attacks.
forward_secrecyRequire forward secrecy between sessions (breaking one session does not break earlier sessions).
mutual_authUse only mechanisms that authenticate both the client and the server to each other.

默认的策略配置如下:

/etc/postfix/main.cf:
    # Specify a list of properties separated by comma or whitespace
    smtpd_sasl_security_options = noanonymous

注意:至少应该配置禁止匿名认证。

加密TLS会话:

不采用tls会话时,postfix通过另一组参数来配置sasl机制,默认情况下是复制非tls会话的配置:

/etc/postfix/main.cf:
    smtpd_sasl_tls_security_options = $smtpd_sasl_security_options

如果想分开配置,可以这样:

/etc/postfix/main.cf:
    smtpd_sasl_security_options = noanonymous, noplaintext
    smtpd_sasl_tls_security_options = noanonymous

仅仅在建立了tls会话之后才启用sasl认证:

/etc/postfix/main.cf:
    smtpd_tls_auth_only = yes

在客户端经过认证后,postfix会决定客户端可以被授权做哪些事情,比如:可以发送邮件给外站用户,使用特定的信封发件人作为mail from指令值,这些权限默认是不允许的。

邮件转发授权:

# With Postfix 2.10 and later, the mail relay policy is
# preferably specified under smtpd_relay_restrictions.
/etc/postfix/main.cf:
    smtpd_relay_restrictions =
        permit_mynetworkspermit_sasl_authenticatedreject_unauth_destination
# Older configurations combine relay control and spam control under
# smtpd_recipient_restrictions. To use this example with Postfix ≥
# 2.10 specify "smtpd_relay_restrictions=".
/etc/postfix/main.cf:
    smtpd_recipient_restrictions =
        permit_mynetworkspermit_sasl_authenticatedreject_unauth_destination
        ...other rules...

到此,关于“怎么在postfix服务器上配置SASL认证”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI