Selectively Hide a Kernel

Sorry for cross-posting, but I need really help with this!


I,m trying to selectively hide a kernel based on a whitelist. So far, I have something like this:

c = get_config()
c.KernelSpecManager.whitelist = {...}
if jupyterhub_user in MATLAB_USERS:
    c.KernelSpecManager.whitelist += "matlab_kernel"

From my understanding so far, this needs to somehow be done in the Spawner…? But maybe I am getting mixed up.

I think what I actually want to do is something with “scopes” in the role dictionary. I’m not entirely sure though.

How would one best go about configuring this? Effectively I want a kernel (and a server proxy application) to be available to a specific group of users which I can administer via a whitelist.

Thanks for any hints!

Seems like KernelSpecManager.whitelist has been deprecated in favour of KernelSpecManager.allowed_kernelspecs.

You will need to put your own logic on how to white list kernels based on usernames and/or groups and/or roles in the Spawner. Once you have the list of allowed_kernelspecs, you can pass it to c.Spawner.args like ["--KernelSpecManager.allowed_kernelspecs", "<kernel1>", "--KernelSpecManager.allowed_kernelspecs", "<kernel2>"]. Note that you can pass this argument multiple times.


Aha! That was exactly what I was looking for. I knew it needed to be in the Spawner somewhere, the kernel I want to selectively hide now disappears as I wanted. Now just the server proxy app, but that’s a separate topic.

Thank you so much!


Follow up question, maybe I just can’t find it easily: The Spawner object knows about self.user. But does the User object somehow have any idea about which groups it belongs to?