jupyterhub / sudospawner

Spawn JupyterHub single-user servers with sudo
BSD 3-Clause "New" or "Revised" License
50 stars 41 forks source link

etc/migrated tried to create as sudo'ed user #74

Closed Frank-Steiner closed 1 year ago

Frank-Steiner commented 1 year ago

Hi,

after having setup sudospawner jupyterhub starts fine. But when the first user tries to login the session fails because it cannot create the etc/migrated file:

Feb 16 12:41:29 euler start_jhub[30082]: Traceback (most recent call last):
Feb 16 12:41:29 euler start_jhub[30082]:   File "/opt/jhub/bin/jupyterhub-singleuser", line 8, in <module>
Feb 16 12:41:29 euler start_jhub[30082]:     sys.exit(main())
Feb 16 12:41:29 euler start_jhub[30082]:   File "/opt/jhub/lib/python3.10/site-packages/jupyterhub/singleuser/app.py", line 66, in main
Feb 16 12:41:29 euler start_jhub[30082]:     return SingleUserLabApp.launch_instance()
Feb 16 12:41:29 euler start_jhub[30082]:   File "/opt/jhub/lib/python3.10/site-packages/jupyter_core/application.py", line 277, in launch_instance
Feb 16 12:41:29 euler start_jhub[30082]:     return super().launch_instance(argv=argv, **kwargs)
Feb 16 12:41:29 euler start_jhub[30082]:   File "/opt/jhub/lib/python3.10/site-packages/traitlets/config/application.py", line 1042, in launch_instance
Feb 16 12:41:29 euler start_jhub[30082]:     app.initialize(argv)
Feb 16 12:41:29 euler start_jhub[30082]:   File "/opt/jhub/lib/python3.10/site-packages/jupyterhub/singleuser/mixins.py", line 971, in initialize
Feb 16 12:41:29 euler start_jhub[30082]:     result = super().initialize(*args, **kwargs)
Feb 16 12:41:29 euler start_jhub[30082]:   File "/opt/jhub/lib/python3.10/site-packages/jupyterhub/singleuser/mixins.py", line 642, in initialize
Feb 16 12:41:29 euler start_jhub[30082]:     super().initialize(argv)
Feb 16 12:41:29 euler start_jhub[30082]:   File "/opt/jhub/lib/python3.10/site-packages/traitlets/config/application.py", line 113, in inner
Feb 16 12:41:29 euler start_jhub[30082]:     return method(app, *args, **kwargs)
Feb 16 12:41:29 euler start_jhub[30082]:   File "/opt/jhub/lib/python3.10/site-packages/jupyter_server/serverapp.py", line 2507, in initialize
Feb 16 12:41:29 euler start_jhub[30082]:     super().initialize(argv=argv)
Feb 16 12:41:29 euler start_jhub[30082]:   File "/opt/jhub/lib/python3.10/site-packages/traitlets/config/application.py", line 113, in inner
Feb 16 12:41:29 euler start_jhub[30082]:     return method(app, *args, **kwargs)
Feb 16 12:41:29 euler start_jhub[30082]:   File "/opt/jhub/lib/python3.10/site-packages/jupyter_core/application.py", line 252, in initialize
Feb 16 12:41:29 euler start_jhub[30082]:     self.migrate_config()
Feb 16 12:41:29 euler start_jhub[30082]:   File "/opt/jhub/lib/python3.10/site-packages/jupyterhub/singleuser/mixins.py", line 434, in migrate_config
Feb 16 12:41:29 euler start_jhub[30082]:     super().migrate_config()
Feb 16 12:41:29 euler start_jhub[30082]:   File "/opt/jhub/lib/python3.10/site-packages/jupyter_core/application.py", line 181, in migrate_config
Feb 16 12:41:29 euler start_jhub[30082]:     migrate()
Feb 16 12:41:29 euler start_jhub[30082]:   File "/opt/jhub/lib/python3.10/site-packages/jupyter_core/migrate.py", line 241, in migrate
Feb 16 12:41:29 euler start_jhub[30082]:     with open(os.path.join(env["jupyter_config"], "migrated"), "w", encoding="utf-8") as f:
Feb 16 12:41:29 euler start_jhub[30082]: PermissionError: [Errno 13] Permission denied: '/opt/jhub/etc/migrated'
Feb 16 12:41:30 euler start_jhub[30082]: [E 230216 12:41:30 mediator:43] mediator result: {'ok': False, 'error': 'Exited with status: 1'}
Feb 16 12:41:30 euler start_jhub[30082]: [E 2023-02-16 12:41:30.249 JupyterHub user:833] Unhandled error starting fst's server: 'pid'

When I set /opt/jhub/etc to permissions 1777 the startup works find and /opt/jhub/etc/migrated is created with user fst as owner.

That doesn't make sense, I guess, because etc/ shouldn't be writeable for everyone.

Is there a way to force the migrated file to be created in some tmp dir? Or is this just a bug?

Once the file has been created, other users can login and start a session, too. I can also touch the migrated file as root (being empty), then the login works, too. But if doesn't exist yet, it should be created as the user running jupyterhub and not as the user who first logs in.

This happens with jupyterhub 3.1.1 and pthon 3.10.8 on SuSE Linux Enterprise 15 SP4

Configuration ```python # jupyterhub_config.py c.Spawner.cmd = ['jupyter-labhub'] c.Spawner.default_url = '/lab' c.JupyterHub.cleanup_servers = False c.ConfigurableHTTPProxy.should_start = False c.JupyterHub.cookie_secret_file = '/etc/jhub/jupyterhub_cookie_secret' c.ConfigurableHTTPProxy.api_url = 'http://localhost:8791' c.JupyterHub.pid_file = '/run/jhub/jhub.pid' c.JupyterHub.db_url = '/var/lib/jhub/jupyterhub.sqlite' c.JupyterHub.spawner_class = 'sudospawner.SudoSpawner' c.SudoSpawner.sudospawner_path = '/opt/jhub/bin/sudospawner' ```
welcome[bot] commented 1 year ago

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively. welcome You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! :wave:
Welcome to the Jupyter community! :tada:

Frank-Steiner commented 1 year ago

It turned out that this was caused by JUPYTER_CONFIG_DIR being set to /opt/jhub/etc accidentally. Unsetting this fixed the problem.