Repository navigation
Superuser access reauthentication is broken for LDAP authenticated users #4
Copy link
Copy link
Open
Description
Note: This issue was originally open in the Sentry repository getsentry/self-hosted#1955 but I was instructed to open it here instead.
Steps to Reproduce
- Configure LDAP (Active Directory) authentication with the help of https://github.com/PMExtra/sentry-auth-ldap (according to the description provided there).
- Login as LDAP authenticated user with Admin and Superuser special privileges assigned.
- Go to Admin > Settings and let the page open without any further activity for approx. 10 minutes.
- After approx. 10 minutes, perform any action that requires the Superuser authorization, such as open Admin > Users.
- The Superuser authorization has expired at this point and you will be requested to reauthenticate ("You are attempting to access a resource that requires superuser access, please re-authenticate as a superuser."). Perform the reauthentication.
- The reauthentication will always fail for LDAP users. You will be repeatedly asked to reauthenticate even though the entered password is correct.
Note: The reauthentication works correctly for local users.
Expected Result
The Superuser reauthentication should work for LDAP users.
Actual Result
WIth the LDAP module debug logging enabled all the time we can see that during the reauthentication attempt there's no LDAP activity logged at all - e.g. it looks like the whole reauthentication isn't performed via LDAP so it may fail somewhere in Sentry. However logs don't reveal much.
sentry-self-hosted-web-1 (with debug LDAP module logging enabled and working)
01:37:03 [INFO] sentry.superuser: superuser.session-expired (ip_address='10.10.12.1' user_id=3)
01:37:03 [INFO] sentry.access.api: api.access (method='GET' view='sentry.api.endpoints.user_index.UserIndexEndpoint' response=403 user_id='3' is_app='None' token_type='None' is_frontend_request='True' organization_id='None' auth_id='None' path='/api/0/users/' caller_ip='10.10.12.1' user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/109.0' rate_limited='False' rate_limit_category='None' request_duration_seconds=0.0754690170288086 rate_limit_type='DNE' concurrent_limit='None' concurrent_requests='None' reset_time='None' group='None' limit='None' remaining='None')
01:37:03 [WARNING] django.request: Forbidden: /api/0/users/ (status_code=403 request=<WSGIRequest: GET '/api/0/users/?per_page=50&sortBy=date'>)
01:37:03 [INFO] sentry.access.api: api.access (method='GET' view='sentry.api.endpoints.authenticator_index.AuthenticatorIndexEndpoint' response=200 user_id='3' is_app='None' token_type='None' is_frontend_request='True' organization_id='None' auth_id='None' path='/api/0/authenticators/' caller_ip='10.10.12.1' user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/109.0' rate_limited='False' rate_limit_category='None' request_duration_seconds=0.0164639949798584 rate_limit_type='DNE' concurrent_limit='None' concurrent_requests='None' reset_time='None' group='None' limit='None' remaining='None')
01:37:16 [INFO] sentry.access.api: api.access (method='PUT' view='sentry.api.endpoints.auth_index.AuthIndexEndpoint' response=403 user_id='3' is_app='None' token_type='None' is_frontend_request='True' organization_id='None' auth_id='None' path='/api/0/auth/' caller_ip='10.10.12.1' user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/109.0' rate_limited='False' rate_limit_category='None' request_duration_seconds=0.01912689208984375 rate_limit_type='DNE' concurrent_limit='None' concurrent_requests='None' reset_time='None' group='None' limit='None' remaining='None')
01:37:16 [WARNING] django.request: Forbidden: /api/0/auth/ (status_code=403 request=<WSGIRequest: PUT '/api/0/auth/'>)
sentry-self-hosted-nginx-1
192.168.0.1 - - [04/Feb/2023:01:37:03 +0000] "GET /api/0/users/?per_page=50&sortBy=date HTTP/1.1" 403 106 "https://sentry.local.net/manage/users/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/109.0" "10.10.12.1"
192.168.0.1 - - [04/Feb/2023:01:37:03 +0000] "GET /_static/dist/sentry/chunks/vendors-node_modules_core-js_modules_es_typed-array_at_js-node_modules_core-js_modules_es_typ-06a003.5636c0cbbfd554229dab.js HTTP/1.1" 200 3373 "https://sentry.local.net/manage/users/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/109.0" "10.10.12.1"
192.168.0.1 - - [04/Feb/2023:01:37:03 +0000] "GET /_static/dist/sentry/chunks/app_components_modals_sudoModal_tsx.046324a25b268bcddd29.js HTTP/1.1" 200 5411 "https://sentry.local.net/manage/users/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/109.0" "10.10.12.1"
192.168.0.1 - - [04/Feb/2023:01:37:03 +0000] "GET /_static/dist/sentry/chunks/vendors-node_modules_cbor-web_dist_cbor_js-node_modules_core-js_modules_web_dom-exception_stack_js.ce1fadf94d1d59de2a16.js HTTP/1.1" 200 34309 "https://sentry.local.net/manage/users/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/109.0" "10.10.12.1"
192.168.0.1 - - [04/Feb/2023:01:37:03 +0000] "GET /api/0/authenticators/ HTTP/1.1" 200 2 "https://sentry.local.net/manage/users/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/109.0" "10.10.12.1"
192.168.0.1 - - [04/Feb/2023:01:37:16 +0000] "PUT /api/0/auth/ HTTP/1.1" 403 28 "https://sentry.local.net/manage/users/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/109.0" "10.10.12.1"
Sentry 23.1.1
sentry-auth-ldap 21.9.6
Reacted by Kamenev Nikolay
Metadata
Metadata
Assignees
Labels
No labels
Activity
PMExtra commentedon Mar 16, 2023
For enabling logging of ldap, we may have to change the Sentry source files, I've described it in README:
The file is usually at
/usr/local/lib/python3.8/site-packages/sentry/conf/server.py.hostalp commentedon Mar 16, 2023
I have the following in
self-hosted-23.3.0/sentry/sentry.conf.pyThis appears to work, however there isn't much in the log anyway. Only those events shown above.
PMExtra commentedon Mar 17, 2023
I think
LOGGING['disable_existing_loggers'] = Falsewon't work withsentry.conf.py.Because
sentry/conf/server.pyis executed aftersentry.conf.py.It will override
disable_existing_loggersbecomeTrue.hostalp commentedon Mar 17, 2023
I think it works, because I can see events such as the following being logged during login:
Is there supposed to be more than that?
With that configuration and logging, there's nothing being logged from django_auth_ldap during the reauthentication. If the logging really works it could mean that the reauthentication processing doesn't even reach the django_auth_ldap module, or that it doesn't get far enough in order to log something.
By the way I'm not sure how to set
LOGGING.disable_existing_loggersvia theserver.pyfile, because I install Sentry from the https://github.com/getsentry/self-hosted sources an there's no such file in there. During the installation process it downloads all the required contents and builds container images from them which are then used to run Sentry. I can then see the related setting (LOGGING.disable_existing_loggers: True) in the/usr/local/lib/python3.8/site-packages/sentry/conf/server.pyfile inside the running container where I can edit it (and delete its compiled form/usr/local/lib/python3.8/site-packages/sentry/conf/__pycache__/server.cpython-38.pyc), but would that be enough (given that the change is performed inside a running container e.g. on the already running Sentry instance)? It doesn't make any difference in the logged output.PMExtra commentedon Mar 21, 2023
getsentry/sentry#10380 @hostalp
Agalin commentedon May 28, 2024
You cannot reauthenticate because it's trying to compare password with the one in the database. Last time I checked code was structured in a way making customization impossible.
There is a workaround that let's you keep access to admin sites: Setup 2 factor authentication. I don't remember if TOTP is enough but it for sure works with U2F. Instead of asking for a password it wants the token and validates it properly.