diff options
author | Ben Howard <ben.howard@canonical.com> | 2012-08-27 16:26:46 -0600 |
---|---|---|
committer | Ben Howard <ben.howard@canonical.com> | 2012-08-27 16:26:46 -0600 |
commit | c8cca3cc82c3c446c49bf23ff6e2805f2aaeef48 (patch) | |
tree | c6c1033a29b2575eea00de0636d671a1224702c1 /cloudinit | |
parent | b81d5ed43e7ebed1d11d4b4109e22e9954316d4c (diff) | |
download | vyos-cloud-init-c8cca3cc82c3c446c49bf23ff6e2805f2aaeef48.tar.gz vyos-cloud-init-c8cca3cc82c3c446c49bf23ff6e2805f2aaeef48.zip |
Fixed critical bug where user and group creation was being done after SSH
configurations were applied. The result of this bug was that cloud-config
supplied SSH public keys would fail to apply since the configured user
may or may not exist. (LP: #1042459).
cloudinit/config/cc_ssh_import_id.py:
ssh_import_id.py now handles all user SSH import IDs.
cloudinit/distros/ubuntu.py:
Removed create_user class override as cruft, since ssh_import_id
now handles all users.
config/cloud.cfg:
Moved users_groups to run under cloud_init_modules.
doc/examples/cloud-config.txt:
Added missing documentation on user and group creation.
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/config/cc_ssh_import_id.py | 40 | ||||
-rw-r--r-- | cloudinit/distros/ubuntu.py | 18 |
2 files changed, 29 insertions, 29 deletions
diff --git a/cloudinit/config/cc_ssh_import_id.py b/cloudinit/config/cc_ssh_import_id.py index cd97b99b..4a8849c8 100644 --- a/cloudinit/config/cc_ssh_import_id.py +++ b/cloudinit/config/cc_ssh_import_id.py @@ -19,6 +19,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. from cloudinit import util +import pwd # The ssh-import-id only seems to exist on ubuntu (for now) # https://launchpad.net/ssh-import-id @@ -26,30 +27,47 @@ distros = ['ubuntu'] def handle(name, cfg, cloud, log, args): + + # import for "user: XXXXX" if len(args) != 0: user = args[0] ids = [] if len(args) > 1: ids = args[1:] - else: - user = cloud.distro.get_default_user() - if 'users' in cfg: - user_zero = cfg['users'].keys()[0] + import_ssh_ids(ids, user, log) - if user_zero != "default": - user = user_zero + # import for cloudinit created users + for user in cfg['users'].keys(): + if user == "default": + distro_user = cloud.distro.get_default_user() + d_ids = util.get_cfg_option_list(cfg, "ssh_import_id", []) + import_ssh_ids(d_ids, distro_user, log) - ids = util.get_cfg_option_list(cfg, "ssh_import_id", []) + user_cfg = cfg['users'][user] + if not isinstance(user_cfg, dict): + user_cfg = None - if len(ids) == 0: - log.debug("Skipping module named %s, no ids found to import", name) - return + if user_cfg: + ids = util.get_cfg_option_list(user_cfg, "ssh_import_id", []) + import_ssh_ids(ids, user, log) + + +def import_ssh_ids(ids, user): if not user: - log.debug("Skipping module named %s, no user found to import", name) + log.debug("Skipping ssh-import-ids, no user for ids") return + if len(ids) == 0: + log.debug("Skipping ssh-import-ids for %s, no ids to import" % user) + return + + try: + check = pwd.getpwnam(user) + except KeyError: + log.debug("Skipping ssh-import-ids for %s, user not found" % user) + cmd = ["sudo", "-Hu", user, "ssh-import-id"] + ids log.debug("Importing ssh ids for user %s.", user) diff --git a/cloudinit/distros/ubuntu.py b/cloudinit/distros/ubuntu.py index 4b3f8572..cb93f971 100644 --- a/cloudinit/distros/ubuntu.py +++ b/cloudinit/distros/ubuntu.py @@ -32,21 +32,3 @@ class Distro(debian.Distro): distro_name = 'ubuntu' default_user = 'ubuntu' - - def create_user(self, name, **kargs): - - if not super(Distro, self).create_user(name, **kargs): - return False - - if 'sshimportid' in kargs: - cmd = ["sudo", "-Hu", name, "ssh-import-id"] + kargs['sshimportid'] - LOG.debug("Importing ssh ids for user %s, post user creation." - % name) - - try: - util.subp(cmd, capture=True) - except util.ProcessExecutionError as e: - util.logexc(LOG, "Failed to import %s ssh ids", name) - raise e - - return True |