diff options
author | Ben Howard <ben.howard@canonical.com> | 2012-08-31 12:45:40 -0600 |
---|---|---|
committer | Ben Howard <ben.howard@canonical.com> | 2012-08-31 12:45:40 -0600 |
commit | b696c2a57821e0e1fe18400016c906b92f8c271e (patch) | |
tree | 91d6d25beded00359f318a25f9d4808cc92ed361 /cloudinit/distros | |
parent | 09cec0837a20f6cfafa520aa0ff2e484e1fd9c01 (diff) | |
download | vyos-cloud-init-b696c2a57821e0e1fe18400016c906b92f8c271e.tar.gz vyos-cloud-init-b696c2a57821e0e1fe18400016c906b92f8c271e.zip |
- Converted user list to user dict to allow exclusion of the default user
on Ubuntu systems via cloud-config (LP: #1041384).
- Fixed bug with user creation on Ubuntu where the default user groups are
not set properly (LP: #1044044).
- Fixed documentation for user creation (LP: #1044508).
Diffstat (limited to 'cloudinit/distros')
-rw-r--r-- | cloudinit/distros/__init__.py | 45 | ||||
-rw-r--r-- | cloudinit/distros/ubuntu.py | 2 |
2 files changed, 31 insertions, 16 deletions
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py index 686c6a9b..40c6aa4f 100644 --- a/cloudinit/distros/__init__.py +++ b/cloudinit/distros/__init__.py @@ -47,6 +47,7 @@ class Distro(object): __metaclass__ = abc.ABCMeta default_user = None + default_user_groups = None def __init__(self, name, cfg, paths): self._paths = paths @@ -59,16 +60,25 @@ class Distro(object): # - nopasswd sudo access user = self.get_default_user() + groups = self.get_default_user_groups() + if not user: raise NotImplementedError("No Default user") - self.create_user(user, - plain_text_passwd=user, - home="/home/%s" % user, - shell="/bin/bash", - lockpasswd=True, - gecos="%s%s" % (user[0:1].upper(), user[1:]), - sudo="ALL=(ALL) NOPASSWD:ALL") + user_dict = { + 'name': user, + 'plain_text_passwd': user, + 'home': "/home/%s" % user, + 'shell': "/bin/bash", + 'lock_passwd': True, + 'gecos': "%s%s" % (user[0:1].upper(), user[1:]), + 'sudo': "ALL=(ALL) NOPASSWD:ALL", + } + + if groups: + user_dict['groups'] = groups + + self.create_user(**user_dict) LOG.info("Added default '%s' user with passwordless sudo", user) @@ -204,6 +214,9 @@ class Distro(object): def get_default_user(self): return self.default_user + def get_default_user_groups(self): + return self.default_user_groups + def create_user(self, name, **kwargs): """ Creates users for the system using the GNU passwd tools. This @@ -220,7 +233,7 @@ class Distro(object): adduser_opts = { "gecos": '--comment', "homedir": '--home', - "primarygroup": '--gid', + "primary_group": '--gid', "groups": '--groups', "passwd": '--password', "shell": '--shell', @@ -229,10 +242,10 @@ class Distro(object): } adduser_opts_flags = { - "nousergroup": '--no-user-group', + "no_user_group": '--no-user-group', "system": '--system', - "nologinit": '--no-log-init', - "nocreatehome": "-M", + "no_log_init": '--no-log-init', + "no_create_home": "-M", } # Now check the value and create the command @@ -254,7 +267,7 @@ class Distro(object): # Default to creating home directory unless otherwise directed # Also, we do not create home directories for system users. - if "nocreatehome" not in kwargs and "system" not in kwargs: + if "no_create_home" not in kwargs and "system" not in kwargs: adduser_cmd.append('-m') # Create the user @@ -273,8 +286,8 @@ class Distro(object): self.set_passwd(name, kwargs['plain_text_passwd']) # Default locking down the account. - if ('lockpasswd' not in kwargs and - ('lockpasswd' in kwargs and kwargs['lockpasswd']) or + if ('lock_passwd' not in kwargs and + ('lock_passwd' in kwargs and kwargs['lock_passwd']) or 'system' not in kwargs): try: util.subp(['passwd', '--lock', name]) @@ -288,8 +301,8 @@ class Distro(object): self.write_sudo_rules(name, kwargs['sudo']) # Import SSH keys - if 'sshauthorizedkeys' in kwargs: - keys = set(kwargs['sshauthorizedkeys']) or [] + if 'ssh_authorized_keys' in kwargs: + keys = set(kwargs['ssh_authorized_keys']) or [] ssh_util.setup_user_keys(keys, name, None, self._paths) return True diff --git a/cloudinit/distros/ubuntu.py b/cloudinit/distros/ubuntu.py index 1f4efb59..5444cbc0 100644 --- a/cloudinit/distros/ubuntu.py +++ b/cloudinit/distros/ubuntu.py @@ -31,3 +31,5 @@ class Distro(debian.Distro): distro_name = 'ubuntu' default_user = 'ubuntu' + default_user_groups = ("adm,admin,audio,cdrom,dialout,floppy,video," + "plugdev,dip,netdev,sudo") |