Skip to content

Share user sessions through the database#1172

Merged
gyorb merged 2 commits intoEricsson:masterfrom
whisperity:share-sessions-through-db
Jan 23, 2018
Merged

Share user sessions through the database#1172
gyorb merged 2 commits intoEricsson:masterfrom
whisperity:share-sessions-through-db

Conversation

@whisperity
Copy link
Copy Markdown
Contributor

@whisperity whisperity commented Nov 23, 2017

Closes #1145.

Along with the existing storage in the server's memory, user authentication session tokens will also be saved to the configuration database, in a new table. This way, if multiple servers are used, the user can authenticate through either and still receive the same token as they had before.

When a session cookie is presented, the following steps are taken to verify it:

  • Check if the token exists in the server's memory. If so, previous procedures apply.
  • Check if the token exists in the database. If the user is authenticated properly and the token exists, we create a local session by reusing the token in the database.

Session expiry times in the configuration file apply to how tokens in the database also expire. Expired tokens are not reused, at the attempt of reusal, they are deleted from the DB too.

Explicit logout also removes tokens from database.

@whisperity whisperity added enhancement 🌟 WIP 💣 Work In Progress CLI 💻 Related to the command-line interface, such as the cmd, store, etc. commands database 🗄️ Issues related to the database schema. server 🖥️ labels Nov 23, 2017
@whisperity whisperity added this to the release 6.3 milestone Nov 23, 2017
@whisperity whisperity requested review from dkrupp and gyorb November 23, 2017 14:46
@whisperity whisperity added RDY-OnHold 🛑 Patch reviewed and ready, but don't merge due to having to merge a dependent patch first. and removed WIP 💣 Work In Progress labels Nov 24, 2017
@whisperity whisperity force-pushed the share-sessions-through-db branch from b15db87 to 2cedd78 Compare November 24, 2017 12:55
@csordasmarton
Copy link
Copy Markdown
Contributor

@whisperity The migration script has been merged. Please resolve the conflicts to review you pull request.

@whisperity whisperity force-pushed the share-sessions-through-db branch from 2cedd78 to b2c9d16 Compare December 7, 2017 14:48
@whisperity whisperity removed the RDY-OnHold 🛑 Patch reviewed and ready, but don't merge due to having to merge a dependent patch first. label Dec 7, 2017
@whisperity whisperity force-pushed the share-sessions-through-db branch from b2c9d16 to b23faef Compare December 7, 2017 14:56
"product_db_version": {
"major" : "6",
"minor" : "0"
"minor" : "1"
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.

These versions can be removed later alembic schema versions should be used.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm adding this file back but without changing the version inside. Removing these dicts tumbles down into edits required that should not be part of this or any of my other PRs. See #1204.

self.is_group = is_group


class Session(Base):
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.

Wouldn't we mix the current database sessions with the user login sessions? I'm just thinking about a different naming here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You import them with different names using from ... import ... as .... The user login session, as an object, is an internal thing to session_manager.py, and should not be imported by code outside of it.

@whisperity whisperity force-pushed the share-sessions-through-db branch from b23faef to f9bc20c Compare December 7, 2017 15:50
if session_token:
headers = {'Cookie': session_manager.SESSION_COOKIE_NAME +
"=" + session_token}
headers = {'Cookie': SESSION_COOKIE_NAME + '=' + session_token}
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.

You use this line of code in multiple places. Can we create a helper function for it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think there exists a good place where this helper function could be put.

@@ -0,0 +1,541 @@
# -------------------------------------------------------------------------
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.

Did you modified this file or just changed the path? Why github doesn't recognize that the path was changed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The first commit split the file into a serverside and a clientside code. The second commit modified the serverside file.

records = transaction.query(SessionRecord). \
filter(and_(SessionRecord.auth_string ==
session.persistent_hash,
SessionRecord.token == token)).all()
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.

Can't we just call the delete operation on the query?

.query().filter().delete()

@whisperity whisperity force-pushed the share-sessions-through-db branch 2 times, most recently from 33ac223 to b250973 Compare December 8, 2017 10:29
@gyorb gyorb modified the milestones: release 6.3, release 6.3.1 Dec 8, 2017
@gyorb gyorb modified the milestones: release 6.3.1, release 6.4 Jan 5, 2018
@whisperity whisperity mentioned this pull request Jan 9, 2018
@whisperity whisperity force-pushed the share-sessions-through-db branch 2 times, most recently from 016ca0d to 60db95e Compare January 18, 2018 13:06
try:
manager = session_manager.SessionManager(root_sha, force_auth)
manager = session_manager.SessionManager(
server_cfg_file,
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.

I am getting the following error when starting CodeChecker with an empty workspace:

UnboundLocalError: local variable 'server_cfg_file' referenced before assignment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is fixed. Damn you IDE for pasting code after an else: like it was meant to be in the else's statement body.

@whisperity whisperity force-pushed the share-sessions-through-db branch from 60db95e to a5cf659 Compare January 18, 2018 13:33


def upgrade():
### commands auto generated by Alembic - please adjust! ###
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.

Please remove these generated comments if the migration script is ok.

import portalocker

from libcodechecker.logger import get_logger
<<<<<<< HEAD:libcodechecker/session_manager.py
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.

Could you remove these git marks from the source?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done these too.

in SessionManager.__valid_sessions
if s.still_reusable()]
self.__logins_since_prune = 0
<<<<<<< HEAD:libcodechecker/session_manager.py
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.

git marks here too.

@whisperity whisperity force-pushed the share-sessions-through-db branch from a5cf659 to e98959b Compare January 18, 2018 15:09
@whisperity whisperity requested a review from gyorb January 18, 2018 15:09
@whisperity whisperity force-pushed the share-sessions-through-db branch from e98959b to aedcc67 Compare January 18, 2018 15:14
@gyorb
Copy link
Copy Markdown
Contributor

gyorb commented Jan 19, 2018

@whisperity do we have a better place to share information between the server and the client? The name of version.py does not reflect this.

@whisperity
Copy link
Copy Markdown
Contributor Author

@gyorb We don't. I was thinking on extending the API to tell the client what is the cookie's name, but then the command line client would need to be rewritten to store for each individual server not only the token but the cookie name too, essentially slowly turning the CLI into a terminal webbrowser...

These are sort of global constants that need to be shared between the faces in a particular build.

I have an idea for making the build script generate the relevant files that contain the constants, kinda like how configure generates a header used in an autotools project. Could do this as a later patch.

@gyorb gyorb merged commit 51de24d into Ericsson:master Jan 23, 2018
@whisperity whisperity deleted the share-sessions-through-db branch January 30, 2018 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLI 💻 Related to the command-line interface, such as the cmd, store, etc. commands database 🗄️ Issues related to the database schema. enhancement 🌟 server 🖥️

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants