Mikołaj Buchwald

Deprecation warning: This web page is out of date. My current web page is located at: mikolajbuchwald.com.

JupyterHub on OpenStack

17 Jun 2019

Creating an instance of a virtual machine on OpenStack that will host JupyterHub server proxied trough an Apache server.

How to setup JupyterHub server on OpenStack

The general tutorial on how to install JupyterHub is available here.

The combined commands are available here, or in sections below.

Standard system upgrade:

sudo apt-get update
sudo apt-get upgrade -y

Nodejs installation on debian (source here):

sudo apt-get install curl software-properties-common
curl -sL https://deb.nodesource.com/setup_10.x | sudo bash -
sudo apt-get install -y nodejs nodejs-legacy

Installing the Jupyter itself:

sudo apt-get install -y python3-pip
sudo python3 -m pip install jupyterhub
sudo npm install -g configurable-http-proxy
sudo python3 -m pip install notebook

To test the installation run:

jupyterhub -h
configurable-http-proxy -h

However, this tutorial is not meant for production environment, as JupyterHub requires special privileges in order to work:

To allow multiple users to sign in to the Hub server, you must start jupyterhub as a privileged user, such as root

Hence, you are redirected to the separate wiki page, where it is explained how to run JupyterHub as a less privileged user.

Some additional resources in order to pull this of are:

  1. Creating a user with home directory (from here):
    sudo useradd -m cicero
    sudo useradd -m demosthenes
    
  2. Preventing other users from inspecting data in the specific user directory (explained here):
    sudo chmod go-rwx /home/cicero
    sudo chmod go-rwx /home/demosthenes
    

Generate passwords for users:

sudo passwd cicero
sudo passwd demosthenes

Add users to jupyterhub group

sudo addgroup jupyterhub
sudo adduser -G jupyterhub cicero
sudo adduser -G jupyterhub demosthenes

Install sudospawner:

sudo python3 -m pip install sudospawner

Use visudo to edit /etc/sudoers. You should have his in your sudoers file (source):

# Cmnd alias specification

# the command(s) the Hub can run on behalf of the above users without needing a password
# the exact path may differ, depending on how sudospawner was installed
Cmnd_Alias JUPYTER_CMD = /usr/local/bin/sudospawner

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL
%jupyterhub ALL=(cicero) /usr/bin/sudo
cicero ALL=(%jupyterhub) NOPASSWD:JUPYTER_CMD

Add user to shadow and jupyterhub groups:

sudo usermod -a -G shadow cicero
sudo usermod -a -G jupyterhub cicero

Logout and login or restart the machine

sudo shutdown -r 0

Make a Directory for JupyterHub

sudo mkdir /etc/jupyterhub
sudo chown cicero /etc/jupyterhub

Install apache:

sudo apt-get install apache2
a2enmod ssl rewrite proxy proxy_http proxy_wstunnel
sudo systemctl restart apache2

In order to generate a self-signed certificate type in the following commands (source for openssl key generation):

mkdir ~/.certs
cd ~/.certs
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mykey.key -out mycert.pem

Enable site and restart the server

sudo a2ensite jupyter.conf
sudo service apache2 restart

Note: In order for the Jupyterhub to work correctly, hou have to remove/rename/backup any existing (conflicting) Jupyter Notebook configuration at ~/.jupyter/jupyter_notebook_config.py


Last modified on 28 June 2019


Tweet