← Back to team overview

cloud-init-dev team mailing list archive

[Merge] lp:~harlowja/cloud-init/patch-ssh-key-users into lp:cloud-init

 

Joshua Harlow has proposed merging lp:~harlowja/cloud-init/patch-ssh-key-users into lp:cloud-init.

Requested reviews:
  cloud init development team (cloud-init-dev)
Related bugs:
  Bug #1053720 in cloud-init: "ssh_fingerprints needs to use new users 'list'"
  https://bugs.launchpad.net/cloud-init/+bug/1053720

For more details, see:
https://code.launchpad.net/~harlowja/cloud-init/patch-ssh-key-users/+merge/125606
-- 
https://code.launchpad.net/~harlowja/cloud-init/patch-ssh-key-users/+merge/125606
Your team cloud init development team is requested to review the proposed merge of lp:~harlowja/cloud-init/patch-ssh-key-users into lp:cloud-init.
=== modified file 'cloudinit/config/cc_ssh_authkey_fingerprints.py'
--- cloudinit/config/cc_ssh_authkey_fingerprints.py	2012-08-22 18:12:32 +0000
+++ cloudinit/config/cc_ssh_authkey_fingerprints.py	2012-09-20 23:32:24 +0000
@@ -21,7 +21,8 @@
 
 from prettytable import PrettyTable
 
-from cloudinit import ssh_util
+from cloudinit.ssh_util import extract_authorized_keys as eak
+
 from cloudinit import util
 
 
@@ -84,13 +85,48 @@
                        stderr=False, console=True)
 
 
+def translate_user_name(uname, distro, log):
+    if not uname:
+        uname = ''
+    uname = uname.strip()
+    real_name = None
+    if uname.lower() == 'default':
+        try:
+            real_name = distro.get_default_user()
+        except NotImplementedError:
+            log.warn("Distro has not implemented default user "
+                     "creation. No default user will be translated.")
+    else:
+        real_name = uname
+    return real_name
+
+
 def handle(name, cfg, cloud, log, _args):
     if 'no_ssh_fingerprints' in cfg:
         log.debug(("Skipping module named %s, "
                    "logging of ssh fingerprints disabled"), name)
-
-    user_name = util.get_cfg_option_str(cfg, "user", "ubuntu")
+        return
+
+    if not 'users' in cfg:
+        log.debug(("Skipping module named %s, "
+                   "logging of ssh fingerprints disabled "
+                   "since no user/s provided"), name)
+        return
+
+    users_to_hash = []
+    for user_config in cfg['users']:
+        user_name = None
+        if isinstance(user_config, (basestring, str)):
+            user_name = translate_user_name(user_config, cloud.distro, log)
+        elif isinstance(user_config, (dict)):
+            if 'name' in user_config:
+                user_name = translate_user_name(user_config['name'],
+                                                cloud.distro, log)
+        if user_name:
+            users_to_hash.append(user_name)
+
     hash_meth = util.get_cfg_option_str(cfg, "authkey_hash", "md5")
-    extract = ssh_util.extract_authorized_keys
-    (auth_key_fn, auth_key_entries) = extract(user_name, cloud.paths)
-    _pprint_key_entries(user_name, auth_key_fn, auth_key_entries, hash_meth)
+    for user_name in users_to_hash:
+        (auth_key_fn, auth_key_entries) = eak(user_name, cloud.paths)
+        _pprint_key_entries(user_name, auth_key_fn,
+                            auth_key_entries, hash_meth)


Follow ups