Debian Codegraph @

doc/sources/admin/security.rst

raw
1 Security recommendation
2 =======================
3
4 Secure configuration access
5 ---------------------------
6
7 Configuration can be stored in several formats
8 (:doc:`SQL<sqlconfbackend>`, :doc:`File<fileconfbackend>`,
9 :doc:`LDAP<ldapconfbackend>`) but must be shared over the network if you
10 use more than 1 server. If some of your servers are not in the same
11 (secured) network than the database, it is recommended to use
12 :doc:`SOAP access<soapconfbackend>` for those servers.
13
14
15 .. tip::
16
17 You can use different type of access:
18 :doc:`SQL<sqlconfbackend>`, :doc:`File<fileconfbackend>` or
19 :doc:`LDAP<ldapconfbackend>` for servers in secured network and
20 :doc:`SOAP<soapconfbackend>` for remote servers.
21
22 Next, you have to configure the SOAP access as described
23 :ref:`here<soapconfbackend-next-configure-soap-for-your-remote-servers>`
24 since SOAP access is denied by default.
25
26 Protect the Manager
27 -------------------
28
29 By default, the manager is restricted to the user 'dwho' (default
30 backend is Demo). To protect the manager, you have to choose one or both
31 of :
32
33 - protect the manager by Apache configuration
34 - protect the manager by LL::NG
35
36 Protect the Manager by the web server
37 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
38
39 You can use any of the mechanisms proposed by Apache: SSL, Auth-Basic,
40 Kerberos,... Example
41
42 .. code-block:: apache
43
44 <VirtualHost *:443>
45 ServerName manager.example.com
46 # SSL parameters
47 ...
48 # DocumentRoot
49 DocumentRoot /var/lib/lemonldap-ng/manager/
50 <Location />
51 AuthType Basic
52 AuthName "Lemonldap::NG manager"
53 AuthUserFile /usr/local/apache/passwd/passwords
54 Require user rbowen
55 Order allow,deny
56 Deny from all
57 Allow from 192.168.142.0/24
58 Options +ExecCGI
59 </Location>
60 </VirtualHost>
61
62 Protect the Manager by LL::NG
63 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
64
65 To protect the manager by LL::NG, you just have to set this in
66 ``lemonldap-ng.ini`` configuration file (section [manager]):
67
68 .. code-block:: ini
69
70 [manager]
71 protection = manager
72
73
74 .. attention::
75
76 Before, you have to create the virtual host
77 ``manager.your.domain`` in the manager and set a
78 :ref:`rule<rules>`, else access to the manager will
79 be denied.
80
81
82 .. _security-portal:
83
84 Portal
85 ------
86
87 LLNG portal now embeds the following features:
88
89 - `CSRF <https://en.wikipedia.org/wiki/Cross-site_request_forgery>`__
90 protection *(Cross-Site Request Forgery)*: a token is built for each
91 form. To disable it, set '​require Token for forms' ​to Off *(portal
92 security parameters in the manager)*. Token timeout can be defined
93 via manager (default to 120 seconds)
94 - `Brute-force
95 attack <https://en.wikipedia.org/wiki/Brute-force_attack>`__
96 protection: after some failed logins, user must wait before re-try to
97 log into Portal
98 - `Content-Security-Policy <https://en.wikipedia.org/wiki/Content_Security_Policy>`__
99 header: portal builds dynamically this header. You can modify default
100 values in the manager *(General parameters » Advanced parameters »
101 Security » Content-Security-Policy)*
102 - `Cross-Origin Resource
103 Sharing <https://en.wikipedia.org/wiki/Cross-origin_resource_sharing>`__
104 headers: CORS is a mechanism that allows restricted resources on a
105 web page to be requested from another domain outside the domain from
106 which the first resource was served. A web page may freely embed
107 cross-origin images, stylesheets, scripts, iframes, and videos.
108 Certain "cross-domain" requests, notably Ajax requests, are forbidden
109 by default by the same-origin security policy. You can modify default
110 values in the manager *(General parameters » Advanced parameters »
111 Security » Cross-Origin Resource Sharing)*
112 - IP filtering: LemonLDAP::NG can use a `CrowdSec server
113 <https://www.crowdsec.net/>`__ to filter connexion using IP reputation
114 from CrowdSec. See :doc:`CrowdSec Bouncer<crowdsec>`
115
116
117 .. attention::
118
119
120
121 - Brute-force attack protection is DISABLED by default
122 - Browser implementations of formAction directive are inconsistent
123 (e.g. Firefox doesn't block the redirects whereas Chrome does).
124 Administrators may have to modify formAction value with wildcard
125 likes ``*``.
126
127
128
129 Split portal when using SOAP/REST
130 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
131
132 If you use :doc:`SOAP<soapsessionbackend>` or
133 :doc:`REST<restsessionbackend>` session backend, dedicate a portal
134 especially for these internal requests.
135
136 .. _security-write-good-rules:
137
138 Write good rules
139 ----------------
140
141 Order your rules
142 ~~~~~~~~~~~~~~~~
143
144 :ref:`Rules<rules>` are applied in alphabetical order
145 (comment and regular expression). The first matching rule is applied.
146
147
148 .. attention::
149
150 The "default" rule is only applied if no other rule
151 matchs
152
153 The Manager let you define comments in rules, to order them:
154
155 |image0|
156
157 For example, if these rules are used without comments:
158
159 ================== ============== =======
160 Regular expression Rule Comment
161 ================== ============== =======
162 ^/pub/admin/ $uid eq "root"
163 ^/pub/ accept
164 ================== ============== =======
165
166 Then the second rule will be applied first, so every authenticated user
167 will access to ``/pub/admin`` directory.
168
169 Use comment to correct this:
170
171 ================== ============== =======
172 Regular expression Rule Comment
173 ================== ============== =======
174 ^/pub/admin/ $uid eq "root" 1_admin
175 ^/pub/ accept 2_pub
176 ================== ============== =======
177
178
179 .. tip::
180
181
182
183 - Reload the Manager to see the effective order
184 - Use rule comments to order your rules
185
186
187
188 Be careful with URL parameters
189 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
190
191 You can write :ref:`rules<rules>` matching any
192 component of URL to protect including GET parameters, but be careful.
193
194 For example with this rule on the ``access`` parameter:
195
196 =============================== ========================== =======
197 Regular expression Rule Comment
198 =============================== ========================== =======
199 ``^/index.php\?.*access=admin`` ``$groups =~ /\badmin\b/``
200 ``default`` ``accept``
201 =============================== ========================== =======
202
203 Then a user that try to access to one of the following will be granted !
204
205 - ``/index.php?access=admin&access=other``
206 - ``/index.php?Access=admin``
207
208 You can use the following rules instead:
209
210 ===================================== ========================== =======
211 Regular expression Rule Comment
212 ===================================== ========================== =======
213 ``^/(?i)index.php\?.*access.*access`` ``deny`` 0_bad
214 ``^/(?i)index.php\?.*access=admin`` ``$groups =~ /\badmin\b/`` 1_admin
215 ``default`` ``accept``
216 ===================================== ========================== =======
217
218
219 .. tip::
220
221 **(?i)** means case no sensitive.
222
223
224 .. danger::
225
226 Remember that rules written on GET parameters must be
227 tested.
228
229 Encoded characters
230 ~~~~~~~~~~~~~~~~~~
231
232 Some characters are encoded in URLs by the browser (such as space,...).
233 To avoid problems, LL::NG decode them using
234 https://metacpan.org/pod/Apache2::URI#unescape_url. So write your rules
235 using normal characters.
236
237 IP in rules
238 ~~~~~~~~~~~
239
240
241 .. danger::
242
243 If you are running LemonLDAP::NG behind a reverse proxy,
244 make sure you check the
245 :doc:`Reverse Proxy how-to<behindproxyminihowto>` so that the rule
246 applies to the real user IP and not the reverse proxy's IP. Make sure
247 you only specify trusted proxy addresses so that an attacker cannot
248 forge the ``X-Forwarded-For`` header
249
250 .. _security-reverseproxies:
251
252 Secure reverse-proxies
253 ----------------------
254
255 LL::NG can protect any Apache hosted application including Apache
256 reverse-proxy mechanism. Example:
257
258 .. code-block:: apache
259
260 PerlOptions +GlobalRequest
261 PerlRequire /var/lib/lemonldap-ng/handler/MyHandler.pm
262 <VirtualHost *:443>
263 SSLEngine On
264 ... other SSL parameters ...
265 PerlInitHandler My::Handler
266 ServerName appl1.example.com
267 ProxyPass / http://hiddenappl1.example.com/
268 ProxyPassReverse / http://hiddenappl1.example.com/
269 ProxyPassReverseCookieDomain / http://hiddenappl1.example.com/
270 </VirtualHost>
271
272 See `mod_proxy <http://httpd.apache.org/docs/2.2/mod/mod_proxy.html>`__
273 and
274 `mod_rewrite <http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html>`__
275 documentation for more about configuring Apache reverse-proxies.
276
277 Such configuration can have some security problems:
278
279 - if a user can access directly to the hidden application, it can
280 bypass LL::NG protection
281 - if many hidden applications are on the same private network, if one
282 is corrupted (by SQL injection, or another attack), the hacker will
283 be able to access to other applications without using reverse-proxies
284 so it can bypass LL::NG protection
285
286 It is recommended to secure the channel between reverse-proxies and
287 application to be sure that only request coming from the LL::NG
288 protected reverse-proxies are allowed. You can use one or a combination
289 of:
290
291 - firewalls (but be careful if more than 1 server is behind the
292 firewall)
293 - server based restriction (like Apache "allow/deny" mechanism)
294 - SSL client certificate for the reverse-proxy (see SSLProxy\*
295 parameters in `mod_ssl
296 documentation <http://httpd.apache.org/docs/2.2/mod/mod_ssl.html>`__)
297
298 .. _security-configure-security-settings:
299
300 Configure security settings
301 ---------------------------
302
303 Go in Manager, ``General parameters`` » ``Advanced parameters`` »
304 ``Security``:
305
306 - **Username control**: Regular expression used to check user login
307 syntax.
308 - **Avoid browsers to store users password**: Enable this option to
309 prevent browsers from prompting users to save passwords.
310 - **Force authentication**: Set to 'On' to force authentication when
311 user connects to portal, even if he has a valid session.
312 - **Force authentication interval**: Time interval (in seconds) when an
313 authentication renewal cannot be forced, used to prevent to loose the
314 current authentication during the main process. If you experience
315 slow network performances, you can increase this value.
316 - **Default required authentication level**: If set, this required authentication
317 level is used for all protected applications (VHosts, CAS, SAML or OIDC)
318 - **Encryption key**: Key used for crypting some data, should not be known
319 by other applications
320 - **Trusted domains**: Domains on which the user can be redirected
321 after login on portal.
322
323 - Example: ``myapp.example.com .subdomain.example.com``
324 - ``*`` allows redirections to any external domain (DANGEROUS)
325
326 - **Use Safe jail**: Set to 'Off' to disable Safe jail. Safe module is
327 used to eval expressions in headers, rules, etc. Disabling it can lead to security issues.
328 Value can be overriden by using ``lemonldap-ng.ini`` file.
329 - **Avoid assignment in expressions**: Set to 'Off' to disable syntax checking.
330 Equal sign can be replaced by \x3D i.e. "dc\x3Dorg"
331 - **Check XSS Attacks**: Set to 'Off' to disable XSS checks. XSS checks
332 will still be done with warning in logs, but this will not prevent
333 the process to continue.
334 - **Required token for forms**: To prevent CSRF attack, a token is
335 build for each form. To disable it, set this parameter to 'Off' or
336 set a special rule
337 - **Form timeout**: Form token timeout (default to 120 seconds)
338 - **Use global storage**: Local cache is used by default for one time
339 tokens. To use global storage, set it to 'On'
340 - **Strict-Transport-Security Max-age**: Set STS header max-age if you use SSL only (by example: 15768000)
341 - **Hashed session storage**: when set to "On", SSO sessions and OIDC tokens
342 are stored with a hashed name, then when parsing storage, nobody
343 can recover SSO session name or OIDC access_token. Not enabled by default
344 because it breaks exiting OIDC offline sessions.
345 **Incompatible with "Proxy" authentication in SOAP mode**.
346 - **Short Token TTL**: time-to-live in seconds for machine-to-machine tokens
347 such as back-channel-logout requests. Default 30 seconds.
348 - **CrowdSec**: See :doc:`CrowdSec Bouncer plugin<crowdsec>`
349 - **Check HIBP API**: Set to 'On' to enable :doc:`Check HIBP API plugin<checkhibp>`
350 - **Check password entropy**: Set to 'On' to enable :doc:`Check password entropy plugin<checkentropy>`
351 - **New location warning**: Set to 'On' to enable :doc:`New location warning plugin<newlocationwarning>`
352 - **Brute-Force Attack protection**: Set to 'On' to enable :doc:`Brute-force protection plugin<bruteforceprotection>`
353 - **LWP::UserAgent and SSL options**: Insert here options to pass to
354 LWP::UserAgent object (used by SAML or OpenID-Connect to query
355 partners and AuthSSL or AuthBasic handler to request Portal URL).
356 Example: ``verify_hostname => 0``, ``SSL_verify_mode => 0``
357 - **Content Security Policy**: Portal builds dynamically this header.
358 You can modify default values. Browser implementations of formAction
359 directive are inconsistent (e.g. Firefox doesn't block the redirects
360 whereas Chrome does). Administrators may have to modify
361 ``formAction`` value with wildcard likes \*.
362 - **Cross-Origin Resource Sharing**: Portal builds those headers. You
363 can modify default values. Administrators may have to modify
364 ``Access-Control-Allow-Origin`` value with ' '.
365
366
367 .. attention::
368
369 If URLs are protected with AuthBasic handler, you have
370 to disable CSRF token by setting a special rule based on callers IP
371 address like this :
372
373 requireToken => $env->{REMOTE_ADDR} && $env->{REMOTE_ADDR} !~ /^127\.0\.[1-3]\.1$/
374
375 .. danger::
376
377 Enable global storage for one time tokens will downgrade
378 Portal performance!!!
379
380 Must ONLY be used with outdated or low performance Load Balancer.
381
382 Fail2ban
383 --------
384
385 To prevent brute force attack with fail2ban
386
387 Edit /etc/fail2ban/jail.conf
388
389 ::
390
391 [lemonldap-ng]
392 enabled = true
393 port = http,https
394 filter = lemonldap
395 action = iptables-multiport[name=lemonldap, port="http,https"]
396 logpath = /var/log/apache*/error*.log
397 maxretry = 3
398
399 and edit /etc/fail2ban/filter.d/lemonldap.conf
400
401 ::
402
403 # Fail2Ban configuration file
404 #
405 # Author: Adrien Beudin
406 #
407 # $Revision: 2 $
408 #
409
410 [Definition]
411
412 # Option: failregex
413 # Notes.: regex to match the password failure messages in the logfile. The
414 # host must be matched by a group named "host". The tag "<HOST>" can
415 # be used for standard IP/hostname matching and is only an alias for
416 # (?f{4,6}:)?(?P<host>[\w\-.^_]+)
417 # Values: TEXT
418 #
419 failregex = Lemonldap\:\:NG \: .* was not found in LDAP directory \(<HOST>\)
420 Lemonldap\:\:NG \: Bad password for .* \(<HOST>\)
421
422 # Option: ignoreregex
423 # Notes.: regex to ignore. If this regex matches, the line is ignored.
424 # Values: TEXT
425 #
426 ignoreregex =
427
428 Restart fail2ban
429
430 Sessions identifier
431 -------------------
432
433 You can change the module used for sessions identifier generation. To
434 do, add ``generateModule`` key in the configured session backend
435 options.
436
437 We recommend to use :
438 ``Lemonldap::NG::Common::Apache::Session::Generate::SHA256``.
439
440 SAML
441 ----
442
443 See
444 :ref:`samlservice#security_parameters<samlservice-security-parameters>`
445
446 .. |image0| image:: /documentation/manager-rule.png
447 :class: align-center
448
449 OIDC
450 ----
451
452 See
453 :ref:`openidconnectservice#security<openidconnectservice-security-parameters>`
454
455 OIDC Security Guidelines
456 ~~~~~~~~~~~~~~~~~~~~~~~~
457
458 See :doc:`OpenID Connect Security<oidc-security>` for comprehensive security recommendations including:
459
460 * RFC 9700 (OAuth 2.0 Security Best Current Practice)
461 * RFC 9207 (Authorization Server Issuer Identification)
462 * RFC 7636 (PKCE)
463 * ANSSI security guidelines