Skip to content

Commit c0ab18a

Browse files
committed
Allow toggling auth for prometheus metrics
Equivalent to jupyterhub/jupyterhub#2224 Prometheus metrics can potentially leak information about the user, so they should be kept behind auth by default. However, for many JupyterHub deployments, they would need to be scraped by a centralized Prometheus instance that can not really authenticate separately to each user notebook without a lot of work. Admins can use this setting to allow unauthenticated access to the /metrics endpoint.
1 parent cd7a06c commit c0ab18a

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

notebook/base/handlers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,8 +914,10 @@ class PrometheusMetricsHandler(IPythonHandler):
914914
"""
915915
Return prometheus metrics for this notebook server
916916
"""
917-
@web.authenticated
918917
def get(self):
918+
if self.settings['authenticate_prometheus'] and not self.logged_in:
919+
raise web.HTTPError(403)
920+
919921
self.set_header('Content-Type', prometheus_client.CONTENT_TYPE_LATEST)
920922
self.write(prometheus_client.generate_latest(prometheus_client.REGISTRY))
921923

notebook/notebookapp.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ def init_settings(self, jupyter_app, kernel_manager, contents_manager,
283283
disable_check_xsrf=jupyter_app.disable_check_xsrf,
284284
allow_remote_access=jupyter_app.allow_remote_access,
285285
local_hostnames=jupyter_app.local_hostnames,
286+
authenticate_prometheus=jupyter_app.authenticate_prometheus,
286287

287288
# managers
288289
kernel_manager=kernel_manager,
@@ -1551,6 +1552,13 @@ def _update_server_extensions(self, change):
15511552
is not available.
15521553
"""))
15531554

1555+
authenticate_prometheus = Bool(
1556+
True,
1557+
help=""""
1558+
Require authentication to access prometheus metrics.
1559+
"""
1560+
).tag(config=True)
1561+
15541562
# Since use of terminals is also a function of whether the terminado package is
15551563
# available, this variable holds the "final indication" of whether terminal functionality
15561564
# should be considered (particularly during shutdown/cleanup). It is enabled only

0 commit comments

Comments
 (0)