1
0
Fork 0
mirror of https://github.com/Kozea/Radicale.git synced 2025-09-30 21:12:05 +00:00
Commit graph

58 commits

Author SHA1 Message Date
Peter Marschall
44c64d70f5 LDAP auth: _login2: re-bind as user within same connection
Python's ldap module, which is modelled along OpenLDAP's API, allows us to
keep the connection and doing a new bind as a different user, superseding
the previous bind.
Use this to simplify the code and avoid duplication.
2025-09-29 20:15:33 +02:00
Peter Marschall
2d7a9b001c LDAP auth: support TLS & start_tls also with python-ldap
Until now, every connection to the LDAP server was silently unencryptedr
when using Python's ldap module instead of the ldap3 module.
I.e. using Python's ldap module was inherently insecure, as there was not
even a hint that the config settings for encryption were ignored.

This commit changes this and brings LDAP authentication based on the ldap
module feature-wise on par with the one based on the ldap3 module.
2025-09-29 20:15:33 +02:00
Peter Marschall
f8b15eb122 LDAP auth: get rid of helper property '_use_encryption'
Inferring 'ldap_security' in earlier commits, allows us to get rid of
the helper property '_use_encryption', streamlining the code.
2025-09-29 20:15:33 +02:00
Peter Marschall
b21549b998 LDAP auth: warn if 'ldap_ssl_ca_file' is set without LDAP encryption 2025-09-29 20:15:33 +02:00
Peter Marschall
73b77defe4 LDAP auth: warn on unset ldap_ssl_ca_file when certificate verification is wanted 2025-09-29 20:15:33 +02:00
Peter Marschall
c58eef4bac LDAP auth: infer 'ldap_security = tls' from the URL prefix: ldaps:// => LDAPS
LDAP URIs starting with the scheme 'ldaps' are - by definition - meant to use
LDAPS instead of plain LDAP: infer 'ldap_security' = "tls" if it is not set.
2025-09-29 20:15:33 +02:00
Peter Marschall
7eb0c66512 LDAP auth: refactor dealing with 'ldap_use_ssl'
* stop treating it as class property
* refactor to consolidate logic into one big 'if' statement
  (for easier removal when the config option gets removed in the future)
* make deprecation warning for 'ldap_use_ssl' more urgent
* raise error if conflicting settings 'ldap_security' = "starttls" and
  'ldap_use_ssl' = True are set together
* if not set, infer  'ldap_security' = "tls" from 'ldap_use_ssl' = True,
  logging  a warning for the admin to update the config
2025-09-29 20:15:33 +02:00
Peter Marschall
caab7d3712 LDAP auth: load SSL/TLS config unconditionally
Currently it is not used by _login2(), but it does not hurt to have it
available.
It is a preparation for supporting encrypted connections in _login2().
2025-09-29 20:15:33 +02:00
Peter Marschall
5f89d18df6 LDAP auth: move evaluation of quirk for Authentik where it belongs
The evaluation of the quirk for the Authentik LDAP server changes the behaviour
of Python's `ldap3` module, and that module only.
Evaluating the quirk in `__init__` which is used for both, `ldap` and `ldap3`
is thus wrong, and may lead to errors when this setting is used together with
the `ldap` module.

Signed-off-by: Peter Marschall <peter@adpm.de>
2025-09-25 18:09:43 +02:00
Peter Bieringer
63b160c2b0 move evaluation of quirk for Authentik where it belongs, superseeds https://github.com/Kozea/Radicale/pull/1877 2025-09-25 15:29:04 +02:00
Peter Marschall
9eb9556536 LDAP auth: decode UTF-8 byte sequences to strings only if necessary 2025-09-07 15:05:47 +02:00
Peter Marschall
cde4c5f2e8 LDAP auth: stop giving type hints for local list variables 2025-09-07 14:44:03 +02:00
Peter Marschall
9b216a9f24 LDAP auth: define fallback value for _use_encryption 2025-09-07 11:38:08 +02:00
Peter Marschall
5c4a0578b0 LDAP auth: fix _login2() by importing ldap.filter 2025-09-07 11:38:08 +02:00
Peter Marschall
5a183e3c2b LDAP auth: make flake8 happy
"fix" small lint to keep flake8 happy.
2025-09-07 11:38:08 +02:00
Peter Marschall
5f677fc77e LDAP auth: document all paramters at the top of the file 2025-09-07 11:38:08 +02:00
Peter Marschall
8821612fa8 LDAP auth: allow finding groups based on separate search
Instead of searching for the membership attribute on the user side
(usually AD: memberOf, Novell eDirectory: groupMembership) to determine
the groups the user loging on is a member of, allow performing a separate
search for the groups having the user as member and use the found groups' DNs.

