sudospowner:使用sudo的jupyterhub的产卵器
sudospawner的Python项目详细描述
苏多斯帕纳
sudospowner启用JupyterHub
通过生成中间服务器,在不作为根用户的情况下生成单用户服务器
通过代表用户执行操作的sudo
进行处理。
中间过程sudospawner
中介只能做两件事:
- 使用os.kill()调用向另一个进程发送信号
- 生成单用户服务器
启动sudospawner
脚本是唯一需要
jupyterhub管理员有权执行sudo
访问。
安装和设置
安装:
pip install -e .
要将jupyterhub配置为使用sudospowner,请在
jupyterhub_config.py
:c.JupyterHub.spawner_class='sudospawner.SudoSpawner'
那张JupyterHub documentation 有关于creating a configuration file的其他信息, 如果需要,以及配置文件的建议文件位置。
自定义单用户启动命令
为了限制sudospowner授予集线器的权限,
启动单用户服务器时
生成的可执行文件硬编码为dirname(sudospawner)/jupyterhub-singleuser
。
这要求sudospawner
可执行文件与jupyterhub-singleuser
命令位于同一目录中。
非常重要用户不能修改包含sudospawner
的bin/
目录,
否则,它们可以修改sudospawner
实际启用jupyterhub的功能。
您可能需要在启动服务器之前初始化用户环境变量,或者执行其他初始化。
如果在sudospawner
旁边安装名为sudospawner-singleuser
的脚本,
这将代替直接的jupyterhub-singleuser
命令。
例如,您可能希望从conda环境中派生笔记本服务器,这些环境是与集线器实例分开修改和部署的。
#!/bin/bash -lset -e # Activate the notebook environmentsource /opt/miniconda/bin/activate /opt/envs/notebook-latest # Show environment info in the log to aid debugging conda info # Delegate the notebook server launch to the jupyterhub-singleuser script.# this is how most sudospawner-singleuser scripts should end.exec"$(dirname "$0")/jupyterhub-singleuser"$@
sudospowner与jupyterlab hub单用户启动命令
为了让sudospowner与jupyterlab hub一起工作,您需要创建一个自定义的单用户启动命令。
在与sudospawner
相同的目录中创建包含以下代码的脚本sudospawner-singleuser
,并授予其相同的权限。
#!/bin/bash -l# Delegate the notebook server launch to the jupyter-labhub script.exec"jupyter-labhub"$@
示例
此repo中的Dockerfile包含用于设置jupyterhub系统的示例配置,无需以根用户身份运行任何内容。