Influencing named server name from spawner

We encourage users to drop SSH keys into shared “project” accounts on our HPC system which lets them share data, code, etc. without having to deal with shared directories and chmod, chown, sticky bits, and umasks. To enable similar authentication functionality in JupyterHub, I’ve written a proof-of-concept proxy authenticator that permits users to authenticate as themselves but login as their project account. I’d like for these users to be able to start named servers, named after the user they are authenticating as, which is preserved in the auth state. (e.g. named something like proxy-{actual_authed_user}) This is basically to prevent them from colliding with one another in the default/unnamed server.

However I don’t think there is a way to influence the server name right now, outside of the UI where people can manually specify it. I think I’d just want to be able to spawn/visit a specific named server for them (go directly to SpawnHandler), bypassing the named server list. This means being able to tack on the escaped server name to the URLs at

            url = url_path_join(self.base_url, 'user', user.escaped_name)
            url = url_path_join(self.hub.base_url, 'spawn', user.escaped_name)

Does it make sense for the spawner to be able to influence the server name? If so, what would be the right approach? For the time being can I override the HomeHandler, and use the info I’ve stashed in auth_state to build the URL?

Related: Named servers via UI · Issue #1935 · jupyterhub/jupyterhub · GitHub

This is tricky, because the Spawner object does not exist until the name has been chosen (via the URL). We could potentially use the ‘default’ server (name='') and allow it to rename itself. It’s not impossible, it should involve:

  1. deciding when the Spawner can pick its own name
  2. if changed, update the name field in the database
  3. trigger redirect to the same page for the new name, so we’re back where we started with the correct name. This might get hairy, because where the redirect is triggered might be far away!

However, perhaps the simplest is setting the default URL (c.JupyterHub.default_url)? This sets the URL a user goes to immediately after login, if another page is not specified. This can be a callable that returns a url, e.g. /spawn/:username/:servername. I think it currently can’t be async, though, which means auth_state is unavailable :/. default_url also does not affect things like the ‘start my server’ button.

Maybe the simplest is a new config option that, like default_url, sets the default server name. This can be an (async) callable that only returns a server name, and could affect all paths to the default server. Putting it on Spawner makes some logical sense, but because objects need to be instantiated to load config, it may be cleaner to put it on a global JupyterHub.default_server_name (plus, then it would be next to `default_url).

1 Like