Skip to content

Commit 6c58a0e

Browse files
authored
Missing warning when no authorizer in found ZMQ handlers (#744)
1 parent 7f2863f commit 6c58a0e

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

jupyter_server/auth/decorator.py

+2-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"""
33
# Copyright (c) Jupyter Development Team.
44
# Distributed under the terms of the Modified BSD License.
5-
import warnings
65
from functools import wraps
76
from typing import Callable
87
from typing import Optional
@@ -12,6 +11,7 @@
1211
from tornado.web import HTTPError
1312

1413
from .utils import HTTP_METHOD_TO_AUTH_ACTION
14+
from .utils import warn_disabled_authorization
1515

1616

1717
def authorized(
@@ -63,17 +63,7 @@ def inner(self, *args, **kwargs):
6363

6464
# Handle the case where an authorizer wasn't attached to the handler.
6565
if not self.authorizer:
66-
warnings.warn(
67-
"The Tornado web application does not have an 'authorizer' defined "
68-
"in its settings. In future releases of jupyter_server, this will "
69-
"be a required key for all subclasses of `JupyterHandler`. For an "
70-
"example, see the jupyter_server source code for how to "
71-
"add an authorizer to the tornado settings: "
72-
"https://github.com/jupyter-server/jupyter_server/blob/"
73-
"653740cbad7ce0c8a8752ce83e4d3c2c754b13cb/jupyter_server/serverapp.py"
74-
"#L234-L256",
75-
FutureWarning,
76-
)
66+
warn_disabled_authorization()
7767
return method(self, *args, **kwargs)
7868

7969
# Only return the method if the action is authorized.

jupyter_server/auth/utils.py

+15
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@
44
# Distributed under the terms of the Modified BSD License.
55
import importlib
66
import re
7+
import warnings
8+
9+
10+
def warn_disabled_authorization():
11+
warnings.warn(
12+
"The Tornado web application does not have an 'authorizer' defined "
13+
"in its settings. In future releases of jupyter_server, this will "
14+
"be a required key for all subclasses of `JupyterHandler`. For an "
15+
"example, see the jupyter_server source code for how to "
16+
"add an authorizer to the tornado settings: "
17+
"https://github.com/jupyter-server/jupyter_server/blob/"
18+
"653740cbad7ce0c8a8752ce83e4d3c2c754b13cb/jupyter_server/serverapp.py"
19+
"#L234-L256",
20+
FutureWarning,
21+
)
722

823

924
HTTP_METHOD_TO_AUTH_ACTION = {

jupyter_server/base/zmqhandlers.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from tornado.websocket import WebSocketHandler
2222

2323
from .handlers import JupyterHandler
24+
from jupyter_server.auth.utils import warn_disabled_authorization
2425

2526

2627
def serialize_binary_message(msg):
@@ -320,7 +321,10 @@ def pre_get(self):
320321
raise web.HTTPError(403)
321322

322323
# authorize the user.
323-
if not self.authorizer.is_authorized(self, user, "execute", "kernels"):
324+
if not self.authorizer:
325+
# Warn if there is not authorizer.
326+
warn_disabled_authorization()
327+
elif not self.authorizer.is_authorized(self, user, "execute", "kernels"):
324328
raise web.HTTPError(403)
325329

326330
if self.get_argument("session_id", False):

jupyter_server/terminal/handlers.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from ..base.handlers import JupyterHandler
99
from ..base.zmqhandlers import WebSocketMixin
1010
from jupyter_server._tz import utcnow
11+
from jupyter_server.auth.utils import warn_disabled_authorization
1112

1213
AUTH_RESOURCE = "terminals"
1314

@@ -28,7 +29,11 @@ def get(self, *args, **kwargs):
2829
if not user:
2930
raise web.HTTPError(403)
3031

31-
if not self.authorizer.is_authorized(self, user, "execute", self.auth_resource):
32+
# authorize the user.
33+
if not self.authorizer:
34+
# Warn if there is not authorizer.
35+
warn_disabled_authorization()
36+
elif not self.authorizer.is_authorized(self, user, "execute", self.auth_resource):
3237
raise web.HTTPError(403)
3338

3439
if not args[0] in self.term_manager.terminals:

0 commit comments

Comments
 (0)