Force a specific UID at user creation with TLJH

Hello everyone,
After setting up a version of Jupyterhub based on Swarm (see here for those interested: Get username with dockerspawner ), I am now working on the question of access to a common home folder:
On the jupyterhub/Swarm platform, Containers are now able to start with a uid that is determined and specific to each user who thus obtains access to their home.
Now, I want to provide access to this same folder for each user from another platform: The Littlest JupyterHub distribution (TLJH).
Both platforms are connected to the same LMS (moodle) via ltiauthenticator (this ensures the users to have the same login on both jupyterhub/swarm and TLJH). I would like that on TLJH, the uids are not assigned by order of arrival, but by a calculation which ensures the same uid on each platform and corresponding to the one owning the home.
So, on jupyterhub/swarm, the assignment of a uid has been defined as follows: 1000 + moodle id = uid (for example, for a moodle id = 1, uid is 1001).
So I’m currently looking to force the assignment of a uid calculated in this way on TLJH.
I suppose it is necessary to add code in jupyterhub_config.py or overload a SystemdSpawner class (I specify that the spawner defined is UserCreatingSpawner in this distribution).
Has anyone a solution or an idea ?

SystemdSpawner uses the UID and GID of Linux system users. So, it is not possible to assign dynamic UID and GID as you would do with the containers. A potential solution can be to create system users upon first login with the Authenticator.

You will need to create a custom Authenticator subclassing LTIAuthenticator and LocalAuthenticator and overload the adduser method to create system users with a consistent UID and GID as you do with other JupyterHub platform. Then, when SystemdSpawner spawns a notebook instance, it will have correct UID and GID as other instance and you should be able to share your common NFS share for both JupyterHub platforms

1 Like

Thank you for your response mahendrapaipuri,
My development skills do not allow me to achieve this… But while searching, I ended up finding a solution:
In the user.py file, I replaced the line

subprocess.check_call(["useradd", "--create-home", username])

by

moodle_id = str(int(username.replace('jupyter-', ''))+1000)
subprocess.check_call(["useradd", "--create-home", username, "--uid", uid])

It’s not a very elegant solution, but it does the job…
A few more tweaks to the system and I will be able to validate that everything is working properly!

I will add a little note here to confirm…

Solution confirmed!
The two platforms swarm and tljh now allow users to find their home via NFS…