Skip to content

do not hide exception when ldap server has a hiccup - #15332

Merged
MorrisJobke merged 8 commits into
stable7from
dont_hide_exceptions
Apr 22, 2015
Merged

MorrisJobke merged 8 commits into
stable7from
dont_hide_exceptions

Conversation

@butonic

@butonic butonic commented Mar 31, 2015

Copy link
Copy Markdown
Contributor

this PR allows connection related exceptions in user_ldap to bubble up. When triggered by the filecache post write hook the following message will now show up in tho oc log.

{"reqId":"551a86144fa46","app":"hook","message":"error while running hook (\\OC\\Files\\Cache\\Shared_Updater::writeHook): No LDAP Connection to server localhost","level":3,"

When a user tries to login and the ldap server is not available he will now see
bildschirmfoto von 2015-03-31 13 47 16

instead of

bildschirmfoto von 2015-03-31 13 50 53

Fixes #13862

@LukasReschke

Copy link
Copy Markdown
Contributor

Can we show the full stacktrace only if Debug mode is enabled? – It's fine to show "No LDAP Connection to server" and log this properly but we really should not expose all the other rest if not really required as I already see people complaining about exposing the directory structure etc…

@DeepDiver1975

Copy link
Copy Markdown
Contributor

Looks reasonable - @butonic do we get prs against master and stable8 as well? THX

@karlitschek

Copy link
Copy Markdown
Contributor

nice 👍 But I agree with @LukasReschke here. Can we make this debug only?

@butonic
butonic force-pushed the dont_hide_exceptions branch from 2febd85 to 24e9286 Compare March 31, 2015 12:56
@butonic

butonic commented Mar 31, 2015

Copy link
Copy Markdown
Contributor Author

bildschirmfoto von 2015-03-31 16 10 42

@DeepDiver1975

Copy link
Copy Markdown
Contributor

from my pov there is no reason to have the login page displayed - the regular exception page is quite okay - exception details should be hidden as soon as debug is disabled

@LukasReschke or is it necessary to throw a HintException here? THX

@LukasReschke

Copy link
Copy Markdown
Contributor

@LukasReschke or is it necessary to throw a HintException here? THX

Nope. HintException's are the only ones where the actual error message is shown to the user. So a throw new \HintException('Foo') would show Foo instead of an error page to the user. This is for example used in the setup for checks like the dependencies etc.

Any other uncatched exception will print the regular exception page which shows the "Instance has encountered a problem" button as well as the request ID to allow easier debugging of the error. If debug mode is enabled the whole stacktrace will be shown to the user. (otherwise the admin needs to cross-reference the request ID with the error log.)

@RobinMcCorkell

Copy link
Copy Markdown
Contributor

Could this result in the case where the LDAP server goes down (perhaps triggered by an admin), then the admin needs to go into oC to disable LDAP, but can't because login throws an exception that isn't caught?

@butonic

butonic commented Mar 31, 2015

Copy link
Copy Markdown
Contributor Author

There seems to be a problem with accessing the users page. @blizzz I always get a Could not create User instance error because the code tries to look up a user in the oc_ldap_user_mapping table. He calls $this->access->username2dn('35946d96-6bd8-1034-90e3-ab64516f8ff1'); but that owncloud_name does not exist. when are they added to the table? Here is the full stacktrace:

Could not create User instance
#0 /home/jfd/Repositories/oc/core-stable7/apps/user_ldap/lib/user/manager.php(193): OCA\user_ldap\lib\user\Manager->createInstancyByUserName('35946d96-6bd8-1...')
#1 /home/jfd/Repositories/oc/core-stable7/apps/user_ldap/user_ldap.php(186): OCA\user_ldap\lib\user\Manager->get('35946d96-6bd8-1...')
#2 /home/jfd/Repositories/oc/core-stable7/lib/private/user/manager.php(104): OCA\user_ldap\USER_LDAP->userExists('35946d96-6bd8-1...')
#3 /home/jfd/Repositories/oc/core-stable7/lib/private/user/manager.php(133): OC\User\Manager->get('35946d96-6bd8-1...')
#4 /home/jfd/Repositories/oc/core-stable7/lib/private/user.php(583): OC\User\Manager->userExists('35946d96-6bd8-1...')
#5 /home/jfd/Repositories/oc/core-stable7/lib/public/user.php(92): OC_User::userExists('35946d96-6bd8-1...', NULL)
#6 /home/jfd/Repositories/oc/core-stable7/apps/user_ldap/lib/access.php(414): OCP\User::userExists('35946d96-6bd8-1...')
#7 /home/jfd/Repositories/oc/core-stable7/apps/user_ldap/lib/access.php(510): OCA\user_ldap\lib\Access->dn2ocname('uid=zombie317,o...', 'Appel, Frederic', true)
#8 /home/jfd/Repositories/oc/core-stable7/apps/user_ldap/lib/access.php(441): OCA\user_ldap\lib\Access->ldap2ownCloudNames(Array, true)
#9 /home/jfd/Repositories/oc/core-stable7/apps/user_ldap/user_ldap.php(141): OCA\user_ldap\lib\Access->ownCloudUserNames(Array)
#10 /home/jfd/Repositories/oc/core-stable7/apps/user_ldap/user_ldap.php(327): OCA\user_ldap\USER_LDAP->getUsers('', 50, NULL)
#11 /home/jfd/Repositories/oc/core-stable7/lib/private/user/manager.php(215): OCA\user_ldap\USER_LDAP->getDisplayNames('', 50, NULL)
#12 /home/jfd/Repositories/oc/core-stable7/lib/private/user.php(570): OC\User\Manager->searchDisplayName('', 50, NULL)
#13 /home/jfd/Repositories/oc/core-stable7/settings/users.php(35): OC_User::getDisplayNames('', 50)
#14 /home/jfd/Repositories/oc/core-stable7/lib/private/route/route.php(135) : runtime-created function(1): require_once('/home/jfd/Repos...')
#15 [internal function]: __lambda_func(Array)
#16 /home/jfd/Repositories/oc/core-stable7/lib/private/route/router.php(227): call_user_func('\x00lambda_2447', Array)
#17 /home/jfd/Repositories/oc/core-stable7/lib/base.php(707): OC\Route\Router->match('/settings/users')
#18 /home/jfd/Repositories/oc/core-stable7/index.php(28): OC::handleRequest()
#19 {main}

@blizzz

blizzz commented Mar 31, 2015 via email

Copy link
Copy Markdown
Contributor

@nickvergessen

Copy link
Copy Markdown
Contributor

Throwing an exception will cause strange behaviour when ajax requests are done, since they receive HTML instead of JSON? What's the best way we can/should handle this?

@butonic
butonic force-pushed the dont_hide_exceptions branch 2 times, most recently from 8ee9145 to 2539c0d Compare April 1, 2015 10:37
@LukasReschke

Copy link
Copy Markdown
Contributor

Throwing an exception will cause strange behaviour when ajax requests are done, since they receive HTML instead of JSON? What's the best way we can/should handle this?

We already have this broken behaviour in a lot of other places :-(

@MorrisJobke

Copy link
Copy Markdown
Contributor

I tested this with a broken LDAP ... it works. Let me check the AJAX calls (I will test the sharing auto complete)

@butonic

butonic commented Apr 1, 2015

Copy link
Copy Markdown
Contributor Author

Throwing an exception will cause strange behaviour when ajax requests are done, since they receive HTML instead of JSON? What's the best way we can/should handle this?

We could check if the accept header is application/json in index.php before printing an exception. That is actually not that much work ... but not part of this PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To drop (roughly) 1 out of 20 requests change that line to:
if(rand(0,19) === 0 || is_null($this->ldapConnectionRes)) {

Comment thread lib/private/hook.php

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@icewind1991 Can you have a look at this?

@MorrisJobke MorrisJobke added this to the 7.0.7-next-maintenance milestone Apr 1, 2015
@MorrisJobke

Copy link
Copy Markdown
Contributor

How to test this:

  1. Setup a LDAP config with users
  2. Login as an LDAP user and share a file with the admin (non-LDAP user)
  3. Shut down the LDAP server
  4. Do a PROPFIND on the root folder (with the share from a LDAP user)

current behaviour:

The shared folder is simply omited.

With running LDAP server:

$ curl -X PROPFIND -H "Depth: 1" -u mjob:mjob http://localhost/master/remote.php/webdav/  | xmllint --format -
<?xml version="1.0" encoding="utf-8"?>
<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:oc="http://owncloud.org/ns">
  <d:response>
    <d:href>/master/remote.php/webdav/</d:href>
    ...
  </d:response>
  <d:response>
    <d:href>/master/remote.php/webdav/Shared-from-LDAP-user/</d:href>
    ...
  </d:response>
</d:multistatus>

With stopped LDAP server:

$ curl -X PROPFIND -H "Depth: 1" -u mjob:mjob http://localhost/master/remote.php/webdav/  | xmllint --format -
<?xml version="1.0" encoding="utf-8"?>
<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:oc="http://owncloud.org/ns">
  <d:response>
    <d:href>/master/remote.php/webdav/</d:href>
    ...
  </d:response>
</d:multistatus>

Behaviour with this patch

The PROPFIND result in a 500

$ curl -X PROPFIND -H "Depth: 1" -u mjob:mjob http://localhost/master/remote.php/webdav/ -v                                                                   
...
< HTTP/1.1 500 Internal Server Error
< Date: Wed, 01 Apr 2015 15:50:49 GMT
...

@jcfischer

Copy link
Copy Markdown
Contributor

@MorrisJobke unfortunately - still creates the f***** local:// entries.

I used the rand(0,100) === 0 method to simulate pathological conditions and let it run on our internal sync server. (only a few users running their sync clients this time of day). Within 20 minutes, 2 new local:// entries (probably due to my sync client doing discovery)

@jcfischer

Copy link
Copy Markdown
Contributor

I assume there is another code path that eats the exception. I have now disabled the creation of the local:// entry and will try to capture a backtrace of it happening

@butonic
butonic force-pushed the dont_hide_exceptions branch from 723beba to 4a87986 Compare April 2, 2015 09:09
@MorrisJobke

Copy link
Copy Markdown
Contributor

The idea now is that if no user could be fetched from any backend we simply cannot mount anything. We should therefore not mount a local storage based on the userId. This simply is wrong. @icewind1991 Can you confirm that this is how it should work? 4a87986?w=1

We throw an exception and let the endpoint (webdav, web UI) know that something bad happened. We later should try to make the backends more robust to failures of the underlying infrastructure, but for now we not have a way to communicate this up to the mount point init.

@icewind1991

Copy link
Copy Markdown
Contributor

@icewind1991 Can you confirm that this is how it should work? 4a87986?w=1

Seems reasonable

@MorrisJobke
MorrisJobke force-pushed the dont_hide_exceptions branch from d9c7123 to 919241c Compare April 22, 2015 09:35
@MorrisJobke

Copy link
Copy Markdown
Contributor

Rebased. Can we get this in. There are more and more problems with stable7 instances that could be solved by this.

cc @nickvergessen @LukasReschke @blizzz @icewind1991

@ghost

ghost commented Apr 22, 2015

Copy link
Copy Markdown

Refer to this link for build results (access rights to CI server needed):
https://ci.owncloud.org//job/pull-request-analyser-ng-simple/11728/
🚀 Test PASSed.🚀
chuck

@DeepDiver1975

Copy link
Copy Markdown
Contributor

👍

1 similar comment
@karlitschek

Copy link
Copy Markdown
Contributor

👍

@blizzz

blizzz commented Apr 22, 2015

Copy link
Copy Markdown
Contributor

If this was resolved #15332 (comment)

Checking

Update Seems so

@blizzz

blizzz commented Apr 22, 2015

Copy link
Copy Markdown
Contributor

The exception is not thrown, when the connection was established initially, but got lost during operation.

For example, do a search using occ over many users and shut off LDAP inbetween. Only partly results will be returned, »LDAP error Can't contact LDAP server (-1) after calling ldap_read« is being logged. I'll have a look.

@blizzz

blizzz commented Apr 22, 2015

Copy link
Copy Markdown
Contributor

added throwing another one. @butonic @MorrisJobke you ok with this?

@butonic

butonic commented Apr 22, 2015

Copy link
Copy Markdown
Contributor Author

@blizzz if you also port it to oc8 & master I am ok with it

@blizzz

blizzz commented Apr 22, 2015

Copy link
Copy Markdown
Contributor

will do

@blizzz

blizzz commented Apr 22, 2015

Copy link
Copy Markdown
Contributor

Added to the stable8 PR and, since master is done, opened an additional PR therefore: #15811

@scrutinizer-notifier

Copy link
Copy Markdown

The inspection completed: 3504 Issues, 89 Patches

@ghost

ghost commented Apr 22, 2015

Copy link
Copy Markdown

Refer to this link for build results (access rights to CI server needed):
https://ci.owncloud.org//job/pull-request-analyser-ng-simple/11740/
🚀 Test PASSed.🚀
chuck

@MorrisJobke

Copy link
Copy Markdown
Contributor

👍

MorrisJobke added a commit that referenced this pull request Apr 22, 2015
do not hide exception when ldap server has a hiccup
@MorrisJobke
MorrisJobke merged commit e72cd71 into stable7 Apr 22, 2015
@MorrisJobke
MorrisJobke deleted the dont_hide_exceptions branch April 22, 2015 20:48
@lock lock Bot locked as resolved and limited conversation to collaborators Aug 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.