userless conf fails assign user[0] as the default user

Bug #1041384 reported by Ben Howard
4
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cloud-init
Fix Released
High
Unassigned

Bug Description

The userles merge fails to properly assign user[0] as the default user due to default configuration and the way that cloud-init merges the ondisk configuration with the cloud-config sent by the user.

cloud-init/config/cloud.cfg (Default configuration)
  4 # Implement for Ubuntu only: create the default 'ubuntu' user
  5 users:
  6 default: true
  7

If a user launches with the cloud config of:
users:
    foo: True

The expected behavior is that user foo would be configured equivalent to the parameter "user: foo".

However, due to this code and the default configuration:
cloud-init/cloudinit/stages.py
164
165.....def _read_cfg(self, extra_fns):
166.........no_cfg_paths = helpers.Paths({}, self.datasource)
167.........merger = helpers.ConfigMerger(paths=no_cfg_paths,
168.......................................datasource=self.datasource,
169.......................................additional_fns=extra_fns,
170.......................................base_cfg=self._read_base_cfg())
171........return merger.cfg

cloud-init generates the user lists as:
users:
    default: True
    foo: True

So what is happening is the default configuratoin is merged with the cloud-config.

Effectively this means that regardless of the user configuration send in the cloud-config:
  - The ubuntu user will always be created on a Ubuntu systems
  - The ubuntu user is always user[0]
  - Any configured user is user[n+1], and therefore will not be uzer[0]
  - A cloud-config of "user: default: false" will be ignored.

IMHO, this is a pretty serious bug.

Related branches

Changed in cloud-init:
status: New → Confirmed
summary: - userless configuration fails due to default configuration
+ userless conf fails assign user[0] as the default user
description: updated
description: updated
description: updated
Revision history for this message
Ben Howard (darkmuggle-deactivatedaccount) wrote :

Filed MP: #121295 as a potential fix.

Revision history for this message
Ben Howard (darkmuggle-deactivatedaccount) wrote :

Note, this bug appears to affect other cloud-config options that have a default option set.

Revision history for this message
Scott Moser (smoser) wrote :

What you're running into is really just a generic limitation of the merge routine that cloud-init uses. We had hoped to improve the function of this merge routine at Bug 1023179, but have not implemented this yet.

I don't think its really safe or desirable to change this at the moment.

A more reasonable change I think is to change the users and groups to be lists of dicts rather than a dict of dicts.
dicts get added to or updated, but lists get replaced. So, if your default config entry is a list rather than a dict, then the user's value will entirely replace the list.

Ie:
groups:
  - ubuntu: [foo,bar]
  - cloud-users
users:
 - name: ubuntu

you could also allow for the case where an entry in the ''users" list is a string:
users:
 - default

basically, then the presense of the 'default' user in the users list would trigger creation of the "default" user.

Scott Moser (smoser)
Changed in cloud-init:
importance: Undecided → High
assignee: nobody → Ben Howard (utlemming)
Revision history for this message
Ben Howard (darkmuggle-deactivatedaccount) wrote :

This was fixed in r641. Marking as fixed released.

Changed in cloud-init:
status: Confirmed → Fix Released
Revision history for this message
James Falcon (falcojr) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.