Debian Codegraph @

doc/sources/admin/oidc-security.rst

raw
1 OpenID Connect Security
2 =======================
3
4 This document provides a comprehensive overview of OpenID Connect and OAuth 2.0 security options in LemonLDAP::NG.
5
6 .. contents::
7 :local:
8 :depth: 2
9
10 Supported Security Specifications
11 ---------------------------------
12
13 LemonLDAP::NG implements security recommendations from:
14
15 * **OpenID Connect Core 1.0** - Authentication and security requirements
16 * **OpenID Connect Back-Channel Logout 1.0**
17 * **RFC 7636** - Proof Key for Code Exchange (PKCE)
18 * **RFC 7662** - OAuth 2.0 Token Introspection
19 * **RFC 9068** - JWT Profile for OAuth 2.0 Access Tokens
20 * **RFC 9701** - JWT Response for OAuth 2.0 Token Introspection
21 * **RFC 9207** - OAuth 2.0 Authorization Server Issuer Identification
22 * **RFC 9700** - OAuth 2.0 Security Best Current Practice
23 * **ANSSI Guidelines** and **France-Connect+ compliance** - French National Cybersecurity Agency recommendations
24
25 - RFC 6749 (OAuth 2.0 - authorization code flow, state parameter)
26 - RFC 6750 (Bearer Token Usage)
27 - RFC 7515/7516 (JWS/JWE signatures and encryption)
28 - RFC 7518 (JSON Web Algorithms)
29
30 Quick Reference
31 ---------------
32
33 .. csv-table:: Security Options by Role
34 :header: "Feature", "Specification", "OP Config", "RP Config"
35 :widths: 25, 15, 30, 30
36
37 "PKCE", "RFC 7636", "Require PKCE (per RP)", "PKCE required (per OP)"
38 "Issuer verification (Since 2.23.0)", "RFC 9207", "Always enabled (auto)", "Issuer required"
39 "State parameter", "RFC 6749", "Require state (2.19.0)", "Always sent (auto)"
40 "Nonce parameter", "OIDC Core", "Require nonce (2.19.0)", "Use nonce"
41 "JWS signatures", "RFC 7515", "ID Token signature alg", "Check JWT signature"
42 "JWE encryption (2.19.0 FC+)", "RFC 7516", "Encryption algorithms", "N/A"
43 "Hashed tokens", "ANSSI R21/R25", "Hashed session storage", "N/A"
44 "Token endpoint auth", "RFC 6749", "Token endpoint auth method", "Token endpoint auth method"
45 "Request objects", "OIDC Core", "Require JWS for auth requests", "Auth method for code request"
46
47
48 OP Security Configuration
49 -------------------------
50
51 This section covers all security options to configure when LemonLDAP::NG acts as an OpenID Connect Provider.
52
53 Flows
54 ~~~~~
55
56 **RFC 9700 Recommendation**: Use the Authorization Code flow instead of Implicit or Hybrid flows.
57
58 **Configuration**: ``OpenID Connect Service`` > ``Security``:
59
60 - Disable ``Allow Implicit Grant``
61 - Disable ``Allow Hybrid Grant``
62 - Enable only ``Allow Authorization Code Grant`` (default)
63
64 PKCE
65 ~~~~
66
67 Proof Key for Code Exchange (RFC 7636) prevents authorization code interception attacks.
68
69 **Configuration** (per Relying Party): ``OpenID Connect Relying Parties`` > *RP name* > ``Options`` > ``Security``:
70
71 - **Require PKCE**: Set to ``On`` to require code_challenge at token endpoint
72
73 .. tip::
74
75 For public clients (mobile apps, SPAs), PKCE is essential. Enable it for all clients when possible.
76
77 State and Nonce
78 ~~~~~~~~~~~~~~~
79
80 The **state** parameter is generated by the RP (client) and sent in the authorization request. The OP returns it unchanged in the authorization response. The RP then verifies that it matches the original value stored in the user's session. This prevents CSRF attacks by ensuring the response corresponds to a request initiated by the user.
81
82 The **nonce** parameter is also generated by the RP and sent in the authorization request. The OP includes it in the ID Token it issues. The RP verifies that the nonce in the ID Token matches the one it sent. This prevents replay attacks by ensuring each ID Token is bound to a specific authorization request.
83
84 As an OP, you can require that RPs include these parameters in their authorization requests.
85
86 .. versionadded:: 2.19.0
87
88 **Configuration** (per Relying Party): ``OpenID Connect Relying Parties`` > *RP name* > ``Options`` > ``Security``:
89
90 - **Require "state" in authorization request**: Reject requests without state (ANSSI R12)
91 - **Require "nonce" in authorization request**: Reject requests without nonce (ANSSI R16)
92
93 Redirect URI Validation
94 ~~~~~~~~~~~~~~~~~~~~~~~
95
96 **RFC 9700 Recommendation**: Use exact redirect URI matching, no wildcards.
97
98 **Configuration** (per Relying Party): ``OpenID Connect Relying Parties`` > *RP name* > ``Basic options``:
99
100 - **Allowed redirection addresses for login**: Space-separated list of exact URIs
101
102 Token Security
103 ~~~~~~~~~~~~~~
104
105 Token Endpoint Authentication
106 """""""""""""""""""""""""""""
107
108 **ANSSI R23 Recommendation**: Use asymmetric authentication (``private_key_jwt``) over symmetric methods.
109
110 **Configuration** (per Relying Party): ``OpenID Connect Relying Parties`` > *RP name* > ``Options`` > ``Security``:
111
112 - **Token endpoint authentication method**:
113
114 - ``client_secret_basic`` - HTTP Basic Auth (default)
115 - ``client_secret_post`` - Secret in POST body
116 - ``client_secret_jwt`` - HMAC-signed JWT
117 - ``private_key_jwt`` - Asymmetric signed JWT (recommended)
118
119 Hashed Token Storage
120 """"""""""""""""""""
121
122 Store tokens as hashes to prevent exposure in case of database compromise (ANSSI R21/R25).
123
124 **Configuration**: ``General Parameters`` > ``Advanced parameters`` > ``Security``:
125
126 - **Hashed session storage**: Set to ``On``
127
128 .. attention::
129
130 This breaks existing OIDC offline sessions and is incompatible with SOAP-mode Proxy authentication.
131 You can use the tool ``convertSessions`` to convert existing sessions.
132
133 Authorization Code Lifetime
134 """""""""""""""""""""""""""
135
136 **Configuration**: ``OpenID Connect Service`` > ``Timeouts`` > ``Authorization Codes`` (default: 60 seconds)
137
138 Access Token Lifetime and Refresh Tokens
139 """"""""""""""""""""""""""""""""""""""""
140
141 **ANSSI R33 Recommendation**: Limit access token validity to reduce exposure in case of token theft.
142
143 **Best practices**:
144
145 - Enable refresh tokens even for online sessions. This allows setting a short access token lifetime (e.g., 10 minutes) while maintaining user sessions through token refresh. If an access token is stolen, it will expire quickly.
146 - Enable refresh token rotation if the client supports it. A new refresh token is issued on each use, and the previous one is invalidated. This limits the impact of a stolen refresh token. This applies to both online and offline refresh tokens.
147
148 **Configuration** (per Relying Party): ``OpenID Connect Relying Parties`` > *RP name* > ``Options``:
149
150 - ``Advanced`` > **Use refresh tokens**
151 - ``Security`` > **Invalidate refresh tokens after use**
152
153 **Configuration**: ``OpenID Connect Service`` > ``Timeouts``:
154
155 - **Access Tokens**: Set to a short duration (e.g., 600 seconds / 10 minutes)
156 - **Refresh Tokens**: Set according to desired session duration
157
158 Algorithms
159 ~~~~~~~~~~
160
161 ID Token Signature
162 """"""""""""""""""
163
164 ID Tokens are signed by default using ``RS256``.
165
166 **Configuration** (per Relying Party): ``OpenID Connect Relying Parties`` > *RP name* > ``Options`` > ``Algorithms``:
167
168 - **ID Token signature algorithm**:
169
170 - **Avoid**: ``none``, ``HS256`` (HMAC-based)
171 - **Recommended**: ``RS256`` (default), ``RS384``, ``RS512``, ``ES256``, ``ES384``, ``ES512``, ``PS256``, ``PS384``, ``PS512``, ``EdDSA``
172
173 .. note::
174
175 Elliptic curve algorithms (ES*) added in 2.19.0 for `France-Connect+`_ compliance.
176
177 .. _France-Connect+: https://docs.partenaires.franceconnect.gouv.fr/fs/fs-technique/fs-technique-oidc-fc-plus/
178
179 JWT Encryption
180 """"""""""""""
181
182 .. versionadded:: 2.19.0
183 Added for `France-Connect+`_ compliance.
184
185 For sensitive data, encrypt tokens in addition to signing. Encryption can be applied to:
186
187 - **ID Token**: returned in token endpoint responses
188 - **UserInfo**: returned by the UserInfo endpoint
189 - **Access Token**: if using JWT format (RFC 9068)
190 - **Introspection response**: if using JWT format (RFC 9701, since 2.23.0)
191
192 .. attention::
193
194 The RP must expose its public encryption keys via its JWKS (JSON Web Key Set) endpoint for the OP to encrypt data.
195
196 **Configuration** (per Relying Party): ``OpenID Connect Relying Parties`` > *RP name* > ``Options`` > ``Algorithms``:
197
198 - **ID Token Encryption key management algorithm**
199 - **ID Token Encryption content encryption algorithm**
200 - **Access Token Encryption algorithms** (if JWT format)
201 - **UserInfo Encryption algorithms**
202 - **Introspection Encryption algorithms** (if JWT format, since 2.23.0)
203
204 Other Options
205 ~~~~~~~~~~~~~
206
207 Signed Authorization Requests (ANSSI R9)
208 """"""""""""""""""""""""""""""""""""""""
209
210 Authorization requests can be sent as signed JWTs (Request Objects) instead of plain query parameters. This prevents tampering with request parameters during redirection.
211
212 **Configuration** (per Relying Party): ``OpenID Connect Relying Parties`` > *RP name* > ``Options`` > ``Security``:
213
214 - **Require JWS for authorization requests**
215
216 Metadata Discovery (ANSSI R48)
217 """"""""""""""""""""""""""""""
218
219 The OpenID Connect discovery endpoint (``/.well-known/openid-configuration``) exposes OP configuration. In high-security environments, you may want to disable it to reduce information exposure.
220
221 **Configuration**: ``OpenID Connect Service`` > ``Security``:
222
223 - **Don't display metadata**
224
225 .. warning::
226
227 Disabling discovery is non-standard and may break applications that rely on automatic OP configuration. Only disable this if all your RPs support manual configuration.
228
229 Dynamic Registration (ANSSI R49)
230 """"""""""""""""""""""""""""""""
231
232 Dynamic client registration allows RPs to register automatically without administrator approval. This should be disabled in production environments to maintain control over authorized clients.
233
234 **Configuration**: ``OpenID Connect Service`` > ``Dynamic registration``:
235
236 - **Activation**: Off (default)
237
238 Secret Management (ANSSI R35-R37)
239 """""""""""""""""""""""""""""""""
240
241 Client secrets must be managed securely:
242
243 - Use cryptographically random secrets with good entropy (use ``pwgen -s 32`` or ``openssl rand -base64 32``)
244 - Use a unique secret per RP
245 - Plan regular secret rotation
246
247 Logging (ANSSI R32)
248 """""""""""""""""""
249
250 Access tokens should not appear in logs to prevent token theft from log files.
251
252 **Configuration**: Set log level to ``info`` or ``notice``. Tokens are only visible at ``debug`` level.
253
254
255 RP Security Configuration
256 -------------------------
257
258 This section covers all security options to configure when LemonLDAP::NG acts as an OpenID Connect Relying Party.
259
260 PKCE
261 ~~~~
262
263 Proof Key for Code Exchange (RFC 7636) prevents authorization code interception attacks by binding the authorization code to the client that requested it.
264
265 **Configuration** (per Provider): ``OpenID Connect Providers`` > *OP name* > ``Options`` > ``Configuration``:
266
267 - **PKCE required**: Set to ``On`` to always use PKCE in authorization requests
268
269 Issuer Verification (RFC 9207)
270 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
271
272 .. versionadded:: 2.23.0
273
274 RFC 9207 prevents mix-up attacks by including the ``iss`` parameter in authorization responses.
275
276 **Configuration** (per Provider): ``OpenID Connect Providers`` > *OP name* > ``Options`` > ``Configuration``:
277
278 - **Issuer required (RFC 9207)**: When enabled, the RP will:
279
280 - Verify the ``iss`` parameter matches the expected issuer (if present)
281 - Reject responses without ``iss`` (when required)
282
283 .. attention::
284
285 Enable this option when connecting to OPs that support RFC 9207 to protect against mix-up attacks.
286
287 Nonce
288 ~~~~~
289
290 The nonce prevents replay attacks (see `State and Nonce`_ for details).
291
292 **Configuration** (per Provider): ``OpenID Connect Providers`` > *OP name* > ``Options`` > ``Protocol``:
293
294 - **Use nonce**: On (default)
295
296 Token Security
297 ~~~~~~~~~~~~~~
298
299 **Configuration** (per Provider): ``OpenID Connect Providers`` > *OP name* > ``Options`` > ``Protocol``:
300
301 - **Token endpoint authentication method**: Use ``private_key_jwt`` (recommended)
302 - **Authentication method for authorization code request**: Prefer asymmetric algorithms
303 - **Signature algorithm for authorization code authentication**: Set explicit algorithm
304
305 JWT Verification
306 ~~~~~~~~~~~~~~~~
307
308 **Configuration** (per Provider): ``OpenID Connect Providers`` > *OP name* > ``Options`` > ``Protocol``:
309
310 - **Check JWT signature**: Set to ``On``
311
312
313 Built-in Security Features
314 --------------------------
315
316 These security features are automatically implemented without configuration:
317
318 .. csv-table::
319 :header: "Feature", "Description", "Reference"
320 :widths: 25, 50, 25
321
322 "State parameter (RP)", "Always sent in authorization requests", "RFC 6749, ANSSI R10"
323 "Secure random generation", "State, nonce, auth codes, tokens use cryptographic random", "ANSSI R11/R15/R18/R24"
324 "Domain verification", "Automatic domain name verification", "ANSSI R6"
325 "Session cookies", "SSO uses secure session cookies", "ANSSI R13"
326 "Open redirect protection", "URI validation prevents open redirects", "ANSSI R17"
327 "Authorization code binding", "Auth codes bound to OIDC client", "ANSSI R20"
328 "One-time auth codes", "Used auth codes are invalidated", "ANSSI R30"
329 "ID Token validation", "Integrity and claims verification", "ANSSI R26/R28"
330 "Authentication level", "ACR/AMR support for level verification", "ANSSI R29"
331 "Bearer token handling", "Access tokens via Authorization header", "ANSSI R31"
332 "Token timeouts", "Configurable validity limits", "ANSSI R33"
333 "UserInfo cross-check", "UserInfo validated against ID Token", "ANSSI R34"
334 "Event logging", "Important events logged", "ANSSI R47"
335 "Issuer parameter (OP)", "RFC 9207 ``iss`` always included in responses", "RFC 9207"
336
337
338 Compliance Reference
339 --------------------
340
341 ANSSI Guidelines
342 ~~~~~~~~~~~~~~~~
343
344 |anssi-logo|
345
346 .. |anssi-logo| image:: logos/240px-ANSSI_Logo.svg.png
347 :class: align-center
348 :scale: 50%
349
350 The `Agence Nationale de la Sécurité des Systèmes d'Information`_ (ANSSI) published `recommendations for securing OpenID Connect`_.
351
352 .. _Agence Nationale de la Sécurité des Systèmes d'Information: https://ssi.gouv.fr
353 .. _recommendations for securing OpenID Connect: https://cyber.gouv.fr/publications/recommandations-pour-la-securisation-de-la-mise-en-oeuvre-du-protocole-openid-connect
354
355 Compliance Matrix
356 """""""""""""""""
357
358 .. csv-table::
359 :header: "Category", "Recommendations", "LL::NG Implementation"
360 :widths: 20, 30, 50
361
362 "Flow Security", "R1", "Disable Implicit/Hybrid (configurable)"
363 "TLS/Crypto", "R3-R8", "HTTPS required, JWS algorithms configurable"
364 "Auth Request", "R9-R16", "State/nonce automatic (RP) or required (OP 2.19.0)"
365 "Auth Code", "R17-R22", "Automatic: random, bound, one-time, hashed (opt)"
366 "Token Security", "R23-R25", "Token endpoint auth methods, hashed storage (opt)"
367 "ID Token", "R26-R30", "Automatic validation and verification"
368 "Access Token", "R31-R34", "Automatic: header, timeouts, cross-check"
369 "Secrets", "R35-R41", "Per-RP secrets recommended"
370 "Algorithms", "R42-R44", "Configurable per RP, ES* since 2.19.0"
371 "Operations", "R45-R51", "Logging, discovery toggle, no dynamic reg"
372
373 Complete ANSSI Recommendations Reference
374 """"""""""""""""""""""""""""""""""""""""
375
376 Below is the complete list of ANSSI recommendations (in French, as in the original document):
377
378 * **R1** Utiliser en priorité la cinématique authorization code pour les applications Web
379 * **R2** Mettre en place une politique de sécurité
380 * **R3** Mettre en œuvre HTTPS
381 * **R4** Appliquer les recommandations de sécurité relatives à TLS
382 * **R5** Imposer aux clients OIDC des suites cryptographiques recommandées pour les communications serveur à serveur
383 * **R6** Vérifier le nom de domaine
384 * **R7** Utiliser le certificate pinning
385 * **R8** Utiliser un JWS protégé par un HMAC
386 * **R8+** Utiliser un JWS protégé par une signature
387 * **R9** Imposer un mode de transmission des paramètres dans une demande d'authentification
388 * **R10** Systématiser l'envoi du paramètre state
389 * **R11** Générer aléatoirement le paramètre state
390 * **R12** Détecter les demandes d'authentification sans le paramètre state
391 * **R13** Utiliser les cookies de session
392 * **R14** Systématiser l'envoi du paramètre nonce
393 * **R15** Générer aléatoirement le paramètre nonce
394 * **R16** Détecter les demandes d'authentification sans le paramètre nonce
395 * **R17** Se protéger contre les redirections ouvertes
396 * **R18** Générer aléatoirement les authorization code
397 * **R19** Limiter la durée de vie d'un authorization code
398 * **R20** Associer le code authorization code au client OIDC
399 * **R21** Stocker les authorization code sous forme d'empreinte
400 * **R22** Vérifier le paramètre state associé à la session de l'utilisateur
401 * **R23** Utiliser une authentification du client OIDC adaptée
402 * **R24** Générer aléatoirement les access token
403 * **R25** Stocker les access token sous formes d'empreintes
404 * **R26** Vérifier l'intégrité de l'ID Token
405 * **R27** Utiliser un secret partagé différent du client_secret pour générer le HMAC de l'ID Token
406 * **R28** Vérifier les informations d'un ID Token
407 * **R29** Vérifier le niveau d'authentification de l'utilisateur
408 * **R30** Rendre inutilisables les authorization code
409 * **R31** Transmettre les access token par l'entête Authorization
410 * **R32** Ne pas écrire dans les journaux les access token
411 * **R33** Restreindre la durée de validité d'un access token
412 * **R34** Croiser les informations du UserInfo et de l'ID Token
413 * **R35** Générer aléatoirement les secrets d'authentification partagés
414 * **R36** Renouveler les secrets d'authentification partagés
415 * **R37** Utiliser un secret différent par client OIDC
416 * **R38** Restreindre l'accès au secret d'authentification
417 * **R39** Utiliser des certificats pour authentifier les JWS
418 * **R40** Restreindre l'accès à la clé privée de signature
419 * **R41** Vérifier la révocation des certificats
420 * **R42** Utiliser des fonctions de hachage recommandées
421 * **R43** Utiliser des mécanismes de signature recommandés
422 * **R44** Fixer l'algorithme utilisé pour le JWS
423 * **R45** Sécuriser l'application Web OIDC
424 * **R46** Mettre en oeuvre un système de journalisation
425 * **R47** Journaliser les évènements importants
426 * **R48** Désactiver la découverte automatisée
427 * **R49** Ne pas utiliser l'enrôlement automatisé
428 * **R50** Sécuriser l'interface Web de configuration d'un client OIDC
429 * **R51** Vérifier l'identité des fournisseurs de service
430
431 France-Connect+
432 ~~~~~~~~~~~~~~~
433
434 .. versionadded:: 2.19.0
435
436 `France-Connect+`_ requires specific security options:
437
438 - **JWE encryption**: ID Token and UserInfo encryption support
439 - **Elliptic curve algorithms**: ES256, ES384, ES512 for signatures
440
441 RFC Coverage
442 ~~~~~~~~~~~~
443
444 RFC 9700 - Security Best Current Practice
445 """""""""""""""""""""""""""""""""""""""""
446
447 RFC 9700 (formerly draft-ietf-oauth-security-topics) defines best current practices for OAuth 2.0 security.
448
449 **Key recommendations implemented:**
450
451 - Authorization Code flow only (configurable)
452 - PKCE support (configurable per RP/OP)
453 - Exact redirect URI matching
454 - Secure token handling
455
456 RFC 9207 - Issuer Identification
457 """"""""""""""""""""""""""""""""
458
459 .. versionadded:: 2.23.0
460
461 - **OP**: ``iss`` parameter automatically included in all authorization responses
462 - **RP**: Configurable verification of ``iss`` parameter
463
464 RFC 7636 - PKCE
465 """""""""""""""
466
467 - **OP**: Require PKCE per RP
468 - **RP**: Enable PKCE per OP
469
470 RFC 9701 - JWT Response for Token Introspection
471 """""""""""""""""""""""""""""""""""""""""""""""
472
473 .. versionadded:: 2.23.0
474
475 RFC 9701 allows returning introspection responses as signed (and optionally encrypted) JWTs instead of plain JSON. This provides:
476
477 - **Integrity**: The response is signed, ensuring it hasn't been tampered with
478 - **Confidentiality**: Optional encryption protects sensitive token metadata
479 - **Non-repudiation**: The signature proves the response came from the authorization server
480
481 **Configuration** (per Relying Party): ``OpenID Connect Relying Parties`` > *RP name* > ``Options`` > ``Algorithms``:
482
483 - **Introspection response format**: Select signature algorithm (RS256, ES256, etc.)
484 - **Introspection Encryption key management algorithm**: Optional encryption
485 - **Introspection Encryption content encryption algorithm**: Encryption content algorithm
486
487
488 Security Checklists
489 -------------------
490
491 OP Security Checklist
492 ~~~~~~~~~~~~~~~~~~~~~
493
494 .. code-block:: text
495
496 [ ] Disable Implicit and Hybrid flows
497 [ ] Enable PKCE requirement for all RPs
498 [ ] Require state and nonce parameters
499 [ ] Use private_key_jwt for token endpoint authentication
500 [ ] Configure ID Token signature algorithm (RS256 or ES256)
501 [ ] Enable hashed session storage
502 [ ] Set appropriate token timeouts
503 [ ] Use unique secrets per RP
504 [ ] Disable dynamic registration (unless needed)
505 [ ] Configure appropriate log level
506 [ ] Protect Manager access
507 [ ] Use HTTPS only
508
509 RP Security Checklist
510 ~~~~~~~~~~~~~~~~~~~~~
511
512 .. code-block:: text
513
514 [ ] Enable PKCE
515 [ ] Enable Issuer verification (RFC 9207)
516 [ ] Enable nonce
517 [ ] Use private_key_jwt for token endpoint authentication
518 [ ] Enable JWT signature verification
519 [ ] Use appropriate ACR values
520 [ ] Configure proper redirect URIs
521 [ ] Use HTTPS only
522
523
524 See Also
525 --------
526
527 * :doc:`OpenID Connect Provider<idpopenidconnect>`
528 * :doc:`OpenID Connect Relying Party<authopenidconnect>`
529 * :doc:`OpenID Connect Service<openidconnectservice>`
530 * :doc:`Security recommendations<security>`
531 * :doc:`Keys management<keys>`