Skip to content

Permission denied with JUPYTER_PATH #591

@sjusko

Description

@sjusko

I have added environment variable "JUPYTER_PATH" with custom locations in Jupyterhub config file (jupyterhub_config.py) via:

c.Spawner.environment = {'JUPYTER_PATH':'/tmp/test_kernels/others/share/jupyter:/tmp/test_kernels/testuser/share/jupyter'}

Kernels are visible in Jupyterhub, but it isn't possible to start any Kernel. Even Kernels located in default locations (~/.local/share/jupyter/, {sys.prefix}/share/jupyter/) are showing "error starting kernel, unhandled error".

Issue is related to directory permissions, when user has no privileges to access one of the directories specified via "JUPYTER_PATH":

(base) [root@td-cdp kernels]# ll /tmp/test_kernels/
total 8
drwxr-xr-x 3 otheruser otheruser 4096 Dec 3 13:20 others
drwx------ 3 testuser testuser 4096 Dec 3 13:04 testuser

Following error is in logs:

File "/opt/miniconda3/lib/python3.8/site-packages/jupyter_client/kernelspec.py", line 234, in get_kernel_spec
Dec 4 14:24:28 td-cdp jupyterhub: resource_dir = self._find_spec_directory(kernel_name.lower())
Dec 4 14:24:28 td-cdp jupyterhub: File "/opt/miniconda3/lib/python3.8/site-packages/jupyter_client/kernelspec.py", line 206, in _find_spec_directory
Dec 4 14:24:28 td-cdp jupyterhub: files = os.listdir(kernel_dir)
Dec 4 14:24:28 td-cdp jupyterhub: PermissionError: [Errno 13] Permission denied: '/tmp/test_kernels/testuser/share/jupyter/kernels'
Dec 4 14:24:28 td-cdp jupyterhub: [W 2020-12-04 14:24:28.441 SingleUserNotebookApp handlers:613] Unhandled error
Dec 4 14:24:28 td-cdp jupyterhub: [E 2020-12-04 14:24:28.442 SingleUserNotebookApp log:166]

image

image

Jupyter_client is handling only "errno.ENOTDIR (Not a directory)" and "errno.ENOENT (No such file or directory)", but there is no handling for "errno.EACCES (Permission denied)".
jupyter_client/kernelspec.py:

204 for kernel_dir in self.kernel_dirs:
205 try:
206 files = os.listdir(kernel_dir)
207 except OSError as e:
209 if e.errno in (errno.ENOTDIR, errno.ENOENT):
210 continue
211 raise

Adding following to code could solve this issue:
if e.errno in (errno.ENOTDIR, errno.ENOENT, errno.EACCES)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions