Use lowercase hostnames for SSH know hosts

OpenSSH will lowercase any hostname; ensure that hostnames
for known_host entries are also lower case avoiding any
authenticity of host type issues during live migration and
resize operators.

Change-Id: Ie5ab0774b49fc0d753ff1c26eb041f1ceb35e8fb
Closes-Bug: 1628216
This commit is contained in:
James Page 2018-07-13 15:52:48 +01:00
parent 927528b7f0
commit 36ccf4ee97
1 changed files with 12 additions and 6 deletions

View File

@ -985,24 +985,30 @@ def ssh_compute_add(public_key, rid=None, unit=None, user=None):
# known hosts entry for its IP, hostname and FQDN.
private_address = relation_get(rid=rid, unit=unit,
attribute='private-address')
hosts = [private_address]
hosts = []
if not is_ipv6(private_address):
if relation_get('hostname'):
hosts.append(relation_get('hostname'))
hostname = relation_get(rid=rid, unit=unit,
attribute='hostname')
if hostname:
hosts.append(hostname.lower())
if not is_ip(private_address):
hosts.append(private_address.lower())
hosts.append(get_host_ip(private_address))
short = private_address.split('.')[0]
if ns_query(short):
hosts.append(short)
hosts.append(short.lower())
else:
hosts.append(private_address)
hn = get_hostname(private_address)
if hn:
hosts.append(hn)
hosts.append(hn.lower())
short = hn.split('.')[0]
if ns_query(short):
hosts.append(short)
hosts.append(short.lower())
else:
hosts.append(private_address)
for host in list(set(hosts)):
add_known_host(host, unit, user)