selinux_cn_statelite_disabled_by_design ran nodeset against the
statelite osimage without building it. copycds declares the osimage, and
nodeset needs the image tree and the litefile links that genimage and
liteimg create, so the case failed on a fresh cluster for a reason that
has nothing to do with SELinux.
Build the image in the case.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
The selinux cases cover the management node and a compute node. A
hierarchical cluster has a service node, which installs xCAT itself and
serves /install and /tftpboot to its own nodes, and nothing measured it
under SELinux. A statelite node was not measured either, although
node_modes resolves it to disabled on purpose.
selinux_sn_enforcing reads the provisioned service node: getenforce,
the kernel command line, the xcat policy module, the labels of /install,
/tftpboot, /opt/xcat and /xcatpost, a restorecon dry run that must find
nothing to relabel, xcatd active, and no xCAT denial since boot.
selinux_sn_per_node_switch sets noderes.selinux on the service node and
reads the mode out of the kickstart that nodeset writes for it, in all
three directions, and checks that a value on the compute node does not
reach the service node.
selinux_cn_statelite_disabled_by_design asks for enforcing on a
statelite node and requires selinux=0 on its boot configuration, with
nodeset saying why.
selinux_bundle.t now keeps a service-node case out of the
management-node bundle, the same way it keeps a compute-node case out.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
compute.rhels10.aarch64.postinstall arrived after the other netboot
postinstall scripts were anchored, and it carries the old pattern:
s/SELINUX=enforcing\|permissive/SELINUX=disabled/. The alternation binds
to the whole pattern, so the right branch is the bare word permissive.
On a permissive image the substitution writes SELINUX=SELINUX=disabled,
which no SELinux reads, and it rewrites the comment line that names
permissive. On a disabled image it still rewrites that comment.
Anchor the pattern to the SELINUX= line, as the other scripts do.
postinstall_selinux_config.bats fails three of its six checks against
this script before the change.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
postinstall_selinux_config.bats required at least 13 postinstall scripts
that write the SELinux config. Three riscv64 scripts are now symlinks to
the rocky one, and the find uses -type f, which counts a shared file
once, so the list holds 12 entries for 15 names and the check fails on a
tree where nothing is wrong.
Lower the bound to 12 and name the aarch64 script among the
representatives. The bound exists to catch a find that stops matching; a
new script needs no new bound, because every other test in the file
loops over the same list.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
selinux_bundle.t fails on this branch: selinux_client_domain is in no
bundle, so no run selects it. The case measures that an xCAT client
command execs and transitions into xcat_t, which is the check that a
client cannot run at all under enforcing.
Name it in selinux.bundle and selinux_mn.bundle. It needs no compute
node, so it belongs in both.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
The xcatmn probe checkpoint became "Checking SELinux policy for xCAT"
when the probe started to check the xcat policy module and the labels of
installdir and tftpdir. The transcript in the quick start still shows
"Checking SELinux is disabled", which tells a reader that xCAT wants
SELinux off.
Show the line the probe prints.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
No case in xCAT-test/autotest/testcase runs xcatprobe xcatmn, so a broken MN
check reaches a release unseen. The new case runs the probe and asserts that
the SELinux checkpoint appears and does not carry the FAIL marker.
The case cannot reach the enforcing mode. A management node under test runs
with SELinux disabled, and a disabled node needs a reboot and a relabel to
become enforcing. probe_utils_selinux.t covers the enforcing verdict.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
The substitution had two unanchored alternatives, SELINUX=enforcing and the bare word
permissive. An image whose /etc/selinux/config reads SELINUX=permissive therefore gets
SELINUX=SELINUX=disabled, which the policy loader rejects, so the image boots with
SELinux enabled. The bare alternative also matches the comment that lists the three
values, so every image gets a rewritten comment line.
The substitution is now anchored on the whole assignment, the form xcatconfig already
uses. Thirteen scripts carry it, and eleven more postinstall paths are symlinks into
those files.
The postinstall scripts source no shared library, so each copy is edited in place.
Symlinks are how this tree already shares a postinstall between distributions.
The xcat_inventory fixture test1.postinstall is changed as well. cases.environment
names it as the postinstall attribute of an osimage, so genimage runs it on a real
diskless image.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
Thirteen netboot postinstall scripts, and the xcat_inventory postinstall fixture,
disable SELinux in the rootimg with
s/SELINUX=enforcing\|permissive/SELINUX=disabled/. The second alternative is a bare
word with no key, so a config that reads SELINUX=permissive becomes
SELINUX=SELINUX=disabled. The same alternative matches the stock comment that names
permissive, which is rewritten on every image. sed returns 0 in both cases.
postinstall_selinux_config.bats runs each script over a scratch image root and reads
the config the script writes. Three of its six tests fail on this tree: the permissive
value, the already-disabled config and the comment.
The other three hold down behaviour the fix must keep. A no-op substitution turns the
enforcing test red, and a dropped -f guard turns the absent-config test red.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
The branch changed what a cluster runs and added no documentation, while
the quick start guide still told the operator to write SELINUX=disabled
on the management node before installing xCAT.
docs/source/advanced/security/selinux.rst says which machine gets which
mode, why a stateless node runs with SELinux disabled, how to set
noderes.selinux and site.selinux, and that xcatd, in.tftpd, kea-dhcp4
and goconserver run in unconfined_service_t, so the work is about
running with SELinux enforcing and not about confining xCAT.
It also covers the upgrade: recordselinuxdefault runs on INITIALINSTALL
only, so an upgraded cluster has no site.selinux value, every node keeps
being provisioned with SELinux off, and reprovisioning is what gives a
node the new mode.
The quick start step now says SELinux can stay enabled and links there.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
netboot_supported() answered 1 for rhels8 and later and for every
openEuler, so mknetboot wrote no selinux= argument and a stateless node
was asked to run SELinux enforcing. It does not boot.
A stateless root is a cpio archive unpacked into tmpfs, and cpio carries
no SELinux label, so the root starts unlabelled. Three boots of an
AlmaLinux 10.1 image on an enforcing node measured both ways out of
that, on cluster xcat163:
- With the stock dracut selinux module, which this branch added to the
module list, the policy loads at pre-pivot 50 over the unlabelled
initramfs. 61 Permission denied lines follow, setfiles returns 126 and
the node loops. That module ships with check() returning 255, so no
image enables it by accident.
- Without it, and with the relabel hook corrected, setfiles labels the
root: /usr/lib/systemd/systemd reads init_exec_t. systemd then loads
the policy after switch_root, cannot relabel /dev or /run, and stops
with "Failed to allocate manager object. Freezing execution".
The hook could not have worked as written either. It read the mode with
sed piped into tail, and the initramfs has neither tail nor chroot:
chroot arrived with the selinux module. The console reported "tail:
command not found" twice and relabelled nothing.
So netboot_supported() answers 0, mknetboot writes selinux=0 for every
stateless node and nodeset says why. The code that only serves a
stateless node with SELinux on is removed with it: the relabel hook and
its two installers, the selinux dracut module, write_image_config, and
the squashfs label machinery that stored labels nothing reads. The
netboot postinstalls and the stateless xcatroot write SELINUX=disabled
again, so the image says what the kernel command line does.
What stays is what was measured working: a diskful node provisioned
enforcing with zero xCAT denials, the kickstart templates, the policy
package, and the service node mount options.
Tests: selinux_netboot_kcmdline.t fails 34 of its 69 checks on the
parent commit. selinux_cn_diskless_disabled_by_design in cases1
provisions a stateless node asked for enforcing and requires selinux=0
on its command line and getenforce Disabled. selinux_image_config.t and
selinux_squashfs_labels.t go with the subs they tested.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
netboot_supported() answers 1 for rhels8 and later and for every
openEuler, so mknetboot omits selinux=0 and a stateless node is told to
run SELinux. No stateless node has been measured booting that way.
This test asserts the opposite: every OS answers 0, every mode gets
selinux=0, and no dracut module ships a relabel hook. It fails on this
commit, which is the point. The walk of the netboot tree carries a
positive control, so an empty hook list means the hooks are gone and not
that the walk looked nowhere.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
Eight checks in the selinux testcases asserted ausearch output =~ "<no
matches>", which is zero denials of any kind in the window. A cluster
denies things xCAT has nothing to do with. On an idle enforcing
management node httpd asks the kernel for net_admin on itself every ten
seconds, and the base policy carries no dontaudit rule for that shape.
One node logged 1034 denials in a day, 817 of them that one shape. So
the assertion cannot pass once ausearch is called correctly, and before
--input-logs was added it could not fail.
selinux_avc_check.sh keeps the denials whose subject program or object
path belongs to xCAT and counts those. The cases assert XCAT_AVC=0.
selinux_mn_labels now also plants a denial on purpose: it mislabels
/install/postscripts/xcatdsklspost, shows httpd answering 403, and
requires the check to report XCAT_AVC=[1-9] before restoring the label.
A counting method with no positive control cannot be trusted to find
anything.
restorecon -RnvF reports a difference in the SELinux user as well as the
type, and the files xCAT writes carry unconfined_u. On one node -RnvF
printed 12 lines over /install where -Rnv printed 2. The checks use
-Rnv, which is the type they assert.
The six cases were in no bundle and in no pipeline conf, so none had
ever run, which is why the dead checks were not noticed.
selinux.bundle and selinux_mn.bundle name them, and selinux_bundle.t
fails when a case is in no bundle.
Tests: selinux_avc_check.bats drives the classifier with records
measured on an enforcing management node. Replacing the filter with one
that keeps every record fails 4 of its 8 checks; dropping the
object-path branch fails 2. selinux_bundle.t fails when selinux.bundle
is removed. selinux_kickstart_template.t asserted the relabel order with
a regex that matched wherever the relabel sat; it now compares line
positions, and moving #SELINUXRELABEL# above the xCAT post includes
fails it.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
cases0 and cases1 call ausearch eight times to assert that a step produced
no AVC denial. On el10, audit 4.0.3 ships an ausearch that reads the
journal, and the journal carries no audit records. Measured on an
enforcing management node: "ausearch -ts today" returns 0 records while
"ausearch --input-logs -ts today" returns 11261, and the raw log holds
1032 denials. So each of the eight checks reports no denials whatever the
node does, and the suite cannot fail.
Add --input-logs to all eight. The option makes ausearch read
/var/log/audit/audit.log, which is where auditd writes.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
Every compute and service node was provisioned with SELinux disabled.
mknetboot added selinux=0, the kickstart templates said selinux
--disable, and the genimage postinstall and the dracut hooks wrote
SELINUX=disabled into the image. noderes.selinux and site.selinux had no
consumer on the node side.
The mode that xCAT::SELinux->node_modes resolves now reaches the node:
- Kernel command line: mknetboot appends kcmdline_selinux(): selinux=0
for disabled, enforcing=0 for permissive, nothing for enforcing. An
image built without the relabel hook (EL7 and older), and a squashfs
image without labels, boot with selinux=0 and nodeset says why.
Test: selinux_netboot_kcmdline.t.
- Kickstart: #SELINUXMODE# and #SELINUXRELABEL# in xCAT::Template. The
rh el8/9/10, riscv64 and openEuler templates use them; the %post ends
with restorecon -RF over the paths the xCAT scripts write. mkinstall
warns when a template cannot express the mode of the node.
Test: selinux_kickstart_template.t.
- genimage: the el8-10 postinstalls no longer write SELINUX=disabled, and
the stateless xcatroot no longer writes /etc/sysconfig/selinux. genimage
sets SELINUX=enforcing in the image, adds dracut 98selinux, and installs
a pre-pivot hook that runs setfiles with the image file_contexts unless
selinux=0 is set. Tests: selinux_image_config.t, selinux_relabel_hook.bats.
- packimage -m squashfs stores the labels of the image policy through
mksquashfs pseudo xattr definitions (squashfs-tools 4.6 or later), and
writes rootimg.sfs.selinux beside the image. Test:
selinux_squashfs_labels.t.
- Service nodes mount /install and /tftpboot from the management node with
context=public_content_t and tftpdir_t when SELinux is on.
Test: selinux_sn_mount_options.t.
- makedns no longer warns about SELinux. xcatprobe xcatmn checks the xcat
module and the labels of installdir and tftpdir instead of failing on
enforcing. Test: probe_utils_selinux_policy.t.
The selinux/cases1 xcattest cases provision a diskful, a stateless and a
squashfs node enforcing, and a stateless node with site.selinux=disabled.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
xcatconfig recorded no SELinux mode at the first install, so an enforcing
management node left site.selinux unset and its nodes were provisioned
with SELinux disabled.
At the first install, xcatconfig now sets site.selinux to enforcing when
the management node is enforcing, and to disabled when it is permissive
or disabled. xCAT::SELinux->install_default makes the decision. An
existing site.selinux value stays, and an upgrade does not set it.
xcatconfig does not change the SELinux mode of the management node.
With the existing value ignored, 12 checks of xcatconfig_selinux_policy.t
fail. With a permissive mode recorded as permissive, 4 checks fail.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
xcatconfig records no SELinux mode at the first install. A management
node that is enforcing therefore leaves site.selinux unset, and its nodes
are provisioned with SELinux disabled.
xcatconfig_selinux_policy.t now drives xCAT::SELinux->install_default for
each runtime mode with no value, an empty value and each existing value.
Only an enforcing node records enforcing, and an existing value is kept.
The test dies on this commit because install_default does not exist.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
No code resolved the SELinux mode of a node, so each provisioning path
would have to repeat the precedence and the platform rules.
xCAT::SELinux->node_modes returns the mode for each node. The noderes row
of the node comes first, then the noderes rows of its groups, then
site.selinux, then disabled. A node or group row can enable SELinux when
site.selinux is disabled. A node resolves to disabled when its OS is not
in the Red Hat, Fedora or openEuler families, when its OS is not known,
and when the node or its osimage is statelite. The OS and the provisioning
method come from the osimage row when nodetype.provmethod names one. An
optional hash reference receives the reason for each such clamp.
With the clamp removed, 7 checks of selinux_node_modes.t fail. With the
site value read before noderes, 5 checks fail.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
No code resolves the SELinux mode of a node from noderes.selinux and
site.selinux. Each provisioning path would need to repeat the precedence
and the platform rules.
selinux_node_modes.t drives xCAT::SELinux->node_modes with Perl stubs for
the noderes, nodetype and osimage tables and for site.selinux. It covers
the node row, the group row, the site value, an absent site value, a node
that enables SELinux under a disabled site, an invalid value, the SLES and
Ubuntu clamp, the osimage OS and the statelite clamp. The test dies on
this commit because node_modes does not exist.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
xCAT had no attribute that selects the SELinux mode of a node.
site.selinux holds the default mode for the cluster. The values are
enforcing, permissive and disabled, and an unset key means disabled. The
new noderes.selinux column overrides it for a node or a group, and chdef
and lsdef show it as the selinux attribute of node and group objects.
Nothing reads the attributes yet.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
xCAT has no attribute that selects the SELinux mode of a node. The site
table help does not describe a selinux key, and noderes has no selinux
column, so neither the admin nor the provisioning code can set a mode per
site, group or node.
selinux_schema.t loads xCAT::Schema and checks the noderes.selinux column,
its description, the node and group object attribute, and the site.selinux
help. 18 of its 19 checks fail on this commit.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
Exercise the full driver with either or both unit suites failing. Check
execution order, both result messages, and the final exit status.
Allow multiple command failures in the fixture. Encode logged commands as
JSON arrays for compatibility with older JSON::PP versions.
A restrictive checkout umask can remove group and other execute bits.
Require the owner execute bit on source postinstall files and reject all
execute bits on data files. Native package tests still require exact modes.
Preserve source modes when staging Debian package builds and accept a
private source fixture. Build group-writable profiles under umasks 0022
and 0002, then check the extracted data, postscripts and directories.
Verify that staging and packaging leave source permissions unchanged,
including a world-writable data file. Reuse the payload checks for normal,
reduced and permission-regression builds.
Group-writable sources leave install and netboot assets writable by other users in the Debian package. Remove group and other write permission from those two staged trees. Preserve executable bits and leave source files and the rest of the payload unchanged.
RPM preparation removes group write permission from source files. Assert the packaged data and postinstall modes instead of comparing them with checkout permissions. Report modes in octal and keep the content, alias and customization checks.
Use relative aliases for identical shipped profiles. Keep their public names,
resolved contents and executable modes. Custom copies remain independent.