The group search is performed in the context of 'ldap_reader_dn', after
the user DN has been found in the directory, but before the authentication
has been performed by doing an LDAP bind in the user's context.

Although this may - in the case of unsuccessful login attempts -
double the number of queries to the LDAP server, it has been done
this way to keep the number of LDAP contexts minimal.

Doing the group search in the context of the user logging on is no viable
option, because there are known implementations where regular users do not
have the necessary permissions to query the groups they are a member in.
2025-09-07 11:38:08 +02:00
Peter Marschall
be3d58c55d LDAP auth: protect LDAP search with a try: .. except clause
Make sure to catch exceptions when searching for the user in LDAP,
log as error and fail gracefully by declining login.
2025-07-20 17:59:31 +02:00
Dipl. Ing. Péter Varkoly
95b3944ade Do not read server info by bind to avoid needless network trafic. 2025-05-31 13:36:59 +02:00
gajus
b805393bd9 Standardize LDAP security configuration naming 2025-04-21 21:26:58 +02:00
gajus
1162a3a011 Add support for start_tls 2025-04-19 17:02:45 +02:00
Miles Liu
24138389ed
fix(auth/ldap): Extract user attribute from list in _login3
This commit modifies `_login3` to check if the attribute value is a
list and, if so, extracts the first element (`[0]`) as the login
identifier. If the value is not a list, it's used directly (fallback).
2025-04-17 14:02:40 +08:00
Peter Bieringer
6b83c409d4
Merge pull request #1742 from BastelBaus/patch-2
Update ldap.py
2025-03-26 05:50:28 +01:00
BastelBaus@gmail.com
5d5b12c124 fixed flake8 errors 2025-03-24 22:14:29 +01:00
BastelBaus
2439266d0e
Update ldap.py
Bugfix, user_entry['attributes'][self._ldap_user_attr] is already the string so user_entry['attributes'][self._ldap_user_attr][0] would give only the first character and not the full user attribute
2025-03-24 20:25:51 +01:00
BastelBaus
3af690fcb6
Update ldap.py 2025-03-24 20:13:38 +01:00
BastelBaus
98152062df
Update ldap.py 2025-03-24 20:11:40 +01:00
BastelBaus
bcbf0918a9
Update ldap.py 2025-03-24 20:10:53 +01:00
BastelBaus
7399286ec9
Update ldap.py
timestamp hack
2025-03-23 18:04:53 +01:00
Peter Marschall
d6c4e6487a LDAP auth: flexibilize parsing of 'ldap_groups_attribute'
Use helper methods from the LDAP modules to get individual elements
(like in our case the RDN value) out of attributes with DN syntax
in a standard compliant way instead fiddling around ourselves.

If these methods fail, fall back to using the whole attribute value,
which allows us to also use attributes with non-DN syntax for groups
and permissions.
2025-01-03 20:47:36 +01:00
Peter Marschall
f9dd3efc3a LDAP auth: remove config option 'ldap_load_groups'
The same effect can be achieved using the option 'ldap_groups_attribute' alone,
if it's default becomes unset instead of 'memberOf'

Benefit: one config option less to deal with.

While at it, also fix header level for 'ldap_user_attribute' in documentation.
2025-01-03 20:47:31 +01:00
Peter Marschall
6c1445d8db LDAP auth: introduce config option 'ldap_groups_attribute'
This attribute is supposed to hold the group membership information
if the config option 'ldap_load_groups' is True.
If not given, it defaults to 'memberOf' for Active Directory.

