Debian Codegraph @

doc/sources/admin/authssl.rst

raw
1 Mutual TLS Authentication
2 =========================
3
4 ============== ===== ========
5 Authentication Users Password
6 ============== ===== ========
7 ✔
8 ============== ===== ========
9
10 Presentation
11 ------------
12
13 LemonLDAP::NG can be configured to authenticate users through client TLS
14 certificates, this is called Mutual TLS Authentication (mTLS). This is most
15 commonly used to perform authentication with smartcards.
16
17 In this configuration, the actual validation is performed by the web server
18 (Apache/Nginx), and LemonLDAP::NG only receives the username extracted by the
19 webserver from the user's certificate.
20
21 There are two possible setups:
22
23 * In the most usual setup, LemonLDAP::NG must be configured to use the
24 :doc:`Authentication choice <authchoice>` module.
25 The main portal VHost (`auth.example.com`) does not require client
26 certificates. A secondary VHost is configured to require client certificates,
27 and an Ajax request is performed from the portal to obtain the user identity.
28
29 .. figure:: mtls-choice.png
30 :alt: Using mTLS authentication with a secondary VHost
31
32 This setup is required when combining mTLS authentication with other
33 authentication methods (such as passwords)
34
35
36 * In a simpler, but rarely used setup, LemonLDAP::NG is configured to use the
37 SSL Authentication module for all authentication attempts, in this case, the
38 main VHost must be configured to require client certificates, which means no
39 other authentication method can be used.
40
41
42 Web server configuration
43 -------------------------
44
45 Whether you configure the regular portal VHost to require SSL, or enable a secondary portal VHost, you need to configure your webserver to require client certificates, and transmit an environment variable to the LemonLDAP::NG application.
46
47 Apache
48 ~~~~~~
49
50 Enable SSL in Apache
51 ^^^^^^^^^^^^^^^^^^^^
52
53 You have to install mod_ssl for Apache.
54
55 For CentOS/RHEL:
56
57 .. code-block:: shell
58
59 yum install mod_ssl
60
61
62 .. tip::
63
64 In Debian/Ubuntu mod_ssl is already shipped in
65 ``apache*-common`` package.
66
67
68 .. tip::
69
70 For CentOS/RHEL, We advice to disable the default SSL virtual
71 host configured in /etc/httpd/conf.d/ssl.conf.
72
73 Apache SSL global configuration
74 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
75
76 You can then use this default SSL configuration, for example in the head
77 of /etc/lemonldap-ng/portal-apache2.conf:
78
79 .. code-block:: apache
80
81 SSLProtocol all -SSLv2
82 SSLCipherSuite HIGH:MEDIUM
83 SSLCertificateFile /etc/httpd/certs/ow2.cert
84 SSLCertificateKeyFile /etc/httpd/certs/ow2.key
85 SSLCACertificateFile /etc/httpd/certs/ow2-ca.cert
86
87
88 .. note::
89
90 Put your own files instead of ``ow2.cert``, ``ow2.key``,
91 ``ow2-ca.cert``:
92
93 - **SSLCertificateFile**: Server certificate
94 - **SSLCertificateKeyFile**: Server private key
95 - **SSLCACertificateFile**: CA certificate to validate client
96 certificates
97
98
99
100 If you specify port in virtual host, then declare SSL port:
101
102 .. code-block:: apache
103
104 NameVirtualHost *:80
105 NameVirtualHost *:443
106
107 Apache portal SSL configuration
108 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
109
110 Edit the portal virtual host or your secondary vhost to enable SSL double authentication:
111
112 .. code-block:: apache
113
114 SSLEngine On
115 SSLVerifyClient optional
116 SSLVerifyDepth 10
117 SSLOptions +StdEnvVars
118 SSLUserName SSL_CLIENT_S_DN_CN
119
120 All SSL options are documented in `Apache mod_ssl
121 page <http://httpd.apache.org/docs/current/mod/mod_ssl.html>`__.
122
123 Here are the main options used by LL::NG:
124
125 - **SSLVerifyClient**: set to ``optional`` to allow user with a bad
126 certificate to access to LL::NG portal page. To switch to another
127 authentication backend, use the :doc:`Multi<authmulti>` module, for
128 example: ``Multi SSL;LDAP``
129 - **SSLOptions**: set to ``+StdEnvVars`` to get certificate fields in
130 environment variables
131 - **SSLUserName** (optional): certificate field that will be used to
132 identify user in LL::NG portal virtual host
133
134 With Nginx
135 ~~~~~~~~~~
136
137 Enable SSL:
138
139 .. code-block:: nginx
140
141 ssl on;
142 ssl_verify_client optional;
143 ssl_certificate /etc/letsencrypt/live/my/fullchain.pem;
144 ssl_certificate_key /etc/letsencrypt/live/my/privkey.pem;
145 ssl_verify_depth 3;
146 # All CA certificates concatenated in a single file
147 ssl_client_certificate /etc/nginx/ssl/ca.pem;
148 ssl_crl /etc/nginx/ssl/crl/my.crl;
149
150 # Reset SSL connection. User does not have to close his browser to try connecting again
151 keepalive_timeout 0 0;
152 add_header 'Connection' 'close';
153 ssl_session_timeout 1s;
154
155 You must also export SSL_CLIENT_S_DN_CN in FastCGI params:
156
157 .. code-block:: nginx
158
159 # map directive must be set in http context
160 map $ssl_client_s_dn $ssl_client_s_dn_cn {
161 default "";
162 ~/CN=(?<CN>[^/]+) $CN; # prior Nginx 1.11.6
163 #~,CN=(?<CN>[^,]+) $CN; # Nginx >= 1.11.6
164 }
165 fastcgi_param SSL_CLIENT_S_DN_CN $ssl_client_s_dn_cn;
166
167 Nginx SSL Virtual Host example with uWSGI
168 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
169
170 .. code-block:: nginx
171
172 server {
173 listen 443;
174 server_name authssl.example.com;
175 root /usr/share/lemonldap-ng/portal/htdocs/;
176 # Use "lm_app" format to get username in nginx.log (see nginx-lmlog.conf)
177 access_log /var/log/nginx/access.log lm_app;
178
179 ssl_verify_client on;
180 ssl_verify_depth 3;
181
182 # Full chain CRL is required
183 # All CRLs must be concatenated in a single .pem format file
184 ssl_crl /etc/nginx/ssl/crl/crls.pem;
185 if ($uri !~ ^/((static|javascript|favicon).*|.*\.psgi)) {
186 rewrite ^/(.*)$ /index.psgi/$1 break;
187 }
188
189 location ~ ^(?<sc>/.*\.psgi)(?:$|/) {
190 # uWSGI Configuration
191 include /etc/nginx/uwsgi_params;
192 uwsgi_pass 127.0.0.1:5000;
193 uwsgi_param LLTYPE psgi;
194 uwsgi_param SCRIPT_FILENAME $document_root$sc;
195 uwsgi_param SCRIPT_NAME $sc;
196 uwsgi_param SSL_CLIENT_S_DN_CN $ssl_client_s_dn_cn;
197 }
198
199 #index index.psgi;
200 location / {
201 try_files $uri $uri/ =404;
202 }
203 }
204
205
206 .. attention::
207
208 Nginx 1.11.6 change: format of the $ssl_client_s_dn and
209 $ssl_client_i_dn variables has been changed to follow RFC 2253 (RFC
210 4514); values in the old format are available in the
211 $ssl_client_s_dn_legacy and $ssl_client_i_dn_legacy variables.
212
213 Configuration of LemonLDAP::NG
214 ------------------------------
215
216 Using mTLS as an alternative authentication method
217 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
218
219 If you enable this feature, you must configure 2 portal virtual hosts:
220
221 - the main *(which corresponds to portal URL)* with
222 ``SSLVerifyClient none``
223
224 - the second (eg. `mtls.example.com`) with ``SSLVerifyClient optional`` (``ssl_verify_client optional`` with Nginx)
225
226 Configure your :doc:`Choice <authchoice>` module, then in `SSL Options`, set
227
228 * `Ajax mTLS URL` to https://mtls.example.com/authssl
229
230 Finally, in `General Parameters` > `Advanced Parameters` > `Security` > `Content Security Policy`,
231
232 add ``https://mtls.lemontest.lxd`` to `Ajax destinations`
233
234 .. note::
235
236 To avoid a bad/expired token during session upgrading (Reauthentication)
237 if URLs are served by different load balancers, you can force Upgrade
238 tokens to be stored into Global Storage by editing ``lemonldap-ng.ini``
239 in section [portal]:
240
241 .. code:: ini
242
243 [portal]
244 forceGlobalStorageUpgradeOTT = 1
245
246
247 Configuring LemonLDAP::NG with mTLS authentication only
248 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
249
250 In Manager, go in ``General Parameters`` > ``Authentication modules``
251 and choose mTLS for authentication.
252
253
254 .. tip::
255
256 You can then choose any other module for users and
257 password.
258
259 Then, go in ``mTLS parameters``:
260
261 - **Authentication level**: authentication level for this module
262 - **Extracted certificate field**: field of the certificate affected to
263 $user internal variable
264
265 Extracting the username attribute
266 ---------------------------------
267
268 The `Extracted certificate field` must be set to the Apache/Nginx
269 environment variable containing the username attribute.
270
271 See the `mod_ssl
272 documentation <https://httpd.apache.org/docs/current/en/mod/mod_ssl.html>`__
273 for a list of supported variables names.
274
275 If your webserver configuration allows multiple CAs, you may configure a
276 different environment variable for each CA.
277
278 In the `Conditional extracted certificate field`, add a line for each
279 CA.
280
281 - key: the CA subject DN (will be printed in debug logs)
282 - value: the variable containing the username when using certificates
283 emitted by this CA
284
285 You can use the `Issuer environment variable` setting to change which variable
286 the CA subject DN is extracted from
287
288 Optional topics
289 -----------------
290
291 Auto reloading SSL Certificates
292 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
293
294 A known problematic is that many browser (Firefox, Chrome) remembers the
295 fact that the certificate is not available at a certain time. It is
296 particularly important for smart cards: when the card is not inserted
297 before the browser starts, the user must restart his browser, or at
298 least refresh (F5) the page.
299
300 Apache server
301 ^^^^^^^^^^^^^
302
303 It is possible with Ajax code and 3 Apache locations to bypass this
304 limitation.
305
306 1. Modify the portal virtual host to match this example:
307
308 .. code-block:: apache
309
310 SSLEngine On
311 SSLCACertificateFile /etc/apache2/ssl/ca.crt
312 SSLCertificateKeyFile /etc/apache2/ssl/lemonldap.key
313 SSLCertificateFile /etc/apache2/ssl/lemonldap.crt
314
315 SSLVerifyDepth 10
316 SSLOptions +StdEnvVars
317 SSLUserName SSL_CLIENT_S_DN_CN
318
319 # DocumentRoot
320 DocumentRoot /var/lib/lemonldap-ng/portal/
321 <Directory /var/lib/lemonldap-ng/portal/>
322 Order Deny,Allow
323 Allow from all
324 Options +ExecCGI +FollowSymLinks
325 SSLVerifyClient none
326 </Directory>
327
328 <Location /index>
329 Order Deny,Allow
330 Allow from all
331 SSLVerifyClient none
332 </Location>
333
334 <Location /testssl>
335 Order Deny,Allow
336 Allow from all
337 SSLVerifyClient require
338 </Location>
339
340 Alias /sslok /var/lib/lemonldap-ng/portal
341 <Location /sslok>
342 Order Deny,Allow
343 Allow from all
344 SSLVerifyClient require
345 </Location>
346
347 - /index/ is an unprotected page to display a SSL test button
348 - /testssl/ is a SSL protected page to check the certificate
349 - /sslok/ is the new LemonLDAP::NG portal. You need to declare the new
350 url in the manager: Portal -> URL: https://auth.example.com/sslok/
351
352 2. Then you need to construct the Ajax page, for example in
353 /index/bouton.html. It looks like this:
354
355 .. code-block:: html
356
357 <body>
358 <script src="./jquery-2.1.4.min.js" type="text/javascript"> </script>
359 <!--<script src="./jquery-ui-1.8-rass.js" type="text/javascript"> </script>-->
360
361
362 <a href="http://www.google.fr" class="enteteBouton" id="continuerButton"><img src=authent.png></a>
363 <script>
364 $('.enteteBouton').click( function (e) {
365 var b=navigator.userAgent.toLowerCase();
366 if(b.indexOf("msie")!==-1){
367 document.execCommand("ClearAuthenticationCache")
368 }
369 e.preventDefault();
370 $.ajax({
371 url:"https://auth.example.com/testssl",
372 beforeSend:function(){},
373 type:"GET",
374 dataType:"html",
375 success:function(c,a){
376 if (c !== "") {
377 alert("Carte OK");
378 window.location.href = "https://auth.example.com/sslok/";
379 }
380 else {
381 alert('Carte KO');
382 }
383 },
384 error:function (xhr, ajaxOptions, thrownError){
385 if(xhr.status==404) {
386 alert("Carte OK");
387 window.location.href = "https://auth.example.com/sslok/";
388 }
389 else {
390 alert('Carte KO');
391 }
392 },
393 complete:function(c,a){}
394 });
395 });
396 </script>
397 </body>
398
399 Nginx server
400 ^^^^^^^^^^^^
401
402 With Nginx, append those server context directives to force SSL
403 connexion reset:
404
405 .. code-block:: nginx
406
407 keepalive_timeout 0 0;
408 add_header 'Connection' 'close';
409 ssl_session_timeout 1s;