From 2c697c574a6844c6cec3dc0cb6498cc0f87ff072 Mon Sep 17 00:00:00 2001 From: elijah Date: Wed, 5 Nov 2014 15:44:24 -0800 Subject: prompt user to update ssh host keys when a better one is available. closes #6320 --- lib/leap_cli/commands/compile.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'lib/leap_cli/commands/compile.rb') diff --git a/lib/leap_cli/commands/compile.rb b/lib/leap_cli/commands/compile.rb index 644ce2a..b30aaea 100644 --- a/lib/leap_cli/commands/compile.rb +++ b/lib/leap_cli/commands/compile.rb @@ -98,6 +98,30 @@ module LeapCli write_file!(:authorized_keys, buffer.string) end + # + # generates the known_hosts file. + # + # we do a 'late' binding on the hostnames and ip part of the ssh pub key record in order to allow + # for the possibility that the hostnames or ip has changed in the node configuration. + # + def update_known_hosts + buffer = StringIO.new + buffer << "#\n" + buffer << "# This file is automatically generated by the command `leap`. You should NOT modify this file.\n" + buffer << "# Instead, rerun `leap node init` on whatever node is causing SSH problems.\n" + buffer << "#\n" + manager.nodes.keys.sort.each do |node_name| + node = manager.nodes[node_name] + hostnames = [node.name, node.domain.internal, node.domain.full, node.ip_address].join(',') + pub_key = read_file([:node_ssh_pub_key,node.name]) + if pub_key + buffer << [hostnames, pub_key].join(' ') + buffer << "\n" + end + end + write_file!(:known_hosts, buffer.string) + end + ## ## ZONE FILE ## -- cgit v1.2.3