summaryrefslogtreecommitdiff
path: root/pod/nginx/ngx_mail_auth_http_module.pod
blob: 994051cca9fdc5fec1c389bdf08d1a6c9ceac661 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
=encoding utf-8

=head1 NAME

ngx_mail_auth_http_module - Module ngx_mail_auth_http_module




=head1 Directives

=head2 auth_http


B<syntax:> auth_http I<I<C<URL>>>



B<context:> I<mail>


B<context:> I<server>





Sets the URL of the HTTP authentication server.
The protocol is described below.







=head2 auth_http_header


B<syntax:> auth_http_header I<I<C<header>> I<C<value>>>



B<context:> I<mail>


B<context:> I<server>





Appends the specified header to requests sent to the authentication server.
This header can be used as the shared secret to verify
that the request comes from nginx.
For example:

    
    auth_http_header X-Auth-Key "secret_string";









=head2 auth_http_pass_client_cert


B<syntax:> auth_http_pass_client_cert I<C<on> E<verbar> C<off>>


B<default:> I<off>


B<context:> I<mail>


B<context:> I<server>



This directive appeared in version 1.7.11.





Appends the C<Auth-SSL-Cert> header with the
L<client|ngx_mail_ssl_module>
certificate in the PEM format (urlencoded)
to requests sent to the authentication server.







=head2 auth_http_timeout


B<syntax:> auth_http_timeout I<I<C<time>>>


B<default:> I<60s>


B<context:> I<mail>


B<context:> I<server>





Sets the timeout for communication with the authentication server.







=head1 Protocol



The HTTP protocol is used to communicate with the authentication server.
The data in the response body is ignored, the information is passed only in
the headers.





Examples of requests and responses:





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







If there is no C<Auth-Wait> header,
an error will be returned and the connection will be closed.
The current implementation allocates memory for each authentication attempt.
The memory is freed only at the end of a session.
Therefore, the number of invalid authentication attempts in a single session
must be limited — the server must respond without
the C<Auth-Wait> header after 10-20 attempts
(the attempt number is passed in the C<Auth-Login-Attempt>
header).





When the APOP or CRAM-MD5 are used, request-response will look as follows:

    
    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







If the C<Auth-User> header exists in the response,
it overrides the username used to authenticate with the backend.





For the SMTP, the response additionally takes into account
the C<Auth-Error-Code> header — if exists, it is used
as a response code in case of an error.
Otherwise, the 535 5.7.0 code will be added to
the C<Auth-Status> header.





For example, if the following response is received
from the authentication server:

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


then the SMTP client will receive an error

    
    451 4.3.0 Temporary server problem, try again later







If proxying SMTP does not require authentication,
the request will look as follows:

    
    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>







For the SSLE<sol>TLS client connection (1.7.11),
the C<Auth-SSL> header is added, and
C<Auth-SSL-Verify> will contain
the result of client certificate verification, if
L<enabled|ngx_mail_ssl_module>:
“C<SUCCESS>”, “C<FAILED:>I<C<reason>>”,
and “C<NONE>” if a certificate was not present.

B<NOTE>

Prior to version 1.11.7, the “C<FAILED>” result
did not contain the I<C<reason>> string.

When the client certificate was present,
its details are passed in the following request headers:
C<Auth-SSL-Subject>, C<Auth-SSL-Issuer>,
C<Auth-SSL-Serial>, and C<Auth-SSL-Fingerprint>.
If L</auth_http_pass_client_cert> is enabled,
the certificate itself is passed in the
C<Auth-SSL-Cert> header.
The protocol and cipher of the established connection
are passed in the C<Auth-SSL-Protocol>
and C<Auth-SSL-Cipher> headers (1.21.2).
The request will look as follows:

    
    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







When the
L<PROXY protocol|ngx_mail_core_module>
is used,
its details are passed in the following request headers:
C<Proxy-Protocol-Addr>,
C<Proxy-Protocol-Port>,
C<Proxy-Protocol-Server-Addr>, and
C<Proxy-Protocol-Server-Port> (1.19.8).