diff --git a/.github/workflows/xcat_test.yml b/.github/workflows/xcat_test.yml index da6e641b74..b757dfb068 100644 --- a/.github/workflows/xcat_test.yml +++ b/.github/workflows/xcat_test.yml @@ -16,6 +16,10 @@ jobs: run: sudo env DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends --no-install-suggests ucf debconf-utils systemd libxml-simple-perl apache2 curl - name: Test Debian package lifecycle run: prove -v xCAT-test/native/xcatd_debian_lifecycle.t xCAT-test/native/xcatd_restart_callers.t xCAT-test/native/apache_package_lifecycle.t xCAT-test/native/package_upgrade_logging.t + - name: Test optional statelite host keys + run: prove -v xCAT-test/native/statelite_optional_hostkey.t + - name: Test Cumulus discovery key failure + run: prove -v xCAT-test/native/cumulus_discovery_key_failure.t - name: Install image test dependencies if: ${{ !cancelled() }} diff --git a/xCAT-test/native/cumulus_discovery_key_failure.t b/xCAT-test/native/cumulus_discovery_key_failure.t new file mode 100644 index 0000000000..722cfaabef --- /dev/null +++ b/xCAT-test/native/cumulus_discovery_key_failure.t @@ -0,0 +1,37 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use FindBin; +use lib "$FindBin::Bin/../lib"; +use File::Path qw(make_path); +use File::Slurper qw(write_text); +use Test::More; +use XCAT::Test::File qw(repo_path); +use XCAT::Test::Sandbox qw(sandbox_root sandbox_run); + +plan skip_all => 'Cumulus discovery requires Linux' unless $^O eq 'linux'; + +my $directory = sandbox_root(); +make_path(map { "$directory/$_" } qw(bin tmp etc/xcat etc/pki/tls var/lib/dhcp)); +write_text("$directory/var/lib/dhcp/dhclient.eth0.leases", ''); +write_text("$directory/bin/openssl", <<'SH'); +#!/bin/sh +echo attempted > /fixture/key-attempt +exit 1 +SH +write_text("$directory/bin/logger", "#!/bin/sh\nexit 0\n"); +write_text("$directory/bin/socat", "#!/bin/sh\ntouch /fixture/listener-started\nexit 0\n"); +chmod(0755, map { "$directory/bin/$_" } qw(openssl logger socat)); + +my ($rc, $output) = sandbox_run($directory, { + read_only => {repo_path('xCAT/postscripts') => '/postscripts'}, + writable => {"$directory/var/lib/dhcp" => '/var/lib/dhcp'}}, + '/bin/bash', '/postscripts/documulusdiscovery'); +is($rc, 1, 'discovery reports failed private-key generation') or diag($output); +ok(-f "$directory/key-attempt", 'the failure comes from the key generator'); +ok(!-e "$directory/tmp/helper.socat.sh", + 'failed key generation leaves no listener helper behind'); +ok(!-e "$directory/listener-started", 'failed key generation does not start a listener'); + +done_testing(); diff --git a/xCAT-test/native/statelite_optional_hostkey.t b/xCAT-test/native/statelite_optional_hostkey.t new file mode 100644 index 0000000000..b52287740c --- /dev/null +++ b/xCAT-test/native/statelite_optional_hostkey.t @@ -0,0 +1,49 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use FindBin; +use lib "$FindBin::Bin/../lib"; +use File::Path qw(make_path); +use File::Slurper qw(read_text write_text); +use Test::More; +use XCAT::Test::File qw(repo_path); +use XCAT::Test::Sandbox qw(sandbox_root sandbox_run); + +plan skip_all => 'statelite requires Linux' unless $^O eq 'linux'; +my $script = repo_path('xCAT-server/share/xcat/netboot/add-on/statelite/add_ssh'); + +for my $with_dsa (0, 1) { + my $root = sandbox_root(); + make_path(map { "$root/$_" } + qw(etc/xcat/hostkeys etc/ssh root/.ssh target/etc/ssh)); + write_text("$root/target/etc/ssh/sshd_config", "X11Forwarding no\n"); + write_text("$root/etc/xcat/hostkeys/ssh_host_rsa_key", "rsa-host-key\n"); + write_text("$root/etc/xcat/hostkeys/ssh_host_dsa_key", "dsa-host-key\n") + if $with_dsa; + write_text("$root/root/.ssh/$_", "client-$_\n") for qw(id_rsa id_rsa.pub config); + + my ($rc, $output) = sandbox_run($root, { + read_only => {$script => '/add_ssh'}, + writable => {"$root/root" => '/root'}, + env => {XCATROOT => '/opt/xcat'}}, + '/bin/bash', '/add_ssh', '/target'); + is($rc, 0, "statelite completes with DSA present=$with_dsa") or diag($output); + is($output, '', "statelite reports no missing-key errors with DSA present=$with_dsa"); + like(read_text("$root/etc/ssh/ssh_config"), qr/StrictHostKeyChecking no/, + 'statelite writes client configuration inside the private filesystem'); + is(read_text("$root/target/etc/ssh/ssh_host_rsa_key"), "rsa-host-key\n", + "statelite preserves the RSA host key with DSA present=$with_dsa"); + is(-f "$root/target/etc/ssh/ssh_host_dsa_key" ? 1 : 0, $with_dsa, + 'statelite copies the optional DSA key only when supplied'); + is((stat("$root/target/etc/ssh/ssh_host_rsa_key"))[2] & oct('0777'), oct('0600'), + 'statelite limits RSA host-key permissions'); + if ($with_dsa) { + is(read_text("$root/target/etc/ssh/ssh_host_dsa_key"), "dsa-host-key\n", + 'statelite preserves the optional DSA key'); + is((stat("$root/target/etc/ssh/ssh_host_dsa_key"))[2] & oct('0777'), oct('0600'), + 'statelite limits DSA host-key permissions'); + } +} + +done_testing(); diff --git a/xCAT-test/unit/cumulus_discovery_key_failure.t b/xCAT-test/unit/cumulus_discovery_key_failure.t deleted file mode 100644 index fb6381d0a8..0000000000 --- a/xCAT-test/unit/cumulus_discovery_key_failure.t +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; - -use FindBin; -use lib "$FindBin::Bin/../lib"; -use File::Path qw(make_path); -use File::Slurper qw(read_text write_text); -use File::Temp qw(tempdir); -use Test::More; -use XCAT::Test::File qw(repo_path); - -my $bash = qx(command -v bash 2>/dev/null); -chomp($bash); -plan skip_all => 'bash is required' unless $bash && -x $bash; - -my $directory = tempdir(CLEANUP => 1); -make_path(map { "$directory/$_" } qw(bin tmp etc/xcat etc/pki/tls var/lib/dhcp)); -write_text("$directory/var/lib/dhcp/dhclient.eth0.leases", ''); -symlink(repo_path('xCAT/postscripts/xcatlib.sh'), "$directory/xcatlib.sh") - or die "link shell library: $!"; - -my $script = read_text(repo_path('xCAT/postscripts/documulusdiscovery')); -$script =~ s{(/etc/xcat|/etc/pki/tls|/var/lib/dhcp|/tmp)(?=/|\b)}{$directory$1}g; -write_text("$directory/documulusdiscovery", $script); -write_text("$directory/bin/openssl", <<'SH'); -#!/bin/sh -echo attempted > "$KEY_ATTEMPT" -exit 1 -SH -write_text("$directory/bin/logger", "#!/bin/sh\nexit 0\n"); -write_text("$directory/bin/socat", "#!/bin/sh\nexit 0\n"); -chmod(0755, map { "$directory/bin/$_" } qw(openssl logger socat)); - -local $ENV{PATH} = "$directory/bin:$ENV{PATH}"; -local $ENV{KEY_ATTEMPT} = "$directory/key-attempt"; -system($bash, "$directory/documulusdiscovery"); -is($? >> 8, 1, 'discovery reports failed private-key generation'); -ok(-f "$directory/key-attempt", 'the failure comes from the key generator'); -ok(!-e "$directory/tmp/helper.socat.sh", - 'failed key generation leaves no listener helper behind'); - -done_testing(); diff --git a/xCAT-test/unit/fips_ssh_keys.t b/xCAT-test/unit/fips_ssh_keys.t index 66d37edb6a..8c81c5213f 100644 --- a/xCAT-test/unit/fips_ssh_keys.t +++ b/xCAT-test/unit/fips_ssh_keys.t @@ -3,7 +3,6 @@ use strict; use warnings; use FindBin; -use File::Path qw(make_path); use File::Spec; use File::Slurper qw(read_text write_text); use File::Temp qw(tempdir); @@ -11,7 +10,6 @@ use Test::More; use lib "$FindBin::Bin/../lib"; use lib "$FindBin::Bin/../../perl-xCAT"; -use XCAT::Test::File qw(repo_path); use xCAT::Utils; my $tmpdir = tempdir(CLEANUP => 1); @@ -41,49 +39,4 @@ foreach my $case ( "$platform rejects DSA in FIPS mode"); } -SKIP: { - skip 'statelite requires Linux shell utilities', 12 unless $^O eq 'linux'; - - foreach my $with_dsa (0, 1) { - my $fixture = tempdir(CLEANUP => 1); - my $image = "$fixture/image"; - make_path("$fixture/hostkeys", "$fixture/client", - "$image/etc/ssh", "$image/root/.ssh"); - write_text("$image/etc/ssh/sshd_config", "X11Forwarding no\n"); - write_text("$fixture/hostkeys/ssh_host_rsa_key", "rsa-host-key\n"); - write_text("$fixture/hostkeys/ssh_host_dsa_key", "dsa-host-key\n") - if $with_dsa; - write_text("$fixture/client/$_", "client-$_\n") for qw(id_rsa id_rsa.pub config); - - my $source = read_text(repo_path('xCAT-server/share/xcat/netboot/add-on/statelite/add_ssh')); - $source =~ s{/etc/xcat/hostkeys}{$fixture/hostkeys}g; - $source =~ s{/install/postscripts/_ssh}{$fixture/postscript-keys}g; - $source =~ s{(?', "$fixture/stdout") or die $!; - open(STDERR, '>', "$fixture/stderr") or die $!; - $ENV{XCATROOT} = $fixture; - exec('bash', "$fixture/add_ssh", $image); - die "exec bash: $!"; - } - waitpid($pid, 0); - is($?, 0, "statelite completes with DSA present=$with_dsa"); - is(read_text("$fixture/stderr"), '', - "statelite reports no missing-key errors with DSA present=$with_dsa"); - like(read_text("$fixture/client/ssh_config"), qr/StrictHostKeyChecking no/, - 'statelite writes client configuration only inside the fixture'); - is(read_text("$image/etc/ssh/ssh_host_rsa_key"), "rsa-host-key\n", - "statelite preserves the RSA host key with DSA present=$with_dsa"); - is(-f "$image/etc/ssh/ssh_host_dsa_key" ? 1 : 0, $with_dsa, - 'statelite copies the optional DSA key only when supplied'); - is((stat("$image/etc/ssh/ssh_host_rsa_key"))[2] & oct('0777'), oct('0600'), - 'statelite limits host-key permissions'); - } -} - done_testing();