How to enable shared trust in Jupyter notebook? - python

In our group we have a common Jupyter server running on a machine in the local network. Two or three people write and edit notebooks collaboratively using their individual PCs and browsers.
Now the Jupyter/IPython security model does not trust notebooks written by others unless you explicitly enable trust (therefore re-writing the notebook).
How can my colleagues open a notebook which I authored without re-writing the key in the notebook?
The manual provides a tiny hint that one can use
c.NotebookApp.secret_file = "/path/to/notebook_secret"
to share trust but is short on details how this should work in practice. Where does the notebook_secret file be stored, on the common server or on each client PC? Where do add this code, in each notebook or in a common configuration file?

Related

Python Jupyter Notebook expose local data in the web?

I'm a total noob at Python, I just downloaded Anaconda and started to use Jupyter Notebook.
I was wondering: since Jupyter Notebook looks web based, should I have any privacy concerns using it? i.e. are the data on my pc exposed out in the web?
You probably shouldn't worry about running notebooks on your localhost. If you want more info (e.g. if you ever intend to run your notebook at a remote server), this link will give you some insight regarding security concerns.
TL;DR: no, your data are not exposed.

How to allow users to run jupyter notebooks stored in my database on my server?

I have a problem and I need a hint how to approach the problem.
I have django application, in which I have sme jupyter notebooks stored in my database. At this point, users can download notebooks and run them on their compuers.
I would like to add functionality, where user could run notebook online. I was thinking of two solutions:
first one is to use some free to use online service, like google colab, but I haven't found any with api where I could send file from my database (maybe you know about some?),
second is to run jupyter hub on my server. I saw how to run jupyter hub remotely, but I don't know how to grant users the access, so they can run notebooks simultaneously, and they don't have access to server itself thorugh it, and do all of this in django.
Do you have any hints that could help me get this functionality?
JupyterHub is a good approach if you trust your users. However, if you want to run untrusted code (like Google Colab does), you need sandboxing. In that case, you can use a Docker image to run notebooks. For example, mikebirdgeneau/jupyterlab. And there is a docker-compose file example: https://github.com/mikebirdgeneau/jupyterlab-docker/blob/master/docker-compose.yml

Hosting interactive jupyter notebook on private website

