Normalize unix usernames to be under 32char

JupyterHub usernames do not have this restriction,
causing user creation to fail when usernames are too large.
This commit is contained in:
yuvipanda
2018-09-12 16:46:59 -07:00
parent f163f62c89
commit 9b0248e0c3
3 changed files with 58 additions and 5 deletions

View File

@@ -7,17 +7,23 @@ import yaml
from glob import glob
from systemdspawner import SystemdSpawner
from tljh import user, configurer
from tljh import configurer, user
from tljh.config import INSTALL_PREFIX, USER_ENV_PREFIX, CONFIG_DIR
from tljh.normalize import generate_system_username
class CustomSpawner(SystemdSpawner):
class UserCreatingSpawner(SystemdSpawner):
"""
SystemdSpawner with user creation on spawn.
FIXME: Remove this somehow?
"""
def start(self):
"""
Perform system user activities before starting server
"""
# FIXME: Move this elsewhere? Into the Authenticator?
system_username = 'jupyter-' + self.user.name
system_username = generate_system_username('jupyter-' + self.user.name)
user.ensure_user(system_username)
user.ensure_user_group(system_username, 'jupyterhub-users')
if self.user.admin:
@@ -26,8 +32,7 @@ class CustomSpawner(SystemdSpawner):
user.remove_user_group(system_username, 'jupyterhub-admins')
return super().start()
c.JupyterHub.spawner_class = CustomSpawner
c.JupyterHub.spawner_class = UserCreatingSpawner
# leave users running when the Hub restarts
c.JupyterHub.cleanup_servers = False