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>
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>
Share line normalization and directive filtering across the legacy text
reader, its include reader and the record reader. Keep leading whitespace
in legacy includes and leave each parser expansion policy unchanged.
Signed-off-by: Vinícius Ferrão <2031761+viniciusferrao@users.noreply.github.com>
imgimport publishes the root image, kernel and ramdisk before it writes
the image definition. When the database refused or failed a write, the
new boot files stayed with the previous definition.
The import now holds the publication lock of the image from before it
places the files until the outcome of the definition is known. When the
definition is not written and its rows went back, it puts back the
previous files, with the checksum and metainfo of the root image. It
removes the files that had no previous version. While a row did not go
back, the new files stay, as that row can refer to them.
The image lock is per host, so another host can publish a root image
between two steps of a caller. lock_rootimg_publication and
unlock_rootimg_publication let a caller hold the publication lock across
such steps. publish_rootimg takes the held lock, and the new
unpublish_rootimg removes an archive with its checksum and metainfo
under it.
set_config writes the osimage, linuximage and kit rows one by one. When
a later write failed, the rows written before it stayed. An image could
keep a new linuximage row, with a new rootimgdir, beside its previous
osimage row.
set_config now keeps the osimage and linuximage rows that it replaces,
disabled rows included. When a write or its commit fails, or bundle
data of an unexpected shape dies between the writes, it checks each row
that it tried to write. It writes changed rows back and removes the rows
that it added, with NULL values as NULL. It skips a row that another
writer changed or filled, so that change stays. set_config reports the
rows that did not go back, also to a caller that asks for their number.
Kit rows stay as written, because other images can use them.
imgimport ignored the result of each write of the image definition. A
write that the database refused left the previous rows, and the import
still reported success. The import now fails and names the table when a
write returns an error, returns no reply or dies, or its commit fails.
A row that holds the new values despite the failure counts as written,
with a warning.
After a failed write the import commits, as before. A rollback would
drop the pending writes of other requests, which share the transaction
of the table in the database worker.
imgimport took the image lock only when the bundle had a rootimg. A
statelite bundle has a rootimgtree instead, so its import extracted the
tree while genimage, packimage, liteimg or rmimage could change the same
image. imgimport now locks the directory of the first of the rootimg,
rootimgtree, kernel and ramdisk that the bundle has.
imgimport wrote the image definition before it published the root
image. When the publication failed, as when another host held the
publication lock, the import failed with the new definition and the
previous files.
imgimport now places the root image, kernel and ramdisk first, then
writes the image definition, then places the other files. A later
failure leaves the definition that matches the published boot files,
as before. Before it writes anything, imgimport also opens the tables
of the image definition without autocommit, as it writes them. A table
that it cannot open then leaves the files as they were.
imgimport moved the boot files and kits of a bundle without a check,
and copied the extra files after it had already written the image. A
bundle without its kernel or a kit then gave a broken image without
an error. A missing extra file failed the import after it published
the root image and wrote the image definition.
imgimport now checks the boot files, kits, extra files and raw image
files that the manifest names. It does this before it writes anything,
and reports each missing file.
imgimport -n checked its nodes when it set their postscripts. By then
it had published the root image, placed the other files and written the
image definition. An undefined node then left a half-imported image.
imgimport now checks the nodes before it writes anything, and fails
with the same error.
kvm.pm made $parser, $node, $confdata and $updatetable package
variables so that kvm_uefi_firmware.t could set them and call
build_xmldesc and reconfigvm. That exposes plugin state to make it
testable, which xCAT::KVMUtils replaced for the other guest decisions.
xCAT::KVMUtils now holds vm_othersettings, requested_firmware,
firmware_error, guest_os, clock_offset and reconfigure_domain. Each one
takes its inputs as arguments. guest_os replaces build_oshash and the
<os> edits in build_xmldesc. reconfigure_domain replaces the XML
rewrite in reconfigvm and loads XML::LibXML when it is called. kvm.pm
calls these subs, and the four variables are file lexicals again.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
stage_genesis_payload() discarded the exit status of restorecon, so mknb
reported success with the staged kernel still carrying the context of the xCAT
install tree. The routine now returns that status, the kernel path and a message
that names the relabel, and process_request reports it. A failed copy keeps its
own message.
selinux_context.sh reads the exit status of restorecon -F -n -v before its
output, so a non-zero exit with no output is a failure.
The helper also resolves the name mknb stages instead of the architecture it was
given: the exact architecture when an OpenEmbedded export is installed, ppc64
for the legacy POWER image. When that kernel is absent it lists the kernels that
are present, so a mapping that no longer matches mknb is named rather than read
as a missing file.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
mknb stages the legacy Genesis kernel with cp -a, which implies --preserve=all
and copies the SELinux context of /opt/xcat/share/xcat/netboot/genesis with it.
On a management node with SELinux enabled the kernel then carries usr_t, while
the policy declares tftpdir_t for that path. Measured on an el9 management node,
restorecon -nvR /tftpboot names genesis.kernel.x86_64 and no other path, so it
is the one file xCAT mislabels under the TFTP root. Nothing in the netboot path
relabels it.
stage_genesis_payload now copies with --no-preserve=context,xattr, and runs
restorecon -F on the staged kernel when xCAT::Utils->isSELINUX reports SELinux
enabled. xattr goes with context because cp stores the context in the
security.selinux xattr, so --no-preserve=context alone still copies it. The
relabel corrects a kernel that an earlier xCAT staged, because a copy over an
existing file keeps that file's context. A failed relabel does not fail the
step.
mknb_genesis_staging.t reports SELinux as disabled, so its command counts stay
about the copies it tests.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
preferred_video_model returned vga whenever no preferred model was
found, also when the hypervisor did not offer vga, did not support video,
or the capability query failed. Under native aarch64 KVM, vga and the
other PCI framebuffer models do not display correctly.
An aarch64 guest now takes the first offered model of virtio and ramfb
under KVM, or of virtio, vga and ramfb under TCG. When video is
unsupported or no wanted model is offered, build_xmldesc writes no
<video> and no <graphics>, and the guest uses its serial console. When
the capabilities are unavailable, build_xmldesc returns an error that
names the query error and vm.vidmodel.
vm.vidmodel still overrides the choice. Other architectures do not
query the capabilities and keep their fixed model.
Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
tabrestore stripped the comma after each field, so a comma after the
field of the last column left nothing to report. A row with one more
empty field was restored as if it fit the columns. A last extra field
of 0 also passed, because the check tested the rest of the line for
truth.
tabrestore now refuses a row whose last column field ends with a comma,
or that has any text left, and rolls back the restore.
The kit commands refuse RHEL 8 and later, but compared the release as a
string. "10.1" sorts before "8", so the kit commands ran on RHEL 10.
They now compare the major release as a number.
imgexport records an extra file with its destination directory. When
that directory did not exist, imgimport copied the file to the path of
the directory, so the file took the name of the directory. When a file
was at that path, imgimport replaced it.
imgimport now creates the destination directory and its missing
parents, as it does for an extra directory. A file at that path fails
the import and stays as it was. The copy runs without a shell, so a
file name with glob characters cannot match another file. A failed
backup of the previous file now fails the import.
kit.pm tested the bareword locked instead of $locked. The test was
always false, so a kit command never took the kit lock, and it ran also
while another process held the lock.
A kit command now takes the lock in one step, and fails while another
process holds it. The is_locked probe is gone, because its release
removed the lock file that another kit command could then hold. A kit
command that another kit command runs goes on under the lock of that
command.
imgimport looked up the litefile entries for all images with "image" =
'ALL'. MySQL takes a double-quoted name for a string, so the lookup
found nothing, and imgimport added entries that an ALL entry already
covered. The lookup now quotes the column the way the database needs.
The removal of abandoned stages, the removal of the other archive
formats after a publication, and rmimage found their files with glob.
glob splits a pattern at a space, so for an image directory such as
"/install/custom images/node" the first word named another path.
rmtree then removed that directory, with its images. glob also takes a
wildcard character in the path of the image directory as a pattern.
image_dir_entries now lists the image directory itself and matches the
names of its entries, and these removals use it.
A failed publication put back only the content of the previous checksum
file. A checksum symlink became a regular file, which a later switch of
the symlinks would leave stale.
publish_rootimg now keeps the previous checksum entry, and a rollback
renames it back. When that rename fails, the previous content goes
back, and the error reports it.
When a failed publication could not put back the previous archive or
metainfo, it moved them to a .rootimg-previous-* directory. When that
move failed too, they stayed in the staging directory, which packimage,
liteimg and imgimport then removed. The only copy of the previous files
was lost.
Staging that keeps a previous file now stays, and the error names it.
The removal of abandoned stages leaves it, and rmimage removes it with
the image. A publication removes its previous files from staging
otherwise, so only a failed one leaves them.
When a publication failed, the rollback put back the previous metainfo
and checksum without checking either step. A metainfo that could not go
back stayed in staging, which cleanup then removed, and the rollback
reported nothing. The rollback now checks each step. It moves a previous
metainfo that cannot go back next to the image, as it does with a
previous archive, and reports where. It also reports a checksum that it
cannot put back.
When no archive was published before, as for the first pack or a change
of format, and the metainfo rename failed after the archive rename, the
rollback looked for a previous archive that did not exist. It reported
that archive as kept in an empty directory, and left the new archive and
its checksum published. The rollback now removes the new archive and its
checksum.
rmimage removed rootimg.* from the image directory. That missed rootimg-
statelite.gz with its checksum and metainfo, and the .rootimgcheck
marker of the initial ramdisk. A temporary directory that an interrupted
packimage, liteimg or imgimport left on this host also stayed, with a
partial archive in it.
rmimage now removes these files, the temporary directories that writers
on this host abandoned, and the .rootimg-previous-* directories that
failed publications kept. rootimg_stage and rmimage share this cleanup
through remove_abandoned_rootimg_stages.
A SLES statelite ramdisk image built with dracut boots
initrd-stateless.gz, but nodeset copied only initrd-statelite.gz to the
TFTP directory and checked only for that file. Nodes requested an initial
ramdisk that nodeset never copied, or one that an older nodeset left.
nodeset now chooses the initial ramdisk once, then copies, checks and
boots that file, as it does on Red Hat.
The statelite branch of debian.pm tested rootfstype without its $, so it
compared the string rootfstype with ramdisk and always took the NFS root
branch. Ubuntu statelite ramdisk nodes got an NFS root and no imgurl, so
they never downloaded rootimg-statelite.gz.
nodeset now tests $rootfstype, and Ubuntu statelite ramdisk nodes get
the imgurl of rootimg-statelite.gz, as on Red Hat and SUSE.
The root image check is on by default, so an upgrade from a release
without it would turn it on for every existing stateless and statelite
image. Their nodes would then need a checksum and an initial ramdisk
that can check.
On an upgrade, while site.rootimgchecksum is not set, xcatconfig sets
the rootimgchecksum attribute to no for each of these images that does
not set it, and then sets site.rootimgchecksum to yes. The existing
images keep booting unchecked, and new images get the check. A later
upgrade finds the site attribute set and changes nothing. A new
installation sets site.rootimgchecksum to yes.