From a0b6d8ec6f60877d3c90d71e564c5ef3de6e9e89 Mon Sep 17 00:00:00 2001 From: Min RK Date: Thu, 20 Feb 2020 12:12:55 +0100 Subject: [PATCH] add allow_implicit_spawn setting - warn that there are known issues associated with enabling it - it is inherently incompatible with named servers --- jupyterhub/app.py | 28 ++++++++++++++++++++++++++++ jupyterhub/handlers/base.py | 8 +++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/jupyterhub/app.py b/jupyterhub/app.py index 0bd57de7..9df85c66 100644 --- a/jupyterhub/app.py +++ b/jupyterhub/app.py @@ -917,10 +917,37 @@ class JupyterHub(Application): def _authenticator_default(self): return self.authenticator_class(parent=self, db=self.db) + allow_implicit_spawn = Bool( + False, + help="""Allow implicit spawning + + When a user visits a URL for a server that's not running, + instead of confirming the spawn request, + automatically begin the spawn process. + + Warning: not compatible with named servers, + and known to cause issues with redirect loops, + server errors, and infinitely respawning servers. + """, + ).tag(config=True) + + @validate('allow_implicit_spawn') + def _allow_named_changed(self, proposal): + if proposal.value and self.allow_named_servers: + self.log.warning("Implicit spawn cannot work with named servers") + return False + return proposal.value + allow_named_servers = Bool( False, help="Allow named single-user servers per user" ).tag(config=True) + @observe('allow_named_servers') + def _allow_named_changed(self, change): + if change.new and self.allow_implicit_spawn: + self.log.warning("Implicit spawn cannot work with named servers") + self.allow_implicit_spawn = False + named_server_limit_per_user = Integer( 0, help=""" @@ -2158,6 +2185,7 @@ class JupyterHub(Application): subdomain_host=self.subdomain_host, domain=self.domain, statsd=self.statsd, + allow_implicit_spawn=self.allow_implicit_spawn, allow_named_servers=self.allow_named_servers, default_server_name=self._default_server_name, named_server_limit_per_user=self.named_server_limit_per_user, diff --git a/jupyterhub/handlers/base.py b/jupyterhub/handlers/base.py index 77c2ae27..9910cdde 100644 --- a/jupyterhub/handlers/base.py +++ b/jupyterhub/handlers/base.py @@ -1426,11 +1426,17 @@ class UserUrlHandler(BaseHandler): # serve a page prompting for spawn and 503 error # visiting /user/:name no longer triggers implicit spawn # without explicit user action - self.set_status(503) spawn_url = url_concat( url_path_join(self.hub.base_url, "spawn", user.escaped_name, server_name), {"next": self.request.uri}, ) + if self.settings["allow_implicit_spawn"]: + self.log.warning("Allowing implicit spawn for %s", self.request.path) + self.redirect(spawn_url) + return + else: + self.set_status(503) + auth_state = await user.get_auth_state() html = self.render_template( "not_running.html",