diff options
author | Scott Moser <smoser@brickies.net> | 2016-12-16 13:29:36 -0500 |
---|---|---|
committer | Scott Moser <smoser@brickies.net> | 2016-12-19 11:10:50 -0500 |
commit | ca3ae67211d907b4cfdcd685c0ae4f9530cb7da1 (patch) | |
tree | 0737429aeb0cfb5245070c9b87aa4035546b4372 /cloudinit | |
parent | c9c9197a3210ac24a039a4096214150d0e8cebb8 (diff) | |
download | vyos-cloud-init-ca3ae67211d907b4cfdcd685c0ae4f9530cb7da1.tar.gz vyos-cloud-init-ca3ae67211d907b4cfdcd685c0ae4f9530cb7da1.zip |
user-groups: fix bug when groups was provided as string and had spaces
Cloud-config provided like:
users:
- default
- name: foobar
groups: sudo, adm
Would result in adduser being called as:
useradd foobar --groups 'sudo, adm' -m
Which would cause error:
useradd: group ' adm' does not exist
The fix here is just to always normalize groups and remove whitespace.
Additionally a fix and unit tests to explicitly set system=False
or no_create_home=True. Previously those paths did not test the value
of the entry, only the presense of the entry.
LP: #1354694
Diffstat (limited to 'cloudinit')
-rwxr-xr-x | cloudinit/distros/__init__.py | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py index 1f731951..94f31f86 100755 --- a/cloudinit/distros/__init__.py +++ b/cloudinit/distros/__init__.py @@ -398,12 +398,16 @@ class Distro(object): # support kwargs having groups=[list] or groups="g1,g2" groups = kwargs.get('groups') if groups: - if isinstance(groups, (list, tuple)): - # kwargs.items loop below wants a comma delimeted string - # that can go right through to the command. - kwargs['groups'] = ",".join(groups) - else: - groups = [group.strip() for group in groups.split(",")] + if isinstance(groups, six.string_types): + groups = groups.split(",") + + # remove any white spaces in group names, most likely + # that came in as a string like: groups: group1, group2 + groups = [g.strip() for g in groups] + + # kwargs.items loop below wants a comma delimeted string + # that can go right through to the command. + kwargs['groups'] = ",".join(groups) primary_group = kwargs.get('primary_group') if primary_group: @@ -413,10 +417,10 @@ class Distro(object): for group in groups: if not util.is_group(group): self.create_group(group) - LOG.debug("created group %s for user %s", name, group) + LOG.debug("created group '%s' for user '%s'", group, name) # Check the values and create the command - for key, val in kwargs.items(): + for key, val in sorted(kwargs.items()): if key in adduser_opts and val and isinstance(val, str): adduser_cmd.extend([adduser_opts[key], val]) @@ -433,7 +437,7 @@ class Distro(object): # Don't create the home directory if directed so or if the user is a # system user - if 'no_create_home' in kwargs or 'system' in kwargs: + if kwargs.get('no_create_home') or kwargs.get('system'): adduser_cmd.append('-M') log_adduser_cmd.append('-M') else: |