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

Investigate possibility of spawning of container with another user than the default 'jovyan' #207

Open
rkevin-arch opened this issue Dec 3, 2020 · 10 comments

Comments

@rkevin-arch
Copy link
Member

From our meeting, if we want people from the HPC side to use JupyterHub and still have access to their files, we need to mount NFS volumes into the Jupyter pods. Each person from the HPC side would have a unique UID, but the pods are usually spawned with UID 1000 (jovyan), with no way to change it easily.

Some ideas:

  1. Mount the NFS volume as normal, run the container as the HPC UID, and before JupyterLab starts we manually do usermod and groupmod to change jovyan's UID/GID (or maybe grab their actual username and use that).
    The problem is there are plenty of places (e.g. /srv/conda) that uses UID 1000, so we have to do a blanket find and chown every time the pod starts, which takes tons of time (test run on my computer took ~25s).
    Also, if the user switches to a different profile that does not go through this UID mapping process, their existing Jupyter home directory will not have UID 1000 and they might not be able to edit their files. This may not be a problem if we enforce "all HPC users must always use their HPC UID", but I'm not 100% sure.

  2. Mount every user's HPC data directory on every host machine, and use something like https://bindfs.org/ to bind mount a copy inside the container, and mask the UID/GID somehow. The user inside the container stays UID 1000, the mount point appears as UID 1000, while the underlying NFS filesystem accesses use their HPC UID. Not sure if this is possible.

Any other suggestions are welcome.

Currently, I can add a regular NFS volume without problems in kubespawner using something like this in the c.KubeSpawner.profile_list function:

          if self.is_hpc:
              profiles.append({
                  'display_name': 'Test mount extra NFS volume',
                  'description': "Mounts 10.0.0.200:/testvol to /testvol",
                  'kubespawner_override': {
                      'volumes': self.volumes + [
                          {
                              'name': 'testvol',
                              'nfs': {
                                  'server': '10.0.0.200',
                                  'path': '/testvol',
                              },
                          },
                      ],
                      'volume_mounts': self.volume_mounts + [
                          {
                              'name': 'testvol',
                              'mountPath': '/testvol',
                          },
                      ],
                  },
              })

So mounting NFS volumes is fine, the UID/GID part is the only problem.

@rkevin-arch
Copy link
Member Author

Going with option 3: Kerberos.

@feltstykket
Copy link

a good starting place will be to add krb5-user to the Dockerfile

@sandertyu sandertyu mentioned this issue Jan 20, 2021
4 tasks
@rfeltstykket rfeltstykket changed the title Mounting HPC NFS volumes into user pod Investigate possibility of spawning of container with another user than the default 'jovyan' Sep 2, 2021
@rfeltstykket
Copy link

rfeltstykket commented Oct 15, 2021

Here is how to get the uid from someone given their loginid:

ldapsearch -LLL -x -h ldap.ucdavis.edu -b ou=People,dc=ucdavis,dc=edu "uid=rf" ucdPersonUUID

Here is how to get it using their email.
ldapsearch -LLL -x -h ldap.ucdavis.edu -b ou=People,dc=ucdavis,dc=edu "mail=rafeltstykket@ucdavis.edu" ucdPersonUUID

If you want to see all attributes you can see with this ldap query, you can just omit ucdPersonUUID

@TimStewartJ
Copy link
Member

I'm not super sure of how to approach this at the moment but I found these potentially helpful resources:

https://discourse.jupyter.org/t/starting-single-user-notebook-with-our-custom-ldap-docker-image/881

jupyterhub/zero-to-jupyterhub-k8s#1292

jupyterhub/zero-to-jupyterhub-k8s#1411

@rfeltstykket
Copy link

jupyterhub/zero-to-jupyterhub-k8s/issues/1292 looks like the best approach for this. Can we test this on staging with the LDAP queries above?

@hokiegeek2
Copy link

@TimStewartJ @rfeltstykket My use case is that I need to set NB_USER and NB_UID because I am using Jupyterhub-on-Kubernetes as a Slurm client. Specifically, the uid in JH must correspond to a Slurm user uid. I can set NB_USER with the following code in my zero-to-jupyterhub -k8s values.yaml:

extraConfig:
      preSpawnHook: |
          from pip._internal import main as pipmain

          # pip install and configure the Authenticator
          pipmain(['install', 'jupyterhub-nativeauthenticator'])

          from nativeauthenticator import NativeAuthenticator

          class GBRMAuthenticator(NativeAuthenticator):
            from tornado import gen
            @gen.coroutine
            def pre_spawn_start(self, user, spawner):
                auth_state = yield user.get_auth_state()
                spawner.environment = {'NB_USER':spawner.user.name, 'NB_UID':'1000'}

          c.JupyterHub.authenticator_class = GBRMAuthenticator
          c.KubeSpawner.args = ['--allow-root']
          c.Spawner.cmd = ['start.sh','jupyterhub-singleuser','--allow-root']

But when I try to change NB_UID to something other than 1000, I get the following error:

PermissionError: [Errno 13] Permission denied: '/home/jovyan/.local/share/jupyter/runtime/nbserver-48-open.html'

@TimStewartJ
Copy link
Member

Thanks for sharing your config! Our ultimate goal is to use Slurm with Jupyterhub as well. I'll take a look into this and see if I can make any progress on it.

Could you share further how you've set up Jupyterhub on Kubernetes and Slurm so far?

@feltstykket
Copy link

feltstykket commented Nov 30, 2021 via email

@hokiegeek2
Copy link

@feltstykket yup, and what's strange (I think) is that my config enables chown which I believe changes the owner of the jovyan home dir files/dirs when they are copied over to the logging in user.

@hokiegeek2
Copy link

Thanks for sharing your config! Our ultimate goal is to use Slurm with Jupyterhub as well. I'll take a look into this and see if I can make any progress on it.

Could you share further how you've set up Jupyterhub on Kubernetes and Slurm so far?

@TimStewartJ sure thing, here's my slurm-cloud-integration github project.

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