-
Notifications
You must be signed in to change notification settings - Fork 41
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
Advantage of using sudo spawner over adding capabilities CAP_SETUID, CAP_SETGID to JupyterHub #62
Comments
This is a very good question - I had been looking for systemd functionality like this since in my tutorial I just run the server as root. But I am not familiar enough with systemd to understand what the implications of the CAP_* settings are. If they are what we need I would like to update my tutorial to use your systemd config. |
A process running with CAP_SETUID is able to set / change its own user ID. Similarly a process with CAP_SETGID can change its group ID. When a process spawns a new subprocess this subprocess inherits the UID and GID of the process. So when the JupyterHub starts a new singleuser it needs to change the singleusers UID and GID. Normally JupyterHub runs as root, then the singleuser runs as root. Since root can change UID and GID, the singleuser changes UID and GID to the correct ones. To run JupyterHub as non-root we need to add the possibility to change UID and GID. In sudospawner this is accomplished by adding the non-root user to the sudoers. The line |
@gatoniel this looks pretty neat! I don't know whether it's more/less/as safe as sudospawner. You could try asking on https://discourse.jupyter.org/ since more people are likely to see it? |
@gatoniel Thanks, that makes sense - I've never actually looked at how jupyterhub sets the user for the spawned processes but good to know it works. Do you know if CAP_SETUID/SETGID allow to set the values to the root user? I guess a downside relative to sudospawner could be that AFAIU the latter only allows to run the hard-coded jupyter process. I don't know if there are systemd options for doing that. I wonder if there is a way to use systemdspawner together with the CAP_* settings - at the moment systemdspawner still requires the hub to run as root 🤔 |
Hi, I tested the config with the standard spawner. Now I am using podmanspawner in combination with PAMAuthenticator, that I have modified to fully work with systemd, PAM and D-Bus (mainly to set loginuid correct). Therefore I need to switch from the non-root user to root and then back to the new logged in user. This is due to some permissions I need for logging in a user at the system. So in short: YES, with CAP_* you can switch back to root. I can´t comment on the other two raised questions due to lack of knowledge... |
I think doing this opens up some security issues, at least without further configuration. As the single-user server is now running with CAP_SETUID, any code run in a notebook or terminal can set the UID to 0 and run any further code as root: [In 1]: import os
os.setuid(0)
[In 2]: os.getuid()
[Out 2]: 0
[In 3]: import subprocess
subprocess.run("whoami", capture_output=True).stdout
[Out 3]: b'root\n' |
Hi,
I am running JupyterHub as separate non-root user with systemd without sudospawner. Instead I leverage the systemd AmbientCapabilities option. My jupyterhub.service file looks like this:
With this I can use the PAMAuthenticator for logging in and use the standard spawner for creating the single user notebooks. My question now is: Am I missing some feature of the sudospawner configuration? Or do I get the same effects with my configuration?
NOTE: I am running on CentOS 8. Maybe this makes a difference?
The text was updated successfully, but these errors were encountered: