add allow_implicit_spawn setting

- warn that there are known issues associated with enabling it
- it is inherently incompatible with named servers
This commit is contained in:
Min RK
2020-02-20 12:12:55 +01:00
parent 3e17b47ec3
commit a0b6d8ec6f
2 changed files with 35 additions and 1 deletions

View File

@@ -917,10 +917,37 @@ class JupyterHub(Application):
def _authenticator_default(self): def _authenticator_default(self):
return self.authenticator_class(parent=self, db=self.db) 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( allow_named_servers = Bool(
False, help="Allow named single-user servers per user" False, help="Allow named single-user servers per user"
).tag(config=True) ).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( named_server_limit_per_user = Integer(
0, 0,
help=""" help="""
@@ -2158,6 +2185,7 @@ class JupyterHub(Application):
subdomain_host=self.subdomain_host, subdomain_host=self.subdomain_host,
domain=self.domain, domain=self.domain,
statsd=self.statsd, statsd=self.statsd,
allow_implicit_spawn=self.allow_implicit_spawn,
allow_named_servers=self.allow_named_servers, allow_named_servers=self.allow_named_servers,
default_server_name=self._default_server_name, default_server_name=self._default_server_name,
named_server_limit_per_user=self.named_server_limit_per_user, named_server_limit_per_user=self.named_server_limit_per_user,

View File

@@ -1426,11 +1426,17 @@ class UserUrlHandler(BaseHandler):
# serve a page prompting for spawn and 503 error # serve a page prompting for spawn and 503 error
# visiting /user/:name no longer triggers implicit spawn # visiting /user/:name no longer triggers implicit spawn
# without explicit user action # without explicit user action
self.set_status(503)
spawn_url = url_concat( spawn_url = url_concat(
url_path_join(self.hub.base_url, "spawn", user.escaped_name, server_name), url_path_join(self.hub.base_url, "spawn", user.escaped_name, server_name),
{"next": self.request.uri}, {"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() auth_state = await user.get_auth_state()
html = self.render_template( html = self.render_template(
"not_running.html", "not_running.html",