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/config/cc_ssh_import_id.py | |
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/config/cc_ssh_import_id.py')
-rw-r--r-- | cloudinit/config/cc_ssh_import_id.py | 40 |
1 files changed, 29 insertions, 11 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) |