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

[WIP] Remove tokens from Database #83

Closed
wants to merge 8 commits into from

Conversation

ssanderson
Copy link
Contributor

Alternative implementation of #81 for discussion in #80.

Removes the APIToken and CookieToken fields from the ORM in favor of relying on Tornado's cookie encryption as the source
of truth for authentication.

This is currently rebased off of @minrk's work on #81 to steal his refactoring of the cookie_secret and proxy auth token handling. If we decide to go this route, it should be rebased some more to not include the detour through DIY encryption-land.

minrk and others added 7 commits October 27, 2014 16:23
- add files for cookie and database secrets
- store cookie secret on disk, instead of in database
- encrypt auth tokens with EncryptedType
- use PasswordType
- store first 4 bytes for filtering by prefix
  since we can't filter by equality on the hashed value.
- user.new_foo_token() returns token string, not ORM object
it's not needed - new tokens are created when spawners start
removes last need for encrypted database fields, so db_secret is removed as well.
@minrk
Copy link
Member

minrk commented Oct 28, 2014

Trying to work through the implications of this:

  • relying on cookie_secret means that cookie_secret changes invalidates all API tokens
  • The only way to revoke a token is to change the cookie_secret
  • That means revoking anyone's login requires restarting all single-user servers
  • The lack of multiple tokens per user means that tokens cannot be revoked individually, only all at once.

Is that right, so far?

@ssanderson
Copy link
Contributor Author

relying on cookie_secret means that cookie_secret changes invalidates all API tokens

Yes. I don't know if there's an easy way to have separate secrets for API vs Cookie Tokens.

The only way to revoke a token is to change the cookie_secret.

Currently, yes. Working on a change that would make it possible to revoke tokens for a just a specific user. Basically the idea is to do user lookups by a unique id rather than the user's name. Then, changing that unique id is enough to invalidate all tokens for that user.

That means revoking anyone's login requires restarting all single-user servers

Yes, with the same caveat as above.

The lack of multiple tokens per user means that tokens cannot be revoked individually, only all at once.

Yes. I don't think there's a straightforward way around that with this design.

@ssanderson
Copy link
Contributor Author

1df0abd, coupled with some sort of cache-invalidation for the SU Server, should make per-user access revocation possible. If the user's auth_id is changed, then _user_from_auth_id will return None, triggering a redirect to /login.

@minrk
Copy link
Member

minrk commented Oct 28, 2014

I had GitHub's API in mind when putting together the token stuff, where one can create tokens for access to the API. The reason being that one could create tokens for external services that monitor and amend behavior of the Hub (e.g. shutting down idle servers, which I don't plan to implement in the Hub itself). I don't really want to force everything that a user has granted access to the API to share the same token. In fact, I had planned to take the Token stuff further, adding auth scopes, etc.

I do like the simplicity here, I'm just trying to figure out if I'm okay with losing the planned functionality. Especially since I wasn't using it, yet.

@minrk
Copy link
Member

minrk commented Oct 28, 2014

@ssanderson here's a use case:

Can you 'log out' a user by invalidating their cookies without forcing their server to restart because the server's API token has also been invalidated?

@minrk
Copy link
Member

minrk commented Oct 28, 2014

Since I'm not sure that we'll be able to get away with no encrypted data in the db forever, I'd actually prefer to leave those digressions in the git history, even if we don't use them.

@minrk
Copy link
Member

minrk commented Oct 28, 2014

My current leaning is that getting rid of cookie tokens is good, but I'm not so sure about getting rid of API tokens. I'll keep thinking about that.

@ssanderson
Copy link
Contributor Author

Can you 'log out' a user by invalidating their cookies without forcing their server to restart because the server's API token has also been invalidated?

You couldn't do that with what's currently implemented, but it would be trivial to add a new unique key to Users that could be used to separately invalidate API keys vs cookies. That ends up being a slippery slope pretty quickly though, so the right thing to do would probably be to add a Permission table that's linked to a user. I think that probably ends up pretty similar in spirit to your original design for API Tokens.


PASSWORD_SCHEMES = ['pbkdf2_sha512']
Copy link
Member

Choose a reason for hiding this comment

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

Where does this get used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is left over from the rebase from #82.

Copy link
Member

Choose a reason for hiding this comment

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

@minrk
Copy link
Member

minrk commented Oct 28, 2014

the right thing to do would probably be to add a Permission table that's linked to a user

I think that's the way it will end up going.

@rgbkrk
Copy link
Member

rgbkrk commented Oct 28, 2014

Ok, I should probably review this for the forest instead of the trees since this is currently a WIP.

@minrk has thoroughly convinced me of why we should keep API tokens (but not the cookie tokens), to enable a way to authorize applications to communicate with JupyterHub. This helps us in that:

  • The application can use an API instead of having to be installed as some plugin on the server
  • It makes our code management easier so that our extension points are at the API level

I'll have to come back to this later after getting some more time to dig in.

@minrk minrk closed this in 27e51cd Oct 30, 2014
consideRatio pushed a commit to consideRatio/jupyterhub that referenced this pull request Feb 19, 2018
Restructure introduction and demark divisions of interest
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

Successfully merging this pull request may close these issues.

None yet

3 participants