Debian Codegraph @

doc/sources/admin/authcombination.rst

raw
1 Combination of authentication schemes
2 =====================================
3
4 ============== ===== ==================
5 Authentication Users Password
6 ============== ===== ==================
7 ✔ ✔ ✔ (since *2.0.10*)
8 ============== ===== ==================
9
10 Presentation
11 ------------
12
13 This backend allows one to chain authentication methods, for example to
14 failback to LDAP authentication if Remote authentication failed…
15
16 Configuration
17 -------------
18
19 You have to use ``Combination`` as authentication module (users module
20 must be set to "Same"). Then go in ``Combination parameters`` to :
21
22 - declare the modules that will be used
23 - set the rule chain
24
25 Modules declaration
26 ~~~~~~~~~~~~~~~~~~~
27
28 Each module that will be used in combination rule must be declared. You
29 must set:
30
31 - the name used in the rule (a uniq string)
32 - the type (LDAP, DBI,...)
33 - the scope:
34
35 - authentication and user DB
36 - authentication only
37 - user DB only
38
39 - overloaded parameters: you can redefine any LLNG string parameters.
40 For example, if you use 2 different LDAP, the first can use normal
41 configuration and for the second, overwritten parameter can redefine
42 ldapServer or any existing parameter.
43
44
45 .. note::
46
47 To overload parameters, you must select a module, add a parameter
48 and set its value. For example:
49
50 ==== ==== ============ ===========================
51 Name Type Scope Parameters
52 ==== ==== ============ ===========================
53 DB1 DBI Auth only
54 DB2 DBI User DB only dbiAuthChain => "mysql:..."
55 ==== ==== ============ ===========================
56
57 Usually, you can't declare two modules of the same type if they don't
58 have the same parameters. For example, usually you can't declare a MySQL
59 DBI and a PostgreSQL DBI, because there is no extra field for PostgreSQL
60 parameters. Now with Combination, you can declare some overloaded
61 parameters.
62
63 For example, if DBI is configured to use PostgreSQL but DB2 is a MySQL
64 DB, you can override the "dbiChain" parameter.
65
66 The over parameter is a HASH ref where keys are attributes names and values are the overriden value.
67 To override a complex key like ldapExportedVars, you must use a JSON value, as the over parameter
68 expect string values:
69
70 .. code-block:: javascript
71
72 {"cn": "cn", "uid": "sAMAccounName", "mail": "mail"}
73
74
75 .. attention::
76
77 If your JSON is corrupted, LLNG will use it as string
78 and just report a warning in logs.
79
80 Rule chain
81 ~~~~~~~~~~
82
83 Combination allows:
84
85 - to chain schemes (example: ``[LDAP] and [DBI]``)
86 - to test different schemes (example: ``[LDAP] or [DBI]``)
87 - to mix schemes (example: ``[Kerberos,LDAP] or [LDAP,LDAP]``)
88 - to choose authentication scheme depending on some request values
89
90 Each scheme must be enclose in ``[]``. A comma separates auth and user
91 DB modules. If only one value is set, the same is used for both.
92
93 Boolean expression
94 ^^^^^^^^^^^^^^^^^^
95
96 Remember that schemes in rules are the names declared above.
97
98 ======================================= =============================================================================
99 Example Explanation
100 ======================================= =============================================================================
101 ``[myLDAP] or [myDBI]`` If myLDAP fails, use myDBI
102 ``[mySSL, myLDAP] or [myLDAP, myLDAP]`` Try mySSL for auth and myLDAP for userDB. If fails, switch to myLDAP for both
103 ``[myLDAP] or [myDBI1] or [myDBI2]`` Try myLDAP, then if it fails, myDBI1, then if it fails myDBI2
104 ``[mySSL and myLDAP, myLDAP ]`` Use mySSL and myLDAP to authentify, myLDAP to get user
105 ======================================= =============================================================================
106
107
108 .. attention::
109
110 Note that "or" can't be used inside a scheme. If you
111 think to "[mySSL or myLDAP, myLDAP]", you must write
112 ``[mySSL, myLDAP] or [myLDAP, myLDAP]``
113
114 ================================================== =========================================================
115 Example Explanation
116 ================================================== =========================================================
117 ``[myDBI1] and [myDBI2] or [myLDAP]`` Try myDBI1 and myDBI2, if it fails, try myLDAP
118 ``[myDBI1] and [myDBI2] or [myLDAP] and [myDBI2]`` Try myDBI1 and myDBI2, if it fails, try myLDAP and myDBI2
119 ================================================== =========================================================
120
121
122 .. attention::
123
124 You can't use brackets in a boolean expression and "and"
125 has precedence on "or".
126
127 If you think to "( [myLDAP] or [myDBI1] ) and [myDBI2]", you must write
128 ``[myLDAP] and [myDBI2] or [myDBI1] and [myDBI2]``
129
130 Tests
131 ^^^^^
132
133 Test can use only the ``$env`` variable. It contains the FastCGI
134 environment variables.
135
136 ======================================================================================================================= ==============================================================================
137 Example Explanation
138 ======================================================================================================================= ==============================================================================
139 ``if($env->{REMOTE_ADDR} =~ /^10\./) then [myLDAP] else [mySSL, myLDAP]`` If user doesn't come from 10.0.0.0/8 network, use SSL as authentication module
140 ``if($env->{REMOTE_ADDR} =~ /^10\./) then [myLDAP] else if($env->{REMOTE_ADDR} =~ /^192/) then [myDBI1] else [myDBI2]`` Chain tests
141 ======================================================================================================================= ==============================================================================
142
143
144 .. attention::
145
146 Note that brackets can't be used except to enclose test.
147
148 If you want to write ``if(...) then if...``, you must write
149 ``if(not ...) then ... else if(...)...``
150
151 Let's be crazy
152 ^^^^^^^^^^^^^^
153
154 The following rule is valid:
155
156 ``if($env->{REMOTE_ADDR} =~ /^192\./) then [mySSL, myLDAP] or [myLDAP] else [myLDAP and myDBI, myLDAP]``
157
158 Combine second factor
159 ~~~~~~~~~~~~~~~~~~~~~
160
161 Imagine you want to authenticate users either by SSL or LDAP+Webauthn, you
162 can't directly write this rule: this is done in 2 steps:
163
164 - use this combination rule: ``[SSL,LDAP] or [LDAP]``
165 - enable Webauthn with this rule: ``$_auth eq "LDAP"`` or
166 ``$authenticationLevel < 4`` *(and adapt Webauthn authentication level)*
167
168 Now if you want to authenticate users either by LDAP or LDAP+Webauthn *(to
169 have 2 different authentication level)*, 2 possibilities:
170
171 - configure 2 portals and overwrite Webauthn activation in the second
172 - Modify login template to propose the choice *(add a "submit" button
173 that points to the second portal)*
174
175 Display multiple forms
176 ~~~~~~~~~~~~~~~~~~~~~~
177
178 Combination module returns the form corresponding to the first
179 authentication scheme available for the current request. You can force
180 it to display the forms chosen using ``combinationForms`` in
181 lemonldap-ng.ini. Example:
182
183 ::
184
185 [portal]
186 combinationForms = standardform, openidform
187
188
189 Password management
190 -------------------
191
192 .. versionadded:: 2.0.10
193
194 Not all configurations of the Combination module allow password management.
195
196 If your combination looks like this ::
197
198 [Kerberos, LDAP] or [LDAP]
199
200 Then you can simply set ``LDAP`` as the password module, and password changes
201 and reset will work as expected.
202
203 If your combination looks like this ::
204
205 [LDAP1] or [LDAP2]
206
207 Then you can configure the ``Combination`` password module to automatically
208 send password changes to the LDAP server which was used during authentication.
209 This module also enables password reset.
210
211 .. note::
212
213 You can set the ``_cmbPasswordDB`` session variable to manually select which
214 backend will be called when changing the password. This is useful when using
215 SASL delegation
216
217 Limitations
218 ~~~~~~~~~~~
219
220 * When using password reset with a combination of 2 or more LDAP servers, you
221 need to make sure that there is no duplication of email addresses between all
222 your servers. If an email exists in more than one server, the password will
223 be reset on the first LDAP server that contains this email address
224 * Combinations using the ``and`` boolean expression will not cause passwords to
225 be changed in both backends for now
226 * Forcing the user to reset their password on next login is not currently
227 supported by the combination module
228
229 Known problems
230 --------------
231
232 Federation protocols
233 ~~~~~~~~~~~~~~~~~~~~
234
235 :doc:`SAML<authsaml>`, :doc:`OpenID-Connect<authopenidconnect>`,
236 :doc:`CAS<authcas>` or :doc:`old OpenID<authopenid>` can't be chained
237 with a "and" for authentication part. So "[SAML] and [LDAP]" isn't
238 valid. This is because their authentication kinematic don't use the same
239 steps.
240
241 ================================= =================================== ========================================================================
242 Bad expression Solution Explanation
243 ================================= =================================== ========================================================================
244 ``[SAML] and [LDAP]`` ``[SAML, SAML and LDAP]`` Authentication is done by SAML only but user must match an LDAP entry
245 ``[SAML] and [LDAP] or [LDAP]`` ``[SAML, SAML and LDAP] or [LDAP]`` Authentication is done by SAML or LDAP but user must match an LDAP entry
246 ================================= =================================== ========================================================================
247
248 Auth::Apache authentication
249 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
250
251 When using this module, LL::NG portal will be called only if Apache does
252 not return "401 Authentication required", but this is not the Apache
253 behaviour: if the auth module fails, Apache returns 401. So it can be
254 used only with a "and" boolean expression.
255
256
257 .. tip::
258
259 The new :doc:`Kerberos authentication module<authkerberos>`
260 solves this for Kerberos: you just have to use it instead of Apache and
261 enable authentication by Ajax in Kerberos parameters.
262
263 Example: ``[ Apache and LDAP, LDAP ]``
264
265 To bypass this, follow the documentation of
266 :doc:`AuthApache module<authapache>`
267
268 SSL authentication
269 ~~~~~~~~~~~~~~~~~~
270
271 To chain SSL, you have to set "SSLRequire optional" in Apache
272 configuration, else users will be authenticated by SSL only.
273
274 Migrating from Multi
275 --------------------
276
277 Old :doc:`Multiple backends stack<authmulti>` implemented only \`if\` and \`or\` keywords. Examples:
278
279 ======================================================================== =============================================================
280 Multi expressions Combination
281 ======================================================================== =============================================================
282 ``LDAP;DBI`` ``[myLDAP] or [myDBI]``
283 ``DBI $env->{REMOTE_ADDR} =~ /^192/;LDAP $env->{REMOTE_ADDR} !~ /^192/`` ``if $env->{REMOTE_ADDR} then [myDBI] else [myLDAP]``
284 ======================================================================== =============================================================