mirror of
https://github.com/jupyterhub/the-littlest-jupyterhub.git
synced 2025-12-18 21:54:05 +08:00
Prefix user accounts we create
- Helps protect against users named 'root' - Makes it clearer that you should not rely on these users for general PAM work, because they are prefixed. Fixes #9
This commit is contained in:
@@ -49,6 +49,7 @@ def apply_yaml_config(path, c):
|
||||
update_userlists(c, tljh_config)
|
||||
update_limits(c, tljh_config)
|
||||
update_user_environment(c, tljh_config)
|
||||
update_user_account_config(c, tljh_config)
|
||||
|
||||
|
||||
def update_auth(c, config):
|
||||
@@ -102,6 +103,10 @@ def update_user_environment(c, config):
|
||||
c.Spawner.default_url = '/nteract'
|
||||
|
||||
|
||||
def update_user_account_config(c, config):
|
||||
c.SystemdSpawner.username_template = 'jupyter-{USERNAME}'
|
||||
|
||||
|
||||
def _merge_dictionaries(a, b, path=None, update=True):
|
||||
"""
|
||||
Merge two dictionaries recursively.
|
||||
|
||||
@@ -8,20 +8,23 @@ from tljh import user, configurer
|
||||
INSTALL_PREFIX = os.environ.get('TLJH_INSTALL_PREFIX')
|
||||
USER_ENV_PREFIX = os.path.join(INSTALL_PREFIX, 'user')
|
||||
|
||||
|
||||
class CustomSpawner(SystemdSpawner):
|
||||
def start(self):
|
||||
"""
|
||||
Perform system user activities before starting server
|
||||
"""
|
||||
# FIXME: Move this elsewhere? Into the Authenticator?
|
||||
user.ensure_user(self.user.name)
|
||||
user.ensure_user_group(self.user.name, 'jupyterhub-users')
|
||||
system_username = 'jupyter-' + self.user.name
|
||||
user.ensure_user(system_username)
|
||||
user.ensure_user_group(system_username, 'jupyterhub-users')
|
||||
if self.user.admin:
|
||||
user.ensure_user_group(self.user.name, 'jupyterhub-admins')
|
||||
user.ensure_user_group(system_username, 'jupyterhub-admins')
|
||||
else:
|
||||
user.remove_user_group(self.user.name, 'jupyterhub-admins')
|
||||
user.remove_user_group(system_username, 'jupyterhub-admins')
|
||||
return super().start()
|
||||
|
||||
|
||||
c.JupyterHub.spawner_class = CustomSpawner
|
||||
|
||||
c.JupyterHub.port = 80
|
||||
|
||||
Reference in New Issue
Block a user