I currently run a personal website using Wordpress (but hosted on siteground) that is a set of engineering study guides. I would like to move towards making these study guides interactive (i.e. refreshing graphics based on sliders, doing basic calculations to indicate if a design works or not, so I need numpy). A friend recommended that I utilize Jupyter notebooks for this purpose, as you can both render LaTeX (which I'm currently using Mathjax with Wordpress to do), as well as have the types of interactive graphics I want using either Bokeh or Plotly.
While I've seen tutorials for sharing notebooks on specific servers, what I'm after is being able for others to run my notebook in their browser (read-only), where the notebook is privately hosted.
I'm still not sure if Jupyter is the correct avenue to accomplish what I want, so I'm open to other suggestions (someone also recommended using Julia, but I've seen fewer examples of this).
I agree with your friend that Jupyter Notebooks is an excellent approach. And while it's by no means the only method to accomplish what you're after, I'm hard-pressed to come up with an immediate alternative that doesn't require significant work to set up.
I can think of three primary methods of using Jupyter Notebooks which suit your needs:
1. Azure Notebooks
Microsoft has a new service called Azure Notebooks, which is (currently) totally free.
Azure Notebooks boasts the complete functionality of Jupyter Notebooks, and in addition to Python, users can also program cells in R and F#. As for typical usage of the service, here's a snippet from their FAQ:
Jupyter (formerly IPython), is a multi-lingual REPL on steroids. This is a free service that provides Jupyter notebooks along with supporting packages for R, Python and F# as a service. This means you can just login and get going since no installation/setup is necessary. Typical usage includes schools/instruction, giving webinars, learning languages, sharing ideas, etc. The service is provided by the Python team # Microsoft, which is part of the Data Group.
2. nbviewer
The top banner of the main Jupyter site contains a link link to an application called nbviewer.
Evidently, you can create your markdown / Jupyter syntax as a discrete page somewhere else, feed the URL to your page into nbviewer, and it'll render it for you right there in the results. If I were going to use this, I would either;
Create a discrete WordPress page for my Jupyter syntax, then feed that into nbviewer; or, more likely
Use GitHub to host my Jupyter Notebook pages (mainly for posterity and version control, over the Gist option), and use the raw text link as the source to feed into nbviewer.
3. Hosting Your Own Solution
If you're technically savy enough, I'd recommend this approach over nbviewer.
When you launch Jupyter Notebooks on your own machine, you access it through your browser using the default URL of http://localhost:8888. That means there must exist some mechanism to expose that port to external users, and allow them to have access to your Notebook, using the exact same interface. Two methods of doing so:
Using Jupyter Notebooks public server
Remotely accessing your normal Jupyter Notebook
Hope that helps! I'm curious to know if any of these options works out for you.
The Iodide Project (and subsequently, Pyodide) are two projects that aim to allow this. They're still in development, but might be worth looking into.
You can try to use Mercury framework. It allows you to transform notebooks into web applications (with interactive widgets). You need to add YAML header to the beginning of the notebook. Based on YAML the widgets will be generated. Your users can change widgets values and click Run button to execute the notebook with new inputs. You can decide whether to show or hide code for your users. You can serve multiple notebooks with Mercury on single server. It is based on Django so can be easily deployed on any server/cloud.
The example notebook:
The generated application for the above notebook:
The screenshot of app/notebooks gallery in the Mercury:

Simplest Way to Serve Jupyter Incubator Dashboards Locally

I've been exploring steps one and two from the Jupyter Incubator Dashboards project (more information here: https://github.com/jupyter-incubator/dashboards/wiki). Its simple to turn my notebooks into usable dashboards, which is just great.
My problem is that I'm unsure about step three, which is sharing/hosting the dashboards. I'm in an enterprise environment with a local server. I need to be able to share the dashboards on the local server and then have people access them over the web. Essentially, I need the "deploy as a local dashboard" option from step two (dashboards_bundlers). It seems that this functionality is now deprecated, however.
My question is this, is there a simple way to share dashboards locally here? I've been looking at the dashboards_server application, but it looks a little over my head right now. The functionality here looks powerful, but is probably more than what we need for the time being.
If this is the only option then I will proceed there, but I wanted to see if anyone has a simpler solution first.
As I see you have posted the similar question on the Github Issues section of Jupyter
You have received the answer too but is not satisfactory I guess. As the person have mentioned that there isn't any way right now for achieving what you are expecting.
But if you want that others should access the local copy of your system Jupyter Dashboard then it is better you make your system as server itself. Then you can grant access to the people for viewing your server/local machine. Others can be a child like systems for your local system.
Just like a Parent-child or Say Master-slave would allow others to have access to your Jupyter DashBoard Copy.
It might be a bit confusing but this is way you can achieve whaht you have mentioned in your question.
This might be a too simplistic answer. Our company uses Windows 7 enterprise. I have Jupyter Notebook running on a desktop which I access by running the command:
jupyter.exe notebook --ip=10.106.166.180 --no-browser
I just use the IP address of my host computer.
Then I just send people the ipynb url
example http://10.106.166.180:8888/notebooks/Notebooks/sample.ipynb
As long as you don't mind people tinkering, using or snooping around your notebooks. Also if the time comes, you can always restart the server then add a password so that people can't access it anymore.

Is JupyterHub kernel safe across users?

I'm using JupyterHub to share computational power of a big computer among some users. The software that's primarily used is a ctypes extension Python script that uses a sophisticated C/C++ code. This code isn't invulnerable to memory problems and crashes.
My question is: If a low-level problem happens with one user and his kernel gets, say, a segmentation fault, will that crash the main server by design and get all users to lose their kernel information? Or is it designed to create a new server for every user that logs in, so that such problems don't happen?
Even if you were using straight Jupyter Notebook instead of JupyterHub, each kernel is a single process, that runs kind of independent of the notebook server. Crashes of individual kernels will not take down the notebook server.
Check out the architecture documentation. We've been running a setup with a single Jupyter Notebook instance (not even JupyterHub, because Windows :/) for about 3 years now. The only problems occuring are due to resource constraints (e.g. single kernel takes up a lot of memory), but that's solvable on both the OS and organisational level.

Categories