Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/xcat_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
status=0
sudo sh -c 'cd "$1" && bats xCAT-test/native/getinstdisk_selection.bats' sh "$workdir" || status=1
sudo sh -c 'cd "$1" && bats xCAT-test/native/syslog_log_directory.bats' sh "$workdir" || status=1
sudo sh -c 'cd "$1" && prove -v xCAT-test/native/getinstdisk_installer.t xCAT-test/native/enablekdump_per_node.t xCAT-test/native/sudoer_password_source.t xCAT-test/native/remoteshell_credentials.t' sh "$workdir" || status=1
sudo sh -c 'cd "$1" && prove -v xCAT-test/native/getinstdisk_installer.t xCAT-test/native/template_root_password.t xCAT-test/native/enablekdump_per_node.t xCAT-test/native/sudoer_password_source.t xCAT-test/native/remoteshell_credentials.t' sh "$workdir" || status=1
exit "$status"
- name: Prepare xCAT syslog directory
if: ${{ !cancelled() }}
Expand Down
13 changes: 11 additions & 2 deletions xCAT-server/lib/perl/xCAT/Template.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,7 @@ sub envvar
return ($ENV{$envvar});
}

sub crydb
sub crypt_field
{
my ($table, $key, $field) = @_;
my @fields = [$field, 'cryptmethod'];
Expand All @@ -1681,10 +1681,19 @@ sub crydb
return xCAT::PasswordUtils::crypt_system_password($table, $kp, \@fields);
}

sub crydb
{
my ( $table, $key, $field ) = @_;
my $crypted = crypt_field( $table, $key, $field );
return $crypted if defined($crypted) && length($crypted);
$tmplerr = "Unable to find requested field <$field> from table <$table>, with key <$key>";
return "";
}

sub crydb_or_locked
{
my ( $table, $key, $field ) = @_;
my $crypted = crydb( $table, $key, $field );
my $crypted = crypt_field( $table, $key, $field );
return $crypted if defined($crypted) && length($crypted);
return '*';
}
Expand Down
56 changes: 56 additions & 0 deletions xCAT-test/native/template_root_password.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env perl
use strict;
use warnings;

use File::Slurper qw(read_text write_text);
use FindBin;
use lib "$FindBin::Bin/../lib";
use lib "$FindBin::Bin/../../perl-xCAT", "$FindBin::Bin/../../xCAT-server/lib/perl";
use Test::More;

use XCAT::Test::File qw(repo_path);
use XCAT::Test::Template qw(template_database set_row render_template);

plan skip_all => 'template rendering requires Linux namespaces' unless $^O eq 'linux';
my $database = template_database();
set_row('site', {key => 'secureroot'}, {value => 0});
set_row('nodetype', {node => 'node'}, {os => 'rhels10.0', arch => 'x86_64', provmethod => 'install'});
my $kickstart = repo_path('xCAT-server/share/xcat/install/rh/compute.rhels10.tmpl');
(my $pkglist = $kickstart) =~ s/\.tmpl$/.pkglist/;
my $output = "$database/ks";

sub render_kickstart {
return eval {
render_template($database, $kickstart, $output, 'node', $pkglist, '/install/media', 'rh', undef,
{xcatmaster => '192.0.2.1'});
1;
} ? '' : $@;
}

my $error = render_kickstart();
like($error, qr/Unable to find requested field <password> from table <passwd>, with key <key=system,username=root>/,
'a kickstart without a root password row is refused');

set_row('passwd', {key => 'system', username => 'root'}, {password => 'cluster'});
$error = render_kickstart();
is($error, '', 'a kickstart with a root password row renders') or diag($error);
my ($hash) = (-f $output ? read_text($output) : '') =~ /^rootpw --iscrypted (\S+)$/m;
ok(defined($hash) && crypt('cluster', $hash) eq $hash, 'the kickstart carries the hash of the root password');

set_row('nodetype', {node => 'node'}, {os => 'ubuntu24.04', arch => 'x86_64', provmethod => 'install'});
my $passwd = xCAT::Table->new('passwd') or die 'Cannot open passwd';
$passwd->delEntries({key => 'system', username => 'root'});
$passwd->close();
write_text("$database/image.pkglist", "vim\n");
my $autoinstall = "$database/autoinstall.yaml";
my $locked = eval {
render_template($database, repo_path('xCAT-server/share/xcat/install/ubuntu/compute.subiquity.tmpl'),
$autoinstall, 'node', "$database/image.pkglist", '/install/ubuntu24.04/x86_64', 'ubuntu', undef,
{xcatmaster => '192.0.2.1'}, osarch => 'x86_64');
1;
};
ok($locked, 'an autoinstall without a root password row renders') or diag($@);
like(-f $autoinstall ? read_text($autoinstall) : '', qr/^\s+password: "\*"$/m,
'the autoinstall locks the password that has no row');

done_testing();