How to execute kinit when startup JupyterHub

I want to execute kinit when startup Jupyterhub, so added blow code in Jupyterhub config file, but it’s not working, anyone have same issue?

def pre_spawn_hook(spawner):
keytab_path = “/home/chen/test.keytab”
principal = “chen”
kinit_cmd = f"kinit {principal} -kt {keytab_path}"
os.system(kinit_cmd)

c.Spawner.pre_spawn_hook = pre_spawn_hook

pre_spawn_hook is Python code that runs in the Hub, not inside the user server environment. You probably want to follow this pattern to launch with a script that can do any initialization you want.

2 Likes