Context:
I am trying to setup JupyterHub (on a single EC2 server, HTTPS is provided via a reverse Nginx proxy URL) such that a small number of users authenticate with a 3rd party Solution (KeyCloak) and upon redirect back to the JupyterHub/Lab will automatically have a user created for them locally.
I have already correctly configured KeyCloak Authentication and a user is able to login with Keycloak and is successfully redirected back to the JupyterHub URL. However, I get 500 : Internal Server Error Unhandled error starting server <username_from_keycloak_login>
. This is expected, because the user that authenticated with KeyCloak does not yet exist on the Server hosting JupyterHub.
Problem:
This is the reason I need the user created locally, automatically. I don’t want to have to SSH into the Server hosting the JupyterHub and manually create an account for someone each time, before they plan to authenticate with KeyCloak.
Attempted Solution:
I am following this guide: “Install JupyterHub and JupyterLab from the ground up” which creates Conda environments per user where they can install whatever dependencies they want for their Python JupyterLab/Notebook.
I found the following snippet of config (for jupyterhub_config.py
) from another thread here, which automatically creates a user upon login such that a Spawner
like jupyterhub.spawner.SimpleLocalProcessSpawner
can spawn a server for that user:
def pre_spawn_hook(spawner):
username = spawner.user.name
try:
import pwd
pwd.getpwnam(username)
except KeyError:
import subprocess
subprocess.check_call(['useradd', '-ms', '/bin/bash', username])
c.Spawner.pre_spawn_hook = pre_spawn_hook
Question:
Does this play nicely with the section on user Conda environments from the guide I referenced above? Or would creating users via the code above not work with Conda? I frankly don’t care if each user that logs into Jupyter (via KeyCloak) doesn’t have a dedicated space to install any Python dependencies they may need, I just need them to have functioning accounts.