From cda7f73cfa75138ae11b757fa24b861cb7cf4f61 Mon Sep 17 00:00:00 2001 From: Rick Gerkin Date: Fri, 16 Aug 2019 04:59:51 +0000 Subject: [PATCH] Added support for consistent UIDs at user creation time --- jupyterhub/auth.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/jupyterhub/auth.py b/jupyterhub/auth.py index bc906a70..0834e3d7 100644 --- a/jupyterhub/auth.py +++ b/jupyterhub/auth.py @@ -660,6 +660,15 @@ class LocalAuthenticator(Authenticator): # This appears to be the Linux non-interactive adduser command: return ['adduser', '-q', '--gecos', '""', '--disabled-password'] + uids = Dict( + help=""" + Dictionary of uids to use at user creation time. + This helps ensure that users created from the database + get the same uid each time they are created + in temporary deployments or containers. + """ + ).tag(config=True) + group_whitelist = Set( help=""" Whitelist all users from this UNIX group. @@ -762,7 +771,15 @@ class LocalAuthenticator(Authenticator): Tested to work on FreeBSD and Linux, at least. """ name = user.name - cmd = [arg.replace('USERNAME', name) for arg in self.add_user_cmd] + [name] + cmd = [arg.replace('USERNAME', name) for arg in self.add_user_cmd] + try: + uid = self.uids[name] + cmd += ['--uid', '%d' % uid] + except AttributeError: + pass + except KeyError: + self.log.warning("No UID for user %s" % name) + cmd += [name] self.log.info("Creating user: %s", ' '.join(map(pipes.quote, cmd))) p = Popen(cmd, stdout=PIPE, stderr=STDOUT) p.wait()