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

Default folder recreates with root owner #127

Closed
egorlitvinenko opened this issue Nov 10, 2016 · 8 comments
Closed

Default folder recreates with root owner #127

egorlitvinenko opened this issue Nov 10, 2016 · 8 comments

Comments

@egorlitvinenko
Copy link

egorlitvinenko commented Nov 10, 2016

JupyterHub 0.6.1 is installing on Ubuntu 14.04, using DockerSpawner, custom Authenticator.
Authentication technic: Jupyter opens from another application with temporal code, LoginHandler get code from URL, connects to common application and check code, if success, user authorization is success, so no login form provides.

jupyterhub_configuration.py:

# Configuration file for jupyterhub.
c.JupyterHub.admin_access = True
c.JupyterHub.authenticator_class = 'MyAuthenticator'

c.JupyterHub.spawner_class = 'dockerspawner.DockerSpawner'
import os
notebook_dir = os.environ.get('DOCKER_NOTEBOOK_DIR') or '/home/jovyan/work'
c.DockerSpawner.notebook_dir = notebook_dir
c.DockerSpawner.volumes = { '/home/me/volumes/{username}': notebook_dir }
c.DockerSpawner.extra_host_config = {'network_mode': 'host'}
c.DockerSpawner.http_timeout = 90
c.DockerSpawner.debug = True

from jupyter_client.localinterfaces import public_ips
print(public_ips())
first_ip = public_ips()[0]
c.JupyterHub.hub_ip = first_ip
c.DockerSpawner.hub_ip_connect = first_ip

A problem is '/home/jovyan/work' folder belongs to root when new Spawner server created.
If I setting another folder, for example, '/notebooks', then '/notebooks' folder will be under root owner, but '/home/jovyan/work' will owned by jovyan. So it looks like folder automatically recreates by root user.
As a result I can't create any notebooks or files because of insufficient privileges and result is 'permission denied' error.

@minrk
Copy link
Member

minrk commented Nov 12, 2016

I think docker volumes need to exist before mounting them to avoid having them owned by root. I'm not sure the best way to do that.

@egorlitvinenko
Copy link
Author

Maybe, unfortunately vagrant doesn't up after I halt them, I will try this, when restore environment.

@myurasov
Copy link

+1

If you're using some external auth, you don't know what volumes need to exist.

@wwj718
Copy link

wwj718 commented Mar 2, 2017

@myurasov +1

@wwj718
Copy link

wwj718 commented Mar 2, 2017

@ALL I have a idea ,when the folder create ,we use watchdog to change the dir mode (chmod)

@myurasov
Copy link

myurasov commented Mar 3, 2017

I ended up with passing custom function to format_volume_name option and creating folder with correct permissions there. Which is not too elegant...

@pgeez
Copy link

pgeez commented Jun 12, 2017

@myurasov can you please post your code? thanks!

@myurasov
Copy link

@pgeez, something like that:

import os
import shutil

def format_volume_name(label_template, spawner):
    path = label_template.format(username=spawner.escaped_name)

    # creates user notebooks dir
    if not os.path.isdir(path):
        os.makedirs(path)
        shutil.chown(path, user='ubuntu', group='ubuntu')
        os.chmod(path, 0o755)

    return path

then in jupyterhub_config.py:

c.DockerSpawner.format_volume_name = format_volume_name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants