Prunus Cerasus
Prunus Cerasus

Reputation: 91

How to elegantly bypass Jupyter notebook password requirement when already authenticated by another service

I have implemented a simple website where user can log in/register via some existing service (e.g Google). After log in a user can manage his Jupyter notebook - open/delete. Basically a user has an account where he can access his notebook. The website and Jupyter notebook are containerized by Docker and organized by Kubernetes.

Now the problem is to bind authentication of a user via Google to access Jupyter notebook without requiring Jupyter notebook token/password from user. It is a problem because URL at which container with Jupyter notebook is running is known and accessible by anyone (so disabling password is not an option).

I tried to search for a way to make the container running at certain URL link accessible only by redirect from other website (in my case it would be user account page) but I haven't found a way. Also I was thinking about writing the Jupyter notebook token on the home screen after deploying notebook for every user with option to set the password for notebook but it seems to me very annoying to ask user for Google password and straight after password/token to notebook.

So I would like to know if there is an efficient way to bind authentication via Google with access to Juypter notebook with requiring only authentication via Google.

Upvotes: 2

Views: 460

Answers (1)

Prunus Cerasus
Prunus Cerasus

Reputation: 91

I found a working solution to my problem.

I generated my own token with python library secrets. This token I passed as environment variable to container with Jupyter notebook (JUPYTER_TOKEN). So the Jupyter notebook uses this token as it's default. Now I can redirect user from website to Jupyter notebook using manually generated token.

Simply:

  1. Generate token
  2. Deploy Jupyter notebook container with token as env variable
  3. Redirect user to https://{JUPYTER}.com/?token={TOKEN}

Where JUPYTER is a place where jupyter notebook container is running and TOKEN is manually generated token. This way user is redirected without requiring of manually typing password. Also no one from outside of internet without knowledge of this token can't get access to Jupyter notebook.

Upvotes: 1

Related Questions