JupyterHub : Inserting data into the hub DB using API and HTML form

84 views
Skip to first unread message

Joshua Dunham

unread,
Nov 16, 2016, 3:32:03 PM11/16/16
to Project Jupyter
Hi Jupyters,

     I'm working through setting up JupyterHub and am trying to think through how to provide a few group of people access to a single hub. Some questions:

- I've noticed that {username} is a variable I can use in some capacity (like directing the user to a specific path), Can I do the same with a group variable? My plan is to keep the config file sparse in terms of allowed users and instead start the server and populate the database. The API shows that users can be a part of groups but I can't find how I can use this (if at all). I can populate the database with a Jupyter service if this variable is useable in the config.

- The API on swagger shows that there is a way to get a username based on API key, is there a way to set a user's api key using the API? I'd like to inject a JWT 'key' that allows access to external systems. If possible, how could a user call this key in their notebook? Another option is to get a token using the authenticator but I'm not sure how I could store this for the duration of the token lifetime.

- The HTML form in the config seems like it could be useful to spawn a specific docker container for a user. Is this possible?


Thanks for your help and patience!

 -Joshua

MinRK

unread,
Nov 18, 2016, 5:47:17 AM11/18/16
to Project Jupyter

On Wed, Nov 16, 2016 at 9:32 PM, Joshua Dunham <joshua...@gmail.com> wrote:

Hi Jupyters,

     I'm working through setting up JupyterHub and am trying to think through how to provide a few group of people access to a single hub. Some questions:

- I've noticed that {username} is a variable I can use in some capacity (like directing the user to a specific path), Can I do the same with a group variable? My plan is to keep the config file sparse in terms of allowed users and instead start the server and populate the database. The API shows that users can be a part of groups but I can't find how I can use this (if at all). I can populate the database with a Jupyter service if this variable is useable in the config.

Group’s tricky, because a user can be in multiple groups. But if you assume that you only put users in one group, then you can accomplish this. An powerful but oft-overlooked tool is that you can have fully custom logic for paths and things by implementing tiny subclasses in your config file:

# jupyterhub_config.py

from jupyterhub.spawner import LocalProcessSpawner

class MySpawner(LocalProcessSpawner):
    def template_namespace(self):
        # add the user's first group as 'group' in the template namespace
        ns = super().template_namespace()
        ns['group'] = self.user.groups[0]

c.MySpawner.notebook_dir = '/shared/{group}/{username}'


- The API on swagger shows that there is a way to get a username based on API key, is there a way to set a user's api key using the API? I'd like to inject a JWT 'key' that allows access to external systems. If possible, how could a user call this key in their notebook? Another option is to get a token using the authenticator but I'm not sure how I could store this for the duration of the token lifetime.

The API key is a key for accessing JupyterHub itself, not for accessing external systems. Do you want to inject environment variables into the user’s server? You can do this with Authenticator.pre_spawn_start, or augmenting Spawner.environment, depending on where the token comes from.


- The HTML form in the config seems like it could be useful to spawn a specific docker container for a user. Is this possible?

Yes! imagespawner is an example of using this form to allow users to pick from a list of supported docker images.

-Min



Thanks for your help and patience!

 -Joshua

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscribe@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/2884f464-ae46-4996-bb84-312cddc69743%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Carol Willing

unread,
Nov 18, 2016, 10:37:27 AM11/18/16
to jup...@googlegroups.com, Project Jupyter
Thanks Min. I've gone ahead and added Ryan Lovett's imagespawner to the JupyterHub wiki (https://github.com/jupyterhub/jupyterhub/wiki/Spawners).

If members of the community have developed spawners that would be helpful to others, please contribute them to the wiki.

Thanks!

Carol Willing

Research Software Engineer, Project Jupyter
Cal Poly San Luis Obispo

Director, Python Software Foundation

Strengths: Empathy, Relator, Ideation, Strategic, Learner 

Sent from Nylas N1, the extensible, open source mail client.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+u...@googlegroups.com.

To post to this group, send email to jup...@googlegroups.com.

MinRK

unread,
Nov 18, 2016, 11:51:59 AM11/18/16
to Project Jupyter
Thanks, Carol!

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscribe@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages