]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
orchestra/connection: accept ecdsa (and future) host key types. 1575/head
authorMarcus Watts <mwatts@redhat.com>
Sat, 31 Oct 2020 19:31:35 +0000 (15:31 -0400)
committerMarcus Watts <mwatts@redhat.com>
Fri, 20 Nov 2020 03:38:41 +0000 (22:38 -0500)
Out of the box, centos 8 ssh daemon makes this file,
/etc/ssh/ssh_host_ecdsa_key.pub
containing a key of type "ecdsa-sha2-nistp256", which was
not recognized by the existing teuthology logic.
Use logic in paramiko.hostkeys to recognize the new key types.

Signed-off-by: Marcus Watts <mwatts@redhat.com>
teuthology/orchestra/connection.py

index 20a3b8fb2496af84c87ad4d401babffd3eb06f94..eefede0c988c0e98f2f582d2d662198e6edf57d1 100644 (file)
@@ -1,13 +1,13 @@
 """
 Connection utilities
 """
-import base64
 import paramiko
 import os
 import logging
 
 from teuthology.config import config
 from teuthology.contextutil import safe_while
+from paramiko.hostkeys import HostKeyEntry
 
 log = logging.getLogger(__name__)
 
@@ -29,14 +29,11 @@ def create_key(keytype, key):
     """
     Create an ssh-rsa, ssh-dss or ssh-ed25519 key.
     """
-    if keytype == 'ssh-rsa':
-        return paramiko.rsakey.RSAKey(data=base64.decodestring(key.encode()))
-    elif keytype == 'ssh-dss':
-        return paramiko.dsskey.DSSKey(data=base64.decodestring(key.encode()))
-    elif keytype == 'ssh-ed25519':
-        return paramiko.ed25519key.Ed25519Key(data=base64.decodestring(key.encode()))
-    else:
-        raise ValueError('keytype must be ssh-rsa, ssh-dss (DSA) or ssh-ed25519')
+    l = "{hostname} {keytype} {key}".format(hostname="x", keytype=keytype, key=key)
+
+    ke = HostKeyEntry.from_line(l)
+    assert ke, f'invalid host key "{keytype} {key}"'
+    return ke.key
 
 
 def connect(user_at_host, host_key=None, keep_alive=False, timeout=60,