模块 ngx_mail_auth_http_module

auth_http
auth_http_header
auth_http_pass_client_cert
auth_http_timeout
协议Directives

Directives

语法: auth_http URL;
默认值:
上下文: mail,server

设置 HTTP 身份验证服务器的 URL。 该协议如下所述

语法: auth_http_header header value;
默认值:
上下文: mail,server

将指定的标头附加到发送到身份验证服务器的请求中。 此标头可用作共享密钥来验证 请求来自 nginx。 例如:

auth_http_header X-Auth-Key "secret_string";

语法: auth_http_pass_client_cert on | off;
默认值:
auth_http_pass_client_cert off;
上下文: mail,server

该Directives出现在版本 1.7.11 中。

将 “Auth-SSL-Cert” 标头与 PEM 格式 (urlencoded) 的客户端证书附加在一起 发送到身份验证服务器的请求。

语法: auth_http_timeout time;
默认值:
auth_http_timeout 60s;
上下文: mail,server

设置与认证服务器通信的超时。

协议

HTTP 协议用于与身份验证服务器通信。 响应正文中的数据将被忽略,信息仅传入 标头。

请求和响应示例:

请求:

GET /auth HTTP/1.0
Host: localhost
Auth-Method: plain # plain/apop/cram-md5/external
Auth-User: user
Auth-Pass: password
Auth-Protocol: imap # imap/pop3/smtp
Auth-Login-Attempt: 1
Client-IP: 192.0.2.42
Client-Host: client.example.org

良好的响应:

HTTP/1.0 200 OK
Auth-Status: OK
Auth-Server: 198.51.100.1
Auth-Port: 143

糟糕的回应:

HTTP/1.0 200 OK
Auth-Status: Invalid login or password
Auth-Wait: 3

如果没有 “Auth-Wait” 标头, 将返回错误,并且连接将关闭。 当前实现为每次身份验证尝试分配内存。 仅在会话结束时释放内存。 因此,单个会话中无效身份验证尝试的次数 必须限制 — 服务器必须在没有 尝试 10-20 次后显示 “Auth-Wait” 报头 (尝试编号在 “Auth-Login-Attempt” 中传递 标头)。

使用 APOP 或 CRAM-MD5 时,请求-响应将如下所示:

GET /auth HTTP/1.0
Host: localhost
Auth-Method: apop
Auth-User: user
Auth-Salt: <238188073.1163692009@mail.example.com>
Auth-Pass: auth_response
Auth-Protocol: imap
Auth-Login-Attempt: 1
Client-IP: 192.0.2.42
Client-Host: client.example.org

良好的响应:

HTTP/1.0 200 OK
Auth-Status: OK
Auth-Server: 198.51.100.1
Auth-Port: 143
Auth-Pass: plain-text-pass

如果响应中存在 “Auth-User” 标头,则 它会覆盖用于向后端进行身份验证的用户名。

对于 SMTP,响应还会考虑 “Auth-Error-Code” 标头 — 如果存在,则使用它 作为出现错误时的响应代码。 否则,535 5.7.0 代码将被添加到 “Auth-Status” 标头。

例如,如果收到以下响应 从身份验证服务器:

HTTP/1.0 200 OK
Auth-Status: Temporary server problem, try again later
Auth-Error-Code: 451 4.3.0
Auth-Wait: 3

则 SMTP 客户端将收到错误

451 4.3.0 Temporary server problem, try again later

如果代理 SMTP 不需要身份验证, 该请求将如下所示:

GET /auth HTTP/1.0
Host: localhost
Auth-Method: none
Auth-User:
Auth-Pass:
Auth-Protocol: smtp
Auth-Login-Attempt: 1
Client-IP: 192.0.2.42
Client-Host: client.example.org
Auth-SMTP-Helo: client.example.org
Auth-SMTP-From: MAIL FROM: <>
Auth-SMTP-To: RCPT TO: <postmaster@mail.example.com>

对于 SSL/TLS 客户端连接 (1.7.11), 添加了 “Auth-SSL” 标头,并且 “Auth-SSL-Verify” 将包含 客户端证书验证的结果(如果启用): “”, “”, 如果证书不存在,则为 “”。SUCCESSFAILED:reasonNONE

在 1.11.7 版本之前,“” 结果 不包含字符串。FAILEDreason

当客户端证书存在时, 其详细信息在以下请求标头中传递: “auth-ssl-subject”, “auth-ssl-issuer”, “auth-ssl-serial” 和 “auth-ssl-fingerprint”。 如果启用了 auth_http_pass_client_cert, 证书本身在 “Auth-SSL-Cert” 标头。 已建立连接的协议和密码 在 “Auth-SSL-Protocol” 中传递 和 “Auth-SSL-Cipher” 标头 (1.21.2)。 该请求将如下所示:

GET /auth HTTP/1.0
Host: localhost
Auth-Method: plain
Auth-User: user
Auth-Pass: password
Auth-Protocol: imap
Auth-Login-Attempt: 1
Client-IP: 192.0.2.42
Auth-SSL: on
Auth-SSL-Protocol: TLSv1.3
Auth-SSL-Cipher: TLS_AES_256_GCM_SHA384
Auth-SSL-Verify: SUCCESS
Auth-SSL-Subject: /CN=example.com
Auth-SSL-Issuer: /CN=example.com
Auth-SSL-Serial: C07AD56B846B5BFF
Auth-SSL-Fingerprint: 29d6a80a123d13355ed16b4b04605e29cb55a5ad

使用 PROXY 协议时, 其详细信息在以下请求标头中传递: “代理协议地址”, “代理协议端口”, “proxy-protocol-server-addr”和 “代理协议服务器端口”(1.19.8)。