danielfrg / s3contents

Jupyter Notebooks in S3 - Jupyter Contents Manager implementation
Apache License 2.0
248 stars 88 forks source link

JupyterHub + s3contents: Define `prefix` based on the authenticated username. #45

Closed martinzugnoni closed 6 years ago

martinzugnoni commented 6 years ago

I'm using JupyterHub with the DockerSpawner and Github OAuth configuration. When a user authenticates using Github, a new container is created using the jupyterhub/singleuser image. Despite having a separated container per authenticated user, everything inside each container runs under the same jovyan username.

I tried to keep users' files and folders in S3 separated by user namespaces, using this configuration:

import getpass
username = getpass.getuser()
c.S3ContentsManager.prefix = '{username}'.format(username=username)

But, of course, all prefixes get the jovyan username.

Is there any way of defining a prefix inside each container based on the real authenticated user instead of the user running the container?

My final goal is to have files/folders in S3 separated in users namespaces, so each of them can have their own files and there are no conflicts.

martinzugnoni commented 6 years ago

I found the solution.

There's a JUPYTERHUB_USER env var that contains the username of the authenticated JupyterHub user. I can use that for the prefix name, like this:

import os
c.S3ContentsManager.prefix = '{username}'.format(username=os.environ['JUPYTERHUB_USER'])

Thanks!

Deepanshu2017 commented 5 years ago

@martinzugnoni I'm trying to achieve the exactly same thing, using DockerSpawner and Github OAuth. I'm able to use the DockerSpawner and GithubOAuth with Jupyterhub Deploy Docker but while trying to use the S3contents with the above architecture, it didn't work for me. Could you please share your jupyterhub_config.py or point me to the repository for the thing that you have done in the past. This would help me a lot in my current project. Any help would be appreciated. Thanks!