Skip to content

S2S: Reuse session instead of authenticating on every request #12228

Closed

Description

@LukasReschke

Currently server-to-server sharing's authentication mechanism is implemented within

protected function validateUserPass($username, $password) {
, in this code the password is verified for every single request.

This is a very huge performance drawback as the password is hashed using bcrypt which consumes a lot of CPU power. Instead we should generate a session which can be then reused by the remote ownCloud server instead of re-authenticating on every request.

@icewind1991 FYI

Activity

  1. PVince81 commented on Jan 21, 2015

    @PVince81
    Contributor

    Setting to 8.1 as this makes server to server sharing very slow, something to look at.

    CC @DeepDiver1975 @karlitschek

  2. added this to the milestone on Jan 21, 2015
  3. PVince81 commented on Feb 11, 2015

    @PVince81
    Contributor

    So, as discussed on IRC with @LukasReschke we need to catch the cookie and resend it with auth, then just reuse it for further requests.

    But currently we use Sabre\Client which relies on curl.
    And you mentionned that Guzzle is a nice HTTP client that could do it.

    Possibly solutions:

    1. Use Guzzle ourselves instead of Sabre\Client
      or
    2. Try and make Sabre\Client use Guzzle instead of curl (if possible from the class structure)
      or
    3. Find a nice and hacky way to tell curl to keep cookies (if possible)
  4. LukasReschke commented on Feb 11, 2015

    @LukasReschke
    ContributorAuthor

    Let me dig into the code some time… Assigning to myself.

  5. self-assigned this
    on Feb 11, 2015
  6. PVince81 commented on Feb 11, 2015

    @PVince81
    Contributor

    I had a quick look and our current version of Sabre wouldn't fit.

    But the new Sabre version seems to come with an improved client: https://github.com/fruux/sabre-dav/blob/2.1/lib/DAV/Client.php
    That one is based on the Sabre\Http\Client here: https://github.com/fruux/sabre-http/blob/master/lib/Client.php#L18 which has events "beforeRequest" and "afterRequest" that give access to the headers. This means that we could just implement those and do the cookie magic.

    It also means that it's really time to upgrade Sabre... #12876

  7. PVince81 commented on Feb 25, 2015

    @PVince81
    Contributor

    🔔 the new Sabre has arrived which means it will be possible to work with the cookies now 😄

  8. modified the milestones: , on Apr 23, 2015
  9. PVince81 commented on Apr 23, 2015

    @PVince81
    Contributor

    Moving to 8.2

  10. PVince81 commented on Sep 21, 2015

    @PVince81
    Contributor

    @LukasReschke any update ?

  11. 10 remaining items

  12. modified the milestones: , on Jun 14, 2016
  13. PVince81 commented on Oct 10, 2016

    @PVince81
    Contributor

    Reuse session or send an Authentication header as per #11815.

    But reusing the session should reduce the burden on the remote server.

  14. PVince81 commented on Oct 10, 2016

    @PVince81
    Contributor

    There are actually two levels of reusing the session:

    1. Level 1: within a single PHP request, we already do many calls to the remote server. Keeping a single session within that PHP request would already reduce the load significantly.

    2. Level 2: store the session id in the database to be able to reuse it in separate PHP requests. When expired, need to refresh it. (this all somehow reminds me of OAuth...)

  15. PVince81 commented on Oct 10, 2016

    @PVince81
    Contributor

    Hmm strange thing, I just tested on master and looking at access_log I only saw a single 401 appearing instead of multiple ones. Maybe one of the Sabre upgrades brought cookie support. Need to double check this.

  16. PVince81 commented on Oct 10, 2016

    @PVince81
    Contributor

    From what I see and remember, Sabre client's HTTP layer has changed a bit. And from what I see here https://github.com/fruux/sabre-http/blob/4.2.1/lib/Client.php#L348 it might be using a single curl session, which is likely to keep cookies.

    I'll check on the remote server to see if we're indeed reusing a session.
    Then: identify which version this stated happening and hopefully close this ticket 😄

  17. PVince81 commented on Oct 10, 2016

    @PVince81
    Contributor

    Okay, I did some debugging on the target server and noticed that the sabre client was already sending the Authorization header for any requests that follow the one with 401. So the 401 only happens once.

    Now let's see if we can also reuse the session to reduce the load even more.

  18. PVince81 commented on Oct 10, 2016

    @PVince81
    Contributor

    Now thinking of it the public webdav usually isn't supposed to have a session.
    But it does have one because someone can authenticate several link shares using their password and that information is stored in the session to avoid re-auth multiple times.

    So there is still a little bit to save here.

  19. modified the milestones: backlog, 10.0 on Apr 11, 2017
  20. PVince81 commented on Dec 15, 2017

    @PVince81
    Contributor

    Will be obsoleted by #29779

  21. lock commented on Aug 2, 2019

    @lock

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  22. locked as resolved and limited conversation to collaborators on Aug 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions