I’m installing jupyterhub in a swarm cluster, with LTI authentication via Moodle
For this, I use dockerspawner.
Containers must use homes from another platform, available from an nfs server. To do this, I want to start the individual contents using extra_container_spec, then providing a UID that I calculate based on the ID provided by moodle (which corresponds to spawner.user.name).
For example, for a moodle ID equal to 1, I add 1000 to obtain a UID of 1001. the container then starts with ID 1001 which corresponds to the owner of the desired home.
So, in jupyterhub_config.py, the extra_container_spec method is described like this:
You can inject the user parameter directly into the spawner environment which will be eventually merged with extra_container-spec. You can make c.Spawner.environment a callable to get spawner.user.name which corresponds to your moodle ID. Check this topic on how to do it.
To debug, I tried to simplify by forcing a static uid, just to see if that already worked:
c.Spawner.environment = {
'USER_ID' : '1001',
}
…But it doesn’t work…
If I understood correctly, there is no need to force a new UID when calling the extra_container_spec method… right?
So, there is no more need of these lines:
c.SwarmSpawner.extra_container_spec = {
'user': <my id that i can not get in jypyterhub_config.py>,
}
I have looked into it too quickly. Well, the solution of injecting user ID into spawner environment wont work as user arg in ContainerSpec that needs to be passed using extra_container_spec. Sorry about wrong lead.
Seems like dockerSpawner have extra_create_kwargs that takes a callable as input but SwarmSpawner does not expose such a config parameter. Well, in this case you can create a custom spawner subclassing from SwarmSpawner something like below in your jupyterhub_config.py
with your code, but the hub failed to start with the logs:
| [C 2024-04-04 12:53:03.475 JupyterHub application:115] Bad config encountered during initialization: The 'spawner_class' trait of <jupyterhub.app.JupyterHub object at 0x7f118146a410> instance must be a type, but 'MySwarmSpawner' could not be imported
Now, my containers start with the good linux uid and access the desired home folder.
The goal was to permit the users of my new jupyterhub/swarm to access the common home of the old jupyterhub/tljh (the swarm version will be tested during some months).
So, i will surely come back soon to customise tljh for fixing the uid too and ensure that any moodle user will have the same uid on each platform.
thanks again!
So, to recap, here is the code to put in jupyterhub_config.py:
from dockerspawner import SwarmSpawner
class MySwarmSpawner(SwarmSpawner):
def create_object(self):
uid = int(self.user.name) + 1000
self.extra_container_spec.update({"user": str(uid)})
return super().create_object()
c.JupyterHub.spawner_class = MySwarmSpawner