ngx_mail_auth_http_module 모듈
ngx_mail_auth_http_module은 메일 클라이언트의 인증을 처리하는 HTTP 인증 서버에 요청을 보내는 모듈이에요. 메일 프록시 서버가 클라이언트를 백엔드로 보내기 전에, 별도의 HTTP 서버에게 "이 사용자가 정말 맞는지" 확인을 맡기는 방식이라고 이해하면 돼요.
출처: 문서
본문
지시어 (Directives)
| Syntax: | auth_http URL; |
|---|---|
| Default: | — |
| Context: | mail, server |
HTTP 인증 서버의 URL을 설정해요. 프로토콜에 대한 자세한 내용은 아래에서 설명할게요.
| Syntax: | auth_http_header header value; |
|---|---|
| Default: | — |
| Context: | mail, server |
인증 서버로 보내는 요청에 지정한 헤더를 덧붙여요. 이 헤더는 요청이 정말 nginx에서 온 것인지 확인하는 공유 비밀키(shared secret)로 사용할 수 있어요. 예를 들어:
auth_http_header X-Auth-Key "secret_string";
| Syntax: | auth_http_pass_client_cert on | off; |
|---|---|
| Default: | ``` |
| auth_http_pass_client_cert off; |
|
| Context: | mail, server |
이 지시어는 1.7.11 버전에서 추가되었어요.
인증 서버로 보내는 요청에 클라이언트 인증서를 PEM 형식(urlencoded)으로 담은 "Auth-SSL-Cert" 헤더를 덧붙여요.
| Syntax: | auth_http_timeout time; |
|---|---|
| Default: | ```
auth_http_timeout 60s;
| | Context: | mail, server |
인증 서버와 통신할 때의 타임아웃을 설정해요.
프로토콜 (Protocol)
인증 서버와의 통신에는 HTTP 프로토콜을 사용해요. 응답 본문의 데이터는 무시하고, 정보는 오직 헤더로만 전달된답니다.
요청과 응답의 예를 살펴볼게요.
요청 (Request):
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
성공 응답 (Good response):
HTTP/1.0 200 OK
Auth-Status: OK
Auth-Server: 198.51.100.1
Auth-Port: 143
실패 응답 (Bad response):
HTTP/1.0 200 OK
Auth-Status: Invalid login or password
Auth-Wait: 3
"Auth-Wait" 헤더가 없다면 오류가 반환되고 연결이 닫혀요. 현재 구현에서는 인증 시도마다 메모리를 할당하고, 이 메모리는 세션이 끝날 때에만 해제된답니다. 그래서 한 세션 안에서의 실패한 인증 시도 횟수를 제한해야 해요 — 서버는 10~20회의 시도 이후에는(시도 횟수는 "Auth-Login-Attempt" 헤더로 전달돼요) "Auth-Wait" 헤더 없이 응답해야 해요.
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
성공 응답 (Good response):
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" 헤더도 추가로 고려해요 — 이 헤더가 있다면 오류 발생 시 응답 코드로 사용하고, 없다면 "Auth-Status" 헤더에 535 5.7.0 코드를 덧붙여요.
예를 들어 인증 서버로부터 다음과 같은 응답을 받았다면:
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"에 그 결과가 담겨요: "SUCCESS", "FAILED:reason", 그리고 인증서가 없을 경우 "NONE"이 들어가요.
1.11.7 버전 이전에는 "FAILED" 결과에 이유 문자열이 포함되지 않았어요.
클라이언트 인증서가 존재할 때는 그 세부 정보가 다음 요청 헤더로 전달돼요: "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 protocol을 사용할 때는 그 세부 정보가 다음 요청 헤더로 전달돼요: "Proxy-Protocol-Addr", "Proxy-Protocol-Port", "Proxy-Protocol-Server-Addr", 그리고 "Proxy-Protocol-Server-Port"(1.19.8).