From bb974cc9d25136601650ea6be48aa74094fd491f Mon Sep 17 00:00:00 2001 From: Garrett Holmstrom Date: Sat, 22 Sep 2012 17:50:21 -0700 Subject: [PATCH] Fix ssh key printing --- cloud-init-0.7.0-ssh-key-users.patch | 79 ++++++++++++++++++++++++++++ cloud-init.spec | 5 ++ 2 files changed, 84 insertions(+) create mode 100644 cloud-init-0.7.0-ssh-key-users.patch diff --git a/cloud-init-0.7.0-ssh-key-users.patch b/cloud-init-0.7.0-ssh-key-users.patch new file mode 100644 index 0000000..db11b09 --- /dev/null +++ b/cloud-init-0.7.0-ssh-key-users.patch @@ -0,0 +1,79 @@ +Index: trunk/cloudinit/config/cc_ssh_authkey_fingerprints.py +=================================================================== +--- trunk.orig/cloudinit/config/cc_ssh_authkey_fingerprints.py ++++ trunk/cloudinit/config/cc_ssh_authkey_fingerprints.py +@@ -21,7 +21,8 @@ import hashlib + + from prettytable import PrettyTable + +-from cloudinit import ssh_util ++from cloudinit.ssh_util import extract_authorized_keys as eak ++ + from cloudinit import util + + +@@ -40,8 +41,9 @@ def _gen_fingerprint(b64_text, hash_meth + hasher = hashlib.new(hash_meth) + hasher.update(base64.b64decode(b64_text)) + return ":".join(_split_hash(hasher.hexdigest())) +- except TypeError: +- # Raised when b64 not really b64... ++ except (TypeError, ValueError): ++ # Raised when b64 not really b64... or ++ # when the hash type isn't valid + return '?' + + +@@ -84,13 +86,48 @@ def _pprint_key_entries(user, key_fn, ke + 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) ++ 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) + +- user_name = util.get_cfg_option_str(cfg, "user", "ubuntu") + 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) diff --git a/cloud-init.spec b/cloud-init.spec index b7db61a..02ec336 100644 --- a/cloud-init.spec +++ b/cloud-init.spec @@ -16,6 +16,9 @@ Patch0: cloud-init-0.7.0-fedora.patch # Make Fedora use the same hostname-updating code as Debian (/etc/hostname) # https://code.launchpad.net/~gholms/cloud-init/hostname-refactor/+merge/125869 Patch1: cloud-init-0.7.0-hostname-refactor.patch +# Fix fingerprint printing caused by recent user code refactoring +# https://code.launchpad.net/~harlowja/cloud-init/patch-ssh-key-users/+merge/125606 +Patch2: cloud-init-0.7.0-ssh-key-users.patch BuildArch: noarch BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) @@ -52,6 +55,7 @@ ssh keys and to let the user run various scripts. %setup -q -n %{name}-%{version}-bzr659 %patch0 -p1 %patch1 -p1 +%patch2 -p1 cp -p %{SOURCE2} README.fedora @@ -132,6 +136,7 @@ fi * Sat Sep 22 2012 Garrett Holmstrom - 0.7.0-0.2.bzr659 - Rebased against upstream rev 659 - Fixed hostname persistence +- Fixed ssh key printing * Mon Sep 17 2012 Garrett Holmstrom - 0.7.0-0.1.bzr650 - Rebased against upstream rev 650