JupyterHub /educational purposes/ --allow-root execution

Hello,

I am using JupyterHub for educational purposes. I have installed the JupyterHub on my own serever (Ubuntu 20.04). I integrate an network simulator (mininet) with notebook to be used in a classroom. Mininet needs to be invoked by sudo. The integration works correctly with jupyter notebook with the below command:

sudo jupyter notebook --all-root

However, with jupyterhub, the cells can not be executed as sudo is required in the mininet calls. I have tried the below tutorial, but no success.

https://jupyterhub.readthedocs.io/en/stable/reference/config-sudo.html

Is there any feasible solution to include –allow-root with jupyterhub execution?

You haven’t given much information on your JupyterHub setup, but assuming you’re using the local spawner running all singleuser servers as root is liable to cause conflicts, since it means multiple users will be running notebooks and other commands as root, and using the same directories.

However, with jupyterhub, the cells can not be executed as sudo is required in the mininet calls.

Could you expand on this? Do you mean the notebook cells run shell commands prefixed with sudo? Or do you mean the notebook must be run as the system root user?

1 Like

Sorry for not provding detailed info.

The first part of your assumption is correct.

I will execute the Python script in cells, which probably runs the mininet as mn. The execution of mininet needs sudo (i.e., sudo mn). In jupyter notebook: as mentioned, it was solved by executing the jupyter via --allow-root.

Update 1: I also made some changes for users to execute “mn” without needing sudo by changing the sudoers file; however, it was not successful with executing the cell in jupyter hub.

Example of running code in a cell:

'Example for Handover'

import sys

from mininet.log import setLogLevel, info

from mn_wifi.cli import CLI

from mn_wifi.net import Mininet_wifi

"Create a network."

net = Mininet_wifi()

info("*** Creating nodes\n")

sta1_args, sta2_args = {}, {}

sta1_args['position'], sta2_args['position'] = '20,30,0', '60,30,0'

sta1 = net.addStation('sta1', mac='00:00:00:00:00:01', **sta1_args)

sta2 = net.addStation('sta2', mac='00:00:00:00:00:02', **sta2_args)

ap1 = net.addAccessPoint('ap1', ssid='ssid-ap1', channel='1', position='15,30,0')

c1 = net.addController('c1')

net.setPropagationModel(model="logDistance", exp=5)

info("*** Configuring wifi nodes\n")

net.configureWifiNodes()

info("*** Creating links\n")

net.addLink(ap1, ap2)

net.plotGraph(max_x=100, max_y=100)


info("*** Starting network\n")

net.build()

c1.start()

ap1.start([c1])

ap2.start([c1])