Introducing this options allows one to use radicale's LDAP auth with groups
even on LDAP servers that keep their group memberships in a different attribute
than 'memberOf', e.g. Novell eDirectory which uses 'groupMembership'.
2025-01-03 20:27:21 +01:00
Peter Marschall
1ca41e2128 LDAP auth: only ask for memberOf if ldap_load_groups = True
Ask for the 'memberOf' attribute to be returned in the user query only
if 'ldap_load_groups' is set to True.

This fixes the issue that currently LDAP authentication can only be used on
LDAP servers that know this non-standard (it's an Active Directory extension)
attribute.
Other LDAP servers either do not necessarily have the group memberships
stored in the user object (e.g. OpenLDAP), or use different attributes for
this purpose (e.g. Novell eDirectory uses 'groupMembership')
2025-01-03 14:34:51 +01:00
Peter Marschall
607b3af67b LDAP auth: calculate attributes to query in __init__()
Remove code duplication by factoring out the calculation of the
LDAP query attributes out of _login2() resp. _login3() into __init__().
2025-01-03 13:09:59 +01:00
Peter Marschall
99f5ec389d LDAP auth: indroduce config option 'ldap_user_attribute'
This option gives us
- flexible authentication options where the name used for logging on
  does not have to be the account name
  e.g. use ldap_filter = (&(obhjectclass=inetOrgperson)(|(cn={0]})(mail={0})))
  to allow loginng on using the cn or the mail address
- automatically consistent / canonicalized username values
  (i.e. exactly the way the LDAP server returns them)
2025-01-02 12:05:39 +01:00
Peter Marschall
0253682c00 LDAP auth: do not blindly assume groups have a 2-letter naming attribute
Instead, strip away everything before (and including) the '=' sign of ther RDN.
2025-01-02 12:05:39 +01:00
Peter Marschall
8c2feb4726 LDAP auth: escape values used in LDAP filters to avoid possible injection of malicious code. 2025-01-02 12:05:39 +01:00
Peter Marschall
c243ae4ebf LDAP auth: require exactly one result when searching for the LDAP user DN
This makes sure not fail securely when the query returns multiple entries

- correct grammar in some cases
- we're doing _authentication here, not authorization
- uppercase LDAP in messages & comments
- rename variable _ldap_version to _ldap_module_version
  to avoid misunderstanding it as LDAP's protocol version
- align formatting & messages better between _login2() and _login3()
2025-01-02 12:05:39 +01:00
Peter Marschall
6f82333ff7 LDAP auth: harmonize _login2() and _login3() methods 2025-01-02 12:05:32 +01:00
Peter Marschall
b22038c746 LDAP auth: a little bit of cleanup
- correct grammar in some cases
- we're doing authentication here, not authorization
- uppercase LDAP in messages & comments
- rename variable _ldap_version to _ldap_module_version
  to avoid misunderstanding it as LDAP's protocol version
2024-12-29 17:36:01 +01:00
IM
7df2fb35a7 Disable overloading BaseAuth login method 2024-12-25 21:56:04 +03:00
Peter Bieringer
886f4ee8d0 make tox happy 2024-12-14 09:09:36 +01:00
Peter Bieringer
46acbfd987 Improve: auth.ldap config shown on startup, terminate in case no password is supplied for bind user 2024-12-14 09:04:15 +01:00
Peter Bieringer
0e0592e3b8 extend copyright 2024-12-14 09:02:36 +01:00
Bishtawi
ee2af306d7 Support loading ldap secret from file 2024-11-05 00:35:36 -08:00
Peter Bieringer
687624a403 fix spelling 2024-11-02 13:23:41 +01:00
Dipl. Ing. Péter Varkoly
e887b06d21 Fix syntax 2024-09-23 15:49:58 +02:00
Dipl. Ing. Péter Varkoly
b1c682de57 Enhance docomentation.
Fix imports
2024-09-23 15:46:08 +02:00
Dipl. Ing. Péter Varkoly
0feca04086 Implementing ssl connection for ldap auth 2024-09-23 10:19:50 +02:00
Dipl. Ing. Péter Varkoly
645619bac8 Fix format string 2024-09-17 09:33:31 +02:00