Commit Graph

218 Commits

Author SHA1 Message Date
Francois Lesueur
ab267a2b87 auth_cache: empty digest when cache miss 2026-04-23 09:20:49 +02:00
Peter Bieringer
1b1c4cf0ef fix https://github.com/Kozea/Radicale/issues/2095 2026-04-19 11:56:57 +02:00
Henning Schild
6690e9e3ca radicale/utils: drop bcrypt compat check
We now support passlib and bcrypt5 so the test can be dropped.

Related-to: #1980
Signed-off-by: Henning Schild <henning@hennsch.de>
2026-04-14 19:13:44 +02:00
Henning Schild
80b0aaf24f auth/htpasswd: deal with bcrypt maximum password length
bcrypt < 5 always truncated overlong passwords for us, since version 5
we need to do that on our own or hope our password library does it for
us.

In order to support both passlib and libpass with bcrypt >= 5 we simply
truncate if needed so it does not matter which of the two libraries is
used.

Closes: #1896
Signed-off-by: Henning Schild <henning@hennsch.de>
2026-04-14 18:21:38 +02:00
webmaster
e22d5b438f fix(auth): prevent login variable overwrite during failed cache cleanup
In the failed login cache cleanup loop, the tuple unpacking was using
`login` as the local variable name, silently overwriting the current
user's login with the one retrieved from the expired cache entry.

This caused subsequent backend authentication (e.g. IMAP) to be
attempted with the wrong username, resulting in spurious auth failures
for legitimate users whenever an expired failed-cache entry happened
to be present at the same time.

Rename the loop variable to `login_expired` to avoid shadowing the
outer `login` variable, and fix the associated debug log to reference
`login_expired` instead of the previously incorrect `login_cache`.

Fixes: intermittent authentication failures when _cache_failed contains
expired entries from previous failed login attempts by other users.

Signed-off-by: webmaster <webmaster@jbsky.fr>
2026-04-10 11:39:56 +02:00
Peter Bieringer
fc50170a8d code/cosmetics 2026-03-29 14:52:41 +02:00
Peter Bieringer
8372482ccd Merge branch 'master' into deprecate-ldap_use_ssl 2026-02-24 21:33:30 +01:00
magicfelix
74ad76b36d [OAuth2] Allow custom client_id and client_secret 2026-02-24 18:24:59 +01:00
Peter Marschall
8c9df49caf LDAP auth: remove config option 'ldap_use_ssl'
Remove the config option 'ldap_use_ssl' from the code and documentation,
deprecating it for good.
2026-02-22 12:51:45 +01:00
Peter Bieringer
863d2e14d0 change loglevel 2026-01-10 07:48:55 +01:00
Peter Bieringer
ffb2fb5e78 cosmetics 2026-01-10 07:48:43 +01:00
Peter Bieringer
5214287875 replace too simple autodetection with hash length by proper regular expression 2026-01-08 05:39:44 +01:00
Peter Bieringer
3eb5f32d3d update copyright year 2026-01-06 17:34:43 +01:00
Peter Bieringer
84bf14fd8e add note about bcrypt vs. passlib/libpass 2026-01-06 17:33:02 +01:00
Peter Bieringer
731716856c check whether bcrypt is usuable with passlib/libpass version 2026-01-06 17:32:24 +01:00
Peter Bieringer
6efb627903 fix typo 2026-01-06 17:30:11 +01:00
Peter Bieringer
690914e49f add unit 2025-12-13 08:00:06 +01:00
Peter Bieringer
f3f73ece15 reactivate IMAP AUTH=LOGIN as fallback replaced by 25402ab641 supporting https://github.com/Kozea/Radicale/issues/1929 2025-12-03 08:24:25 +01:00
Peter Bieringer
bf8619a41c add support for http_remote_user 2025-11-15 15:32:13 +01:00
Peter Marschall
2d9830fb6a LDAP auth: add my Copyright to radicale/auth/ldap.py 2025-09-29 20:17:16 +02:00
Peter Marschall
f0626a8dde LDAP auth: change 'ldap_ssl_verify_mode' to NONE for ldapi://
For ldapi:// connections, which connect - by definition - to a local UNIX
socket, lower the value of config setting 'ldap_ssl_verify_mode' to "NONE"
to avoid certificate validation failures.
The UNIX socket address can NEVER match any DNS name from a certificate,
making the whole certificate validation moot.

This is a workaround for a limitation of Python's LDAP modules, that do not
consider this edge case.
2025-09-29 20:15:33 +02:00
Peter Marschall
bcba53ed8d LDAP auth: re-factor handling of 'ldap_ssl_verify_mode'
* treat 'ldap_ssl_verify_mode' as string
* perform check for accepted values; fail on illegal ones
* translate to the values nbeeded by the respective LDAP module
  when doing the login, based on a module specific dictionary
2025-09-29 20:15:33 +02:00
Peter Marschall
7df4c070e1 LDAP auth: fail on illegal values for config settings
Thr config settings 'ldap_security' and 'ldap_ssl_verify_mode' only
accept a specific set of values: fail if other values are provided.
2025-09-29 20:15:33 +02:00
Peter Marschall
b6ee3b6991 LDAP auth: align values when logging config options
In addition, log 'ldap_ssl_verify_mode' and 'ldap_ssl_ca_file' unconditionally.
2025-09-29 20:15:33 +02:00
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 Bieringer
b46916fca9 fix according to https://github.com/Kozea/Radicale/issues/1878#issue-3438629348 2025-09-24 06:35:27 +02:00
Johannes Berg
256ca59aaf auth: clean up remote IP parameter/documentation
Make the remote IP parameter more generic and make it an enum
determining the source instead of a boolean. Also fix the
changelog entry.

Both as requested, I managed to miss those comments previously.
2025-09-09 20:25:49 +02:00
Johannes Berg
b5a1ea911d auth: dovecot: pass remote IP (rip=) to auth server
If known, let the auth server know where the client came
from, using REMOTE_ADDR or, optionally/configurably, the
X-Remote-Addr header value (which is needed when running
behind a trusted proxy.)

Addresses #1859.
2025-09-09 12:10:00 +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
Peter Bieringer
1e44a086bc Python < 3.10 regression fix 2025-05-16 07:37:35 +02:00
Peter Bieringer
d1098c3e22 flake8 regression E261 2025-05-16 07:28:50 +02:00
Juan F Arjona
7eb4e037cc Fixing extra space lint doesn't like :-|. 2025-05-07 13:33:18 -04:00
Juan F Arjona
1fe0211ba6 Update __init__.py
Making lint happy (?)
2025-05-07 11:59:27 -05:00