Skip to content

Commit 5a73a8e

Browse files
authored
Merge pull request #5870 from yuvipanda/authenticate-prometheus
Allow toggling auth for prometheus metrics
2 parents cd7a06c + c0ab18a commit 5a73a8e

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)