jupyterhub / the-littlest-jupyterhub

Simple JupyterHub distribution for 1-100 users on a single server
https://tljh.jupyter.org
BSD 3-Clause "New" or "Revised" License
1.04k stars 340 forks source link

Admin user names are parsed as integers when they correspond to numbers #589

Open jtpio opened 4 years ago

jtpio commented 4 years ago

Bug description

Expected behaviour

It should be possible to add admin users identified as numbers via tljh-config.

Actual behaviour

Doing so yields an error (see traceback below)

How to reproduce

  1. Use LTIAuthenticator
  2. Add a user as admin: sudo tljh-config add-item users.admin "9" (users are numbers with LTI)
  3. Reload the hub with tljh-config reload hub
  4. JupyterHub fails to reload with the following stack trace:
Jun 23 17:11:14 jhub3 python3[442251]: [E 2020-06-23 17:11:14.041 JupyterHub app:2718]
Jun 23 17:11:14 jhub3 python3[442251]:     Traceback (most recent call last):
Jun 23 17:11:14 jhub3 python3[442251]:       File "/opt/tljh/hub/lib/python3.8/site-packages/jupyterhub/app.py", line 2715, in launch_instance_async
Jun 23 17:11:14 jhub3 python3[442251]:         await self.initialize(argv)
Jun 23 17:11:14 jhub3 python3[442251]:       File "/opt/tljh/hub/lib/python3.8/site-packages/jupyterhub/app.py", line 2286, in initialize
Jun 23 17:11:14 jhub3 python3[442251]:         await self.init_users()
Jun 23 17:11:14 jhub3 python3[442251]:       File "/opt/tljh/hub/lib/python3.8/site-packages/jupyterhub/app.py", line 1614, in init_users
Jun 23 17:11:14 jhub3 python3[442251]:         admin_users = [
Jun 23 17:11:14 jhub3 python3[442251]:       File "/opt/tljh/hub/lib/python3.8/site-packages/jupyterhub/app.py", line 1615, in <listcomp>
Jun 23 17:11:14 jhub3 python3[442251]:         self.authenticator.normalize_username(name)
Jun 23 17:11:14 jhub3 python3[442251]:       File "/opt/tljh/hub/lib/python3.8/site-packages/jupyterhub/auth.py", line 325, in normalize_username
Jun 23 17:11:14 jhub3 python3[442251]:         username = username.lower()
Jun 23 17:11:14 jhub3 python3[442251]:     AttributeError: 'int' object has no attribute 'lower'

Your personal set up

Workaround

A workaround is to specify the list of admin users explicitely as strings in the JupyterHub config with:

c.Authenticator.admin_users = { '9' }
jtpio commented 4 years ago

It looks like this is coming from the parse_value function which automatically converts the string to the appropriate type:

https://github.com/jupyterhub/the-littlest-jupyterhub/blob/0b81d7e3fa93a2b25f0891d83d46b27e3b07ca1e/tljh/config.py#L273-L287

consideRatio commented 3 years ago

I've seen the equivalent issue for the helm CLI resolved as a --set-string alongside the more commonly used --set.

I'm not sure how to go about handling this situation as it's a bit too convoluted in my mind if we would track what value that the user tries to set or add an item to... Well... Unless we have a schema for it at least, hmmm...

I've opened #725 to track the need for adding a JSONSchema for the tljh configuration file.