Skip to content

Commit ad5c1a2

Browse files
takluyverminrk
authored andcommitted
Backport PR #1972: better docs for token auth
- clearer description of defaults in help output for token - show how to get the token on the login page - add details about token auth to the security doc closes 1944 Signed-off-by: Min RK <[email protected]>
1 parent 7cb285d commit ad5c1a2

File tree

4 files changed

+101
-24
lines changed

4 files changed

+101
-24
lines changed

docs/source/changelog.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ For more detailed information, see `GitHub <https://github.com/jupyter/notebook>
1414
.. _release-4.3:
1515

1616
4.3
17-
-----
17+
---
1818

1919
4.3 is a minor release with many bug fixes and improvements.
2020

2121
Highlights:
2222

2323
- API for creating mime-type based renderer extensions using :code:`OutputArea.register_mime_type` and :code:`Notebook.render_cell_output` methods. See `mimerender-cookiecutter <https://github.com/jupyterlab/mimerender-cookiecutter>`__ for reference implementations and cookiecutter.
24-
- Enable token authentication by default
24+
- Enable token authentication by default. See :ref:`server_security` for more details.
2525
- Update security docs to reflect new signature system
2626
- Switched from term.js to xterm.js
2727

@@ -30,7 +30,7 @@ Bug fixes:
3030
- Ensure variable is set if exc_info is falsey
3131
- Catch and log handler exceptions in :code:`events.trigger`
3232
- Add debug log for static file paths
33-
- Don't check origin on token-authenticated requests
33+
- Don't check origin on token-authenticated requests
3434
- Remove leftover print statement
3535
- Fix highlighting of Python code blocks
3636
- :code:`json_errors` should be outermost decorator on API handlers

docs/source/security.rst

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,77 @@
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+
171
.. _notebook_security:
272

3-
Security in Jupyter notebooks
4-
=============================
73+
Security in notebook documents
74+
==============================
575

676
As Jupyter notebooks become more popular for sharing and collaboration,
777
the potential for malicious people to attempt to exploit the notebook

notebook/notebookapp.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,10 +517,11 @@ def _write_cookie_secret_file(self, secret):
517517
self.cookie_secret_file
518518
)
519519

520-
token = Unicode(config=True,
520+
token = Unicode('<generated>', config=True,
521521
help="""Token used for authenticating first-time connections to the server.
522522
523-
Only used when no password is enabled.
523+
When no password is enabled,
524+
the default is to generate a new, random token.
524525
525526
Setting to an empty string disables authentication altogether, which is NOT RECOMMENDED.
526527
"""

notebook/templates/login.html

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<div class="navbar-inner">
2121
<div class="container">
2222
<div class="center-nav">
23-
<p class="navbar-text nav">Password:</p>
23+
<p class="navbar-text nav">Password or token:</p>
2424
<form action="{{base_url}}login?next={{next}}" method="post" class="navbar-form pull-left">
2525
<input type="password" name="password" id="password_input" class="form-control">
2626
<button type="submit" id="login_submit">Log in</button>
@@ -30,22 +30,6 @@
3030
</div>
3131
</div>
3232
</div>
33-
{% elif login_token_available %}
34-
<div class="col-sm-6 col-sm-offset-3 text-left">
35-
<p class="warning">
36-
This notebook server has no password set,
37-
but token-authentication is enabled.
38-
39-
You need to open the notebook server with its first-time login token in the URL,
40-
or enable a password in order to gain access.
41-
The command:
42-
</p>
43-
<pre>jupyter notebook list</pre>
44-
<p>
45-
will show you the URLs of running servers with their tokens,
46-
which you can copy and paste into your browser.
47-
</p>
48-
</div>
4933
{% else %}
5034
<p>No login available, you shouldn't be seeing this page.</p>
5135
{% endif %}
@@ -58,6 +42,28 @@
5842
{% endfor %}
5943
</div>
6044
{% endif %}
45+
{% block token_message %}
46+
<div class="col-sm-6 col-sm-offset-3 text-left">
47+
<p class="warning">
48+
If this notebook server has no password set, token authentication is enabled.
49+
50+
You need to open the notebook server with its first-time login token in the URL,
51+
or enable a password in order to gain access.
52+
The command:
53+
</p>
54+
<pre>jupyter notebook list</pre>
55+
<p>
56+
will show you the URLs of running servers with their tokens,
57+
which you can copy and paste into your browser. For example:
58+
</p>
59+
<pre>Currently running servers:
60+
http://localhost:8888/?token=c8de56fa... :: /Users/you/notebooks
61+
</pre>
62+
<p>
63+
Or you can paste just the token value into the password field on this page.
64+
</p>
65+
</div>
66+
{% endblock token_message %}
6167
</div>
6268

6369
{% endblock %}

0 commit comments

Comments
 (0)