mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-24 12:05:22 +08:00
Allow toggling auth for prometheus metrics
Equivalent to https://github.com/jupyterhub/jupyterhub/pull/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.
This commit is contained in:
parent
cd7a06ce88
commit
c0ab18a534
@ -914,8 +914,10 @@ class PrometheusMetricsHandler(IPythonHandler):
|
||||
"""
|
||||
Return prometheus metrics for this notebook server
|
||||
"""
|
||||
@web.authenticated
|
||||
def get(self):
|
||||
if self.settings['authenticate_prometheus'] and not self.logged_in:
|
||||
raise web.HTTPError(403)
|
||||
|
||||
self.set_header('Content-Type', prometheus_client.CONTENT_TYPE_LATEST)
|
||||
self.write(prometheus_client.generate_latest(prometheus_client.REGISTRY))
|
||||
|
||||
|
@ -283,6 +283,7 @@ class NotebookWebApplication(web.Application):
|
||||
disable_check_xsrf=jupyter_app.disable_check_xsrf,
|
||||
allow_remote_access=jupyter_app.allow_remote_access,
|
||||
local_hostnames=jupyter_app.local_hostnames,
|
||||
authenticate_prometheus=jupyter_app.authenticate_prometheus,
|
||||
|
||||
# managers
|
||||
kernel_manager=kernel_manager,
|
||||
@ -1551,6 +1552,13 @@ class NotebookApp(JupyterApp):
|
||||
is not available.
|
||||
"""))
|
||||
|
||||
authenticate_prometheus = Bool(
|
||||
True,
|
||||
help=""""
|
||||
Require authentication to access prometheus metrics.
|
||||
"""
|
||||
).tag(config=True)
|
||||
|
||||
# Since use of terminals is also a function of whether the terminado package is
|
||||
# available, this variable holds the "final indication" of whether terminal functionality
|
||||
# should be considered (particularly during shutdown/cleanup). It is enabled only
|
||||
|
Loading…
Reference in New Issue
Block a user