From 6c720f739d6be1e3870a82777f5fb2b3d5f7fd4c Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Wed, 6 May 2015 10:56:34 +0100 Subject: [PATCH] Debian: refactor preseeding of .ssh directories Causes known_hosts to be consistently created as well as ~osstest/.ssh to be consistently populated (it previsouly wasn't for HVM guests). Signed-off-by: Ian Campbell Cc: longtaox.pang@intel.com Acked-by: Ian Jackson --- Osstest/Debian.pm | 117 ++++++++++++++++++++++++------------------ ts-debian-hvm-install | 5 +- 2 files changed, 67 insertions(+), 55 deletions(-) diff --git a/Osstest/Debian.pm b/Osstest/Debian.pm index 3585760f..f9b3f43b 100644 --- a/Osstest/Debian.pm +++ b/Osstest/Debian.pm @@ -37,6 +37,7 @@ BEGIN { %preseed_cmds preseed_base preseed_create + preseed_ssh preseed_hook_command preseed_hook_installscript preseed_hook_cmds di_installcmdline_core ); @@ -551,8 +552,70 @@ sub di_installcmdline_core ($$;@) { return @cl; } -sub preseed_base ($$$;@) { - my ($ho,$suite,$extra_packages,%xopts) = @_; +sub preseed_ssh ($$) { + my ($ho,$sfx) = @_; + + my $authkeys_url= create_webfile($ho, "authkeys$sfx", authorized_keys()); + + my $hostkeyfile= "$c{OverlayLocal}/etc/ssh/ssh_host_rsa_key.pub"; + my $hostkey= get_filecontents($hostkeyfile); + chomp($hostkey); $hostkey.="\n"; + my $knownhosts= ''; + + my $hostsq= $dbh_tests->prepare(<execute($flight); + while (my ($node) = $hostsq->fetchrow_array()) { + my $defaultfqdn = $node; + $defaultfqdn .= ".$c{TestHostDomain}" unless $defaultfqdn =~ m/\./; + + my %props; + $mhostdb->get_properties($node, \%props); + + my $longname= $props{Fqdn} // $defaultfqdn; + my (@hostent)= gethostbyname($longname); + if (!@hostent) { + logm("skipping host key for nonexistent host $longname"); + next; + } + my $specs= join ',', $longname, $node, map { + join '.', unpack 'W4', $_; + } @hostent[4..$#hostent]; + logm("adding host key for $specs"); + $knownhosts.= "$specs ".$hostkey; + } + $hostsq->finish(); + + $knownhosts.= "localhost,127.0.0.1 ".$hostkey; + my $knownhosts_url= create_webfile($ho, "known_hosts$sfx", $knownhosts); + + preseed_hook_command($ho, 'late_command', $sfx, <{Tftp}{Path}.'/'.$ho->{Tftp}{DiBase}.'/'.$r{arch}.'/'. $c{TftpDiVersion}.'-'.$ho->{Suite}; - my $hostsq= $dbh_tests->prepare(<execute($flight); - while (my ($node) = $hostsq->fetchrow_array()) { - my $defaultfqdn = $node; - $defaultfqdn .= ".$c{TestHostDomain}" unless $defaultfqdn =~ m/\./; - - my %props; - $mhostdb->get_properties($node, \%props); - - my $longname= $props{Fqdn} // $defaultfqdn; - my (@hostent)= gethostbyname($longname); - if (!@hostent) { - logm("skipping host key for nonexistent host $longname"); - next; - } - my $specs= join ',', $longname, $node, map { - join '.', unpack 'W4', $_; - } @hostent[4..$#hostent]; - logm("adding host key for $specs"); - $knownhosts.= "$specs ".$hostkey; - } - $hostsq->finish(); - - $knownhosts.= "localhost,127.0.0.1 ".$hostkey; - my $knownhosts_url= create_webfile($ho, "known_hosts$sfx", $knownhosts); - my $overlays= ''; my $create_overlay= sub { my ($srcdir, $tfilename) = @_; @@ -753,17 +779,6 @@ set -ex r=/target/root cd \$r -umask 022 -mkdir .ssh -wget -O .ssh/authorized_keys '$authkeys_url' -wget -O .ssh/known_hosts '$knownhosts_url' - -u=osstest -h=/home/\$u -mkdir /target\$h/.ssh -cp .ssh/authorized_keys /target\$h/.ssh -chroot /target chown -R \$u.\$u \$h/.ssh - echo FANCYTTY=0 >> /target/etc/lsb-base-logging.sh $overlays @@ -878,7 +893,7 @@ END my $extra_packages = join(",",@extra_packages); - my $preseed_file= preseed_base($ho,$suite,$extra_packages,%xopts); + my $preseed_file= preseed_base($ho,$suite,$sfx,$extra_packages,%xopts); $preseed_file .= (< /root/.ssh/authorized_keys" END $preseed_file .= preseed_hook_cmds(); -- 2.39.5