mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-11-21 01:42:15 +00:00
7d66afe2f3
selinux_image_repair.t measured a moved publication directory and an image root
with a rootimg component in the middle in separate fixtures, and it called the
mappings of a scenario a repair without running the restorecon the page puts
between them. Neither condition reaches the ordering defect on its own, and the
relabel the procedure runs itself was never measured.
The case now gives each scenario the relabel, so the scenario places it where
the page does. It reads the guest labels straight after the procedure, because a
label the procedure overwrote cannot be recovered by a mapping added afterwards.
It then asserts the mapping and the label of each path after a recursive relabel
and after a reinstall of the module.
A third scenario runs the four documented steps on the layout that needs all of
them: site.installdir is /srv/xcat-images, so no mapping covers the tree until
the procedure adds one, and the image root carries a rootimg component in the
middle, so the guest exclusion matches the published artifacts too.
selinux_docs.t gains three checks on the order of the page: the guest exclusions
come before the artifact mappings, the relabel comes after the last mapping, and
there is one relabel. All three fail against the page at 78f6d65a7.
With the command order of that page, the full sequence fails 47 of 381 checks:
16 guest labels, which go from shadow_t, etc_t and bin_t to var_t, and 15
artifact mappings, which resolve <<none>> for the five expressions that carry a
wildcard.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
86 lines
3.7 KiB
Perl
86 lines
3.7 KiB
Perl
#!/usr/bin/env perl
|
|
use strict;
|
|
use warnings;
|
|
|
|
use FindBin;
|
|
use File::Slurper qw(read_text);
|
|
use Test::More;
|
|
|
|
# The SELinux pages and the policy module disagreed. The security page said the
|
|
# package defines no type and that xcatd runs in unconfined_service_t, while
|
|
# xcat.te declared two domains. Derive the domain set from the policy source,
|
|
# so a page cannot describe a module that is not shipped.
|
|
my $root = "$FindBin::Bin/../..";
|
|
|
|
my $te = read_text("$root/xCAT-selinux/xcat.te");
|
|
my @permissive = sort($te =~ /^\s*permissive\s+(\w+)\s*;/mg);
|
|
is_deeply(\@permissive, [ 'xcat_image_t', 'xcat_t' ],
|
|
"xcat.te declares the permissive domains @permissive");
|
|
|
|
my @pages = (
|
|
'docs/source/advanced/security/selinux.rst',
|
|
'docs/source/advanced/selinux/index.rst',
|
|
);
|
|
my %text;
|
|
foreach my $page (@pages) {
|
|
$text{$page} = read_text("$root/$page");
|
|
ok(length($text{$page}) > 1000, "$page holds @{[length $text{$page}]} characters");
|
|
}
|
|
|
|
foreach my $page (@pages) {
|
|
foreach my $domain (@permissive) {
|
|
like($text{$page}, qr/\Q$domain\E/, "$page names $domain");
|
|
}
|
|
like($text{$page}, qr/permissive/, "$page says the domains are permissive");
|
|
|
|
# xcatd enters xcat_t on the xcatd script. A page that still names the
|
|
# domain of an unconfined service describes the module before xcat_t.
|
|
unlike($text{$page}, qr/unconfined_service_t/,
|
|
"$page does not put an xCAT service in unconfined_service_t");
|
|
unlike($text{$page}, qr/defines no type/,
|
|
"$page does not say the package defines no type");
|
|
}
|
|
|
|
# The branch ships noderes.selinux, so a page cannot place the nodes outside
|
|
# the scope of what xCAT decides.
|
|
my $modes = read_text("$root/perl-xCAT/xCAT/SELinux.pm");
|
|
like($modes, qr/sub node_modes/, 'SELinux.pm resolves the mode of a node');
|
|
foreach my $page (@pages) {
|
|
like($text{$page}, qr/noderes\.selinux/, "$page names noderes.selinux");
|
|
unlike($text{$page}, qr/xCAT does not select their mode/,
|
|
"$page does not say xCAT leaves the mode of a node alone");
|
|
}
|
|
|
|
# A repair of a published artifact is a persistent file-context mapping, applied
|
|
# with restorecon. chcon writes a type that no mapping selects, and a recursive
|
|
# chcon over an image root walks into both guest trees.
|
|
my $repair = 'docs/source/advanced/selinux/index.rst';
|
|
unlike($text{$repair}, qr/chcon\s+-R/, "$repair documents no recursive chcon");
|
|
like($text{$repair}, qr/semanage fcontext -a/, "$repair maps the artifact with semanage");
|
|
like($text{$repair}, qr/restorecon -R/, "$repair applies the mapping with restorecon");
|
|
like($text{$repair}, qr/installdir/,
|
|
"$repair takes the publication directory from site.installdir");
|
|
foreach my $guest (qw(rootimg rootimg-statelite)) {
|
|
like($text{$repair}, qr/\Q$guest\E/, "$repair names the $guest tree");
|
|
}
|
|
|
|
# The order of the repair is what makes it work. A relabel before the guest
|
|
# exclusions writes a generic type over the guest labels, and an artifact
|
|
# mapping read before them loses to them.
|
|
my $exclusion = index($text{$repair}, "-t '<<none>>'");
|
|
my $artifact = index($text{$repair}, '-f f');
|
|
my $relabel = index($text{$repair}, 'restorecon -R');
|
|
my $last_map = rindex($text{$repair}, 'semanage fcontext -a');
|
|
cmp_ok($exclusion, '>', 0, "$repair excludes the guest trees with <<none>>");
|
|
cmp_ok($artifact, '>', $exclusion,
|
|
"$repair maps a published artifact after the guest exclusions");
|
|
cmp_ok($relabel, '>', $last_map, "$repair relabels after the last mapping");
|
|
my $relabels = () = $text{$repair} =~ /restorecon -R/g;
|
|
is($relabels, 1, "$repair relabels once, and it relabels $relabels time(s)");
|
|
|
|
my $fc = read_text("$root/xCAT-selinux/xcat.fc");
|
|
unlike($fc, qr/chcon/, 'xcat.fc advises no chcon');
|
|
like($fc, qr/semanage fcontext/, 'xcat.fc names the command that maps a path');
|
|
|
|
done_testing();
|