-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #730 from OpenSourceBrain/release/0.7.1
Release/0.7.1
- Loading branch information
Showing
46 changed files
with
1,205 additions
and
795 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
cloudharness keycloak authenticator | ||
=================================== | ||
|
||
Authenticator to use Jupyterhub with the keycloak gatekeeper. | ||
|
||
|
||
Running Tests: | ||
-------------- | ||
|
||
.. code-block:: bash | ||
pip install -r test-requirements.txt | ||
pip install -e . | ||
pytest | ||
PyTest does a lot of caching and may run into troubles if old files linger around. | ||
Use one ore more of the following commands to clean up before running pytest. | ||
|
||
.. code-block:: bash | ||
find ./ -name '*.pyc' -delete |
96 changes: 96 additions & 0 deletions
96
applications/jupyterhub/src/chauthenticator/chauthenticator/auth.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import random | ||
import sys | ||
import logging | ||
|
||
from jupyterhub.auth import Authenticator | ||
from jupyterhub.handlers import BaseHandler | ||
from tornado import gen | ||
from traitlets import Bool | ||
from jupyterhub.utils import url_path_join | ||
from cloudharness.auth import AuthClient | ||
|
||
handler = logging.StreamHandler(sys.stdout) | ||
handler.setLevel(logging.DEBUG) | ||
logging.getLogger().addHandler(handler) | ||
|
||
class CloudHarnessAuthenticateHandler(BaseHandler): | ||
""" | ||
Handler for /chkclogin | ||
Creates a new user based on the keycloak user, and auto starts their server | ||
""" | ||
def initialize(self, force_new_server, process_user): | ||
super().initialize() | ||
self.force_new_server = force_new_server | ||
self.process_user = process_user | ||
|
||
@gen.coroutine | ||
def get(self): | ||
self.clear_login_cookie() | ||
|
||
try: | ||
|
||
accessToken = self.request.cookies.get( | ||
'kc-access', None) or self.request.cookies.get('accessToken', None) | ||
print("Token", accessToken) | ||
if accessToken == '-1' or not accessToken: | ||
import socket | ||
raw_user = self.user_from_username("a-%s-%0.5x" % (socket.inet_aton(self.request.remote_ip).hex(), random.randint(0, 99999))) | ||
else: | ||
accessToken = accessToken.value | ||
user_data = AuthClient.decode_token(accessToken) | ||
username = user_data['sub'] | ||
print("Username", username, "-",user_data['preferred_username']) | ||
raw_user = self.user_from_username(username) | ||
print("JH user: ", raw_user.__dict__) | ||
self.set_login_cookie(raw_user) | ||
except Exception as e: | ||
logging.error("Error getting user from session", exc_info=True) | ||
raise | ||
|
||
user = yield gen.maybe_future(self.process_user(raw_user, self)) | ||
self.redirect(self.get_next_url(user)) | ||
|
||
|
||
class CloudHarnessAuthenticator(Authenticator): | ||
""" | ||
JupyterHub Authenticator for use with Cloud Harness | ||
When JupyterHub is configured to use this authenticator, the client | ||
needs to set the accessToken domain cookie | ||
""" | ||
|
||
auto_login = True | ||
login_service = 'chkc' | ||
|
||
force_new_server = Bool( | ||
True, | ||
help=""" | ||
Stop the user's server and start a new one when visiting /hub/chlogin | ||
When set to True, users going to /hub/chlogin will *always* get a | ||
new single-user server. When set to False, they'll be | ||
redirected to their current session if one exists. | ||
""", | ||
config=True | ||
) | ||
|
||
def process_user(self, user, handler): | ||
""" | ||
Do additional arbitrary things to the created user before spawn. | ||
user is a user object, and handler is a CloudHarnessAuthenticateHandler | ||
object. Should return the new user object. | ||
This method can be a @tornado.gen.coroutine. | ||
Note: This is primarily for overriding in subclasses | ||
""" | ||
return user | ||
|
||
def get_handlers(self, app): | ||
# FIXME: How to do this better? | ||
extra_settings = { | ||
'force_new_server': self.force_new_server, | ||
'process_user': self.process_user | ||
} | ||
return [ | ||
('/chkclogin', CloudHarnessAuthenticateHandler, extra_settings) | ||
] | ||
|
||
def login_url(self, base_url): | ||
return url_path_join(base_url, 'chkclogin') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
FROM jupyter/base-notebook:hub-1.4.2 | ||
|
||
COPY hub/jupyter_notebook_config.py /etc/jupyter/jupyter_notebook_config.py | ||
COPY hub/jupyter_notebook_config.py /etc/jupyter/jupyter_notebook_config.py | ||
USER root | ||
RUN mkdir /opt/workspace | ||
RUN chown -R jovyan:users /opt/workspace | ||
USER jovyan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
lfpykit==0.5.1 | ||
git+https://github.com/Neurosim-lab/netpyne.git@osbv2 |
Oops, something went wrong.