Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TIMEOUTs not working #264

Open
gumish opened this issue Aug 23, 2023 · 8 comments
Open

TIMEOUTs not working #264

gumish opened this issue Aug 23, 2023 · 8 comments

Comments

@gumish
Copy link

gumish commented Aug 23, 2023

Hello, at first thank you for great package! I am a newbie in Django+LDAP but I have managed to run it in quite short time :)

But I have a question about the case if the LDAP server is not reachable, so it can't be connected.
LDAP_AUTH_URL = ['ldaps://nonsense.com']

Is there a fallback that it will stop trying to connect the server and authenticate you via User model data?

I thought that these settings could help but nothing happened:

LDAP_AUTH_CONNECT_TIMEOUT = 2
LDAP_AUTH_RECEIVE_TIMEOUT = 2

I have also tried to add ModelBackend but also without success:

AUTHENTICATION_BACKENDS = (
    'django_python3_ldap.auth.LDAPBackend',
    'django.contrib.auth.backends.ModelBackend',)

Also nothing about unreachable server appears in console (with logging settings from help):

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
        },
    },
    'loggers': {
        'django_python3_ldap': {
            'handlers': ['console'],
            'level': 'INFO',
        },
    },
}
@gumish gumish changed the title LDAP not connected Fallback TIMEOUTs not working Aug 29, 2023
@etianen
Copy link
Owner

etianen commented Sep 19, 2023

Adding multiple AUTHENTICATION_BACKENDS is the way to make it fall back to the model backend.

However, the model backend requires that the user account has a valid password set.

What makes you think the fallback the model backend is not working?

@gumish
Copy link
Author

gumish commented Sep 20, 2023

As you can see I used multiple AUTHENTICATION_BACKENDS.

But if I use a non-existing LDAP_AUTH_URL address like ['ldaps://nonsense.com'], then during login, I only see a rotating spinner in the browser, and nothing happens.

I would expect that because of LDAP_AUTH_CONNECT_TIMEOUT = 2 after 2 seconds it switch to 'django.contrib.auth.backends.ModelBackend' and log me in.

@etianen
Copy link
Owner

etianen commented Sep 20, 2023 via email

@gumish
Copy link
Author

gumish commented Sep 20, 2023

I am not sure if this will be useful:
DEBUG = True, logging level DEBUG

LDAP_AUTH_URL = ['ldaps://existing_server.com'] - existing running ldap server

D:\03__Web\CONTI\echm2>_virtenv\Scripts\python manage.py runserver 0.0.0.0:8080 
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
September 20, 2023 - 11:36:38
Django version 4.1.1, using settings 'echm.settings'
Starting development server at http://0.0.0.0:8080/
Quit the server with CTRL-BREAK.
[20/Sep/2023 11:37:35] "GET /accounts/login/?next=/ HTTP/1.1" 200 9734
[20/Sep/2023 11:37:44] "POST /accounts/login/ HTTP/1.1" 302 0
[20/Sep/2023 11:37:44] "GET / HTTP/1.1" 200 68206

>> successfully logged in


LDAP_AUTH_URL changed to ['ldaps://nonsense.com'] - non-existing server

D:\03__Web\CONTI\echm2\echm\settings.py changed, reloading.
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
September 20, 2023 - 11:38:12
Django version 4.1.1, using settings 'echm.settings'
Starting development server at http://0.0.0.0:8080/
Quit the server with CTRL-BREAK.
[20/Sep/2023 11:38:16] "GET /accounts/logout/?next=/ HTTP/1.1" 302 0
[20/Sep/2023 11:38:16] "GET / HTTP/1.1" 200 65959
[20/Sep/2023 11:38:18] "GET /accounts/login/?next=/ HTTP/1.1" 200 9734

>> no response, browser is endlessly waiting for it

@etianen
Copy link
Owner

etianen commented Sep 20, 2023

I think you're going to have to delve into the ldap3 source code to figure out what's going on here. Those settings are being passed to ldap3, and it seems to not be interpreting them as one would expect.

I'm wondering if it's one of:

@gumish
Copy link
Author

gumish commented Sep 21, 2023

Yes, I agree. I have noticed that you only pass setting variables to ldap3. I am not very experienced with github issuing, so I wrote here first if you are sure that this works correctly to you.

@danilogbotelho
Copy link

As you can see I used multiple AUTHENTICATION_BACKENDS.

But if I use a non-existing LDAP_AUTH_URL address like ['ldaps://nonsense.com'], then during login, I only see a rotating spinner in the browser, and nothing happens.

I would expect that because of LDAP_AUTH_CONNECT_TIMEOUT = 2 after 2 seconds it switch to 'django.contrib.auth.backends.ModelBackend' and log me in.

Placing ModelBackend first in AUTHENTICATION_BACKENDS allows me to login when my LDAP server is unreachable. If LDAPBackend comes first and the server is unreachable then Django hangs.

@parad0x96
Copy link

Same issue here these parameters seems to be ignored

LDAP_AUTH_CONNECT_TIMEOUT = 5
LDAP_AUTH_RECEIVE_TIMEOUT = 5

borislaviv added a commit to borislaviv/django-python3-ldap that referenced this issue Jun 4, 2024
Currently the pool is initiated so that servers are retried
indefinetely. This makes it hard to define concrete hard timeout for
login operation.

This change exposes ldap3's ServerPool active parameter as setting. That
way it provides means to resolve situations as with etianen#264.

https://ldap3.readthedocs.io/en/latest/server.html#server-pool
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants