2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-19 17:02:15 +00:00

fix(xcat-core): the documented repair of a published artifact relabels the guest trees

The SELinux page told the operator to run chcon -R -t public_content_t over the
image root to repair a published artifact that kept an older type. That command
walks into rootimg and rootimg-statelite, so it replaces the labels of the guest
operating system with public_content_t. The xcat.fc comment carried the same
advice. chcon also writes a type that no mapping selects, so the next relabel of
a path that has a mapping reverts it: the repair held only until then.

The page now maps each published artifact with semanage fcontext and applies the
mapping with restorecon. Each expression names one regular file directly below
the image root, so no path in either guest tree matches one, and both trees keep
the <<none>> of the packaged mappings. The procedure reads the publication
directory from site.installdir, and a site that moved it maps the configured
directory and keeps both guest trees out of that mapping. The page says why a
tree mapping over the image root is the same defect as the chcon.

xCAT-test/native/selinux_image_repair.t passes 170 of 170 checks with the
documented procedure. With the chcon of the previous page it fails 101, 36 of
them guest labels. selinux_docs.t fails 7 of 26 on the parent commit.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
Daniel Hilst
2026-10-22 18:25:33 -03:00
parent 576370bdf9
commit 78f6d65a7c
2 changed files with 44 additions and 8 deletions
+42 -6
View File
@@ -85,14 +85,50 @@ that ``restorecon`` already made ``public_content_t``, and a new file inherits
the type of its directory, so the kernel is ``public_content_t`` and ``httpd``
serves it. Netboot works.
The cost is a path that already carries another type, from before the package
was installed or from a ``chcon``. It keeps that type, and ``restorecon`` over
``/install`` cannot repair it, with or without ``-F``: there is no context to
apply. Set it directly::
The cost is a published artifact of such an image root that already carries
another type, from before the package was installed. ``restorecon`` over the
publication directory cannot repair it, with or without ``-F``, because the
path has no context to apply. Give it one.
chcon -R -t public_content_t /install/netboot/rootimg/rhels9/x86_64/compute
``site.installdir`` selects the publication directory. Read it, and map each
published artifact of that one image root::
A later ``restorecon`` leaves that value alone, so the repair holds.
installdir=$(lsdef -t site -i installdir -c | sed 's/^.*=//; s:/*$::')
imgroot=$installdir/netboot/rootimg/rhels9/x86_64/compute
for name in kernel hypervisor 'initrd[^/]*' 'rootimg\.[^/]*' \
'rootimg-statelite\.[^/]*' 'rootimgtree\.[^/]*' \
'litefile\.csv' 'common\.filelist'; do
semanage fcontext -a -t public_content_t -f f "$imgroot/$name"
done
restorecon -R -v "$imgroot"
Each expression names one regular file directly below the image root, so no
path in ``$imgroot/rootimg`` or ``$imgroot/rootimg-statelite`` matches one.
Both guest trees keep the ``<<none>>`` of the packaged mappings, and
``restorecon`` leaves every file in them alone. ``file_contexts.local`` is read
after the packaged file, and the last expression that matches a path wins, so
each mapping above wins against ``/install(/.*)?/rootimg(/.*)?``.
Do not repair a label with ``chcon``, and do not map the image root as a tree.
``chcon`` writes a type that no mapping selects, so the next relabel of a path
that has a mapping reverts it, and a recursive ``chcon`` relabels both guest
trees as well. A tree mapping over the image root relabels them through
``restorecon`` instead.
The packaged mappings name ``/install``. A site that moved ``site.installdir``
maps the configured directory, and keeps both guest trees out of that mapping::
semanage fcontext -a -t public_content_t "$installdir(/.*)?"
semanage fcontext -a -t '<<none>>' "$installdir(/.*)?/rootimg(/.*)?"
semanage fcontext -a -t '<<none>>' "$installdir(/.*)?/rootimg-statelite(/.*)?"
restorecon -R -v "$installdir"
A mapping is persistent, so a later recursive relabel and a policy upgrade both
keep the result. ``xCAT-test/native/selinux_image_repair.t`` starts with the
wrong type on every published artifact and valid types in both guest trees,
runs each procedure, and reads the labels back after a recursive relabel and
after a reinstall of the module.
The unit holds ``/opt/xcat`` as the default prefix, and ``%post`` writes
``/etc/xcat/xcatroot.env`` with the prefix of the installation, which the unit
+2 -2
View File
@@ -37,8 +37,8 @@
# An entry of <<none>> keeps whatever label the path has. It does not clear one.
# genimage creates such a kernel under an image root that restorecon already
# made public_content_t, so the kernel inherits that type and httpd serves it.
# A path that carries another type keeps it, and no restorecon repairs that:
# chcon -R -t public_content_t over the image root does.
# A path that carries another type keeps it. The repair is one semanage fcontext
# mapping for that one file, then restorecon. The SELinux page carries it.
/install(/.*)?/rootimg(-statelite)?/kernel -- gen_context(system_u:object_r:public_content_t,s0)
/install(/.*)?/rootimg(-statelite)?/hypervisor -- gen_context(system_u:object_r:public_content_t,s0)
/install(/.*)?/rootimg(-statelite)?/initrd[^/]* -- gen_context(system_u:object_r:public_content_t,s0)