Added support for consistent UIDs at user creation time

This commit is contained in:
Rick Gerkin
2019-08-16 04:59:51 +00:00
parent 915664ede2
commit cda7f73cfa

View File

@@ -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()