|
| 1 | + |
| 2 | +.. _server_security: |
| 3 | + |
| 4 | +Security in the Jupyter notebook server |
| 5 | +======================================= |
| 6 | + |
| 7 | +Since access to the Jupyter notebook server means access to running arbitrary code, |
| 8 | +it is important to restrict access to the notebook server. |
| 9 | +For this reason, notebook 4.3 introduces token-based authentication that is **on by default**. |
| 10 | + |
| 11 | +.. note:: |
| 12 | + |
| 13 | + If you enable a password for your notebook server, |
| 14 | + token authentication is not enabled by default, |
| 15 | + and the behavior of the notebook server is unchanged from from versions earlier than 4.3. |
| 16 | + |
| 17 | +When token authentication is enabled, the notebook uses a token to authenticate requests. |
| 18 | +This token can be provided to login to the notebook server in three ways: |
| 19 | + |
| 20 | +- in the ``Authorization`` header, e.g.:: |
| 21 | + |
| 22 | + Authorization: token abcdef... |
| 23 | + |
| 24 | +- In a URL parameter, e.g.:: |
| 25 | + |
| 26 | + https://my-notebook/tree/?token=abcdef... |
| 27 | + |
| 28 | +- In the password field of the login form that will be shown to you if you are not logged in. |
| 29 | + |
| 30 | +When you start a notebook server with token authentication enabled (default), |
| 31 | +a token is generated to use for authentication. |
| 32 | +This token is logged to the terminal, so that you can copy/paste the URL into your browser:: |
| 33 | + |
| 34 | + [I 11:59:16.597 NotebookApp] The Jupyter Notebook is running at: http://localhost:8888/?token=c8de56fa4deed24899803e93c227592aef6538f93025fe01 |
| 35 | + |
| 36 | + |
| 37 | +If the notebook server is going to open your browser automatically |
| 38 | +(the default, unless ``--no-browser`` has been passed), |
| 39 | +an *additional* token is generated for launching the browser. |
| 40 | +This additional token can be used only once, |
| 41 | +and is used to set a cookie for your browser once it connects. |
| 42 | +After your browser has made its first request with this one-time-token, |
| 43 | +the token is discarded and a cookie is set in your browser. |
| 44 | + |
| 45 | +At any later time, you can see the tokens and URLs for all of your running servers with :command:`jupyter notebook list`:: |
| 46 | + |
| 47 | + $ jupyter notebook list |
| 48 | + Currently running servers: |
| 49 | + http://localhost:8888/?token=abc... :: /home/you/notebooks |
| 50 | + https://0.0.0.0:9999/?token=123... :: /tmp/public |
| 51 | + http://localhost:8889/ :: /tmp/has-password |
| 52 | + |
| 53 | +For servers with token-authentication enabled, the URL in the above listing will include the token, |
| 54 | +so you can copy and paste that URL into your browser to login. |
| 55 | +If a server has no token (e.g. it has a password or has authentication disabled), |
| 56 | +the URL will not include the token argument. |
| 57 | +Once you have visited this URL, |
| 58 | +a cookie will be set in your browser and you won't need to use the token again, |
| 59 | +unless you switch browsers, clear your cookies, or start a notebook server on a new port. |
| 60 | + |
| 61 | + |
| 62 | +You can disable authentication altogether by setting the token and password to empty strings, |
| 63 | +but this is **NOT RECOMMENDED**, unless authentication or access restrictions are handled at a different layer in your web application: |
| 64 | + |
| 65 | +.. sourcecode:: python |
| 66 | + |
| 67 | + c.NotebookApp.token = '' |
| 68 | + c.NotebookApp.password = '' |
| 69 | + |
| 70 | + |
1 | 71 | .. _notebook_security:
|
2 | 72 |
|
3 |
| -Security in Jupyter notebooks |
4 |
| -============================= |
| 73 | +Security in notebook documents |
| 74 | +============================== |
5 | 75 |
|
6 | 76 | As Jupyter notebooks become more popular for sharing and collaboration,
|
7 | 77 | the potential for malicious people to attempt to exploit the notebook
|
|
0 commit comments