diff --git a/docs/source/advanced/selinux/index.rst b/docs/source/advanced/selinux/index.rst index 7189d199a2..95e20525c6 100644 --- a/docs/source/advanced/selinux/index.rst +++ b/docs/source/advanced/selinux/index.rst @@ -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 ``<>`` 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 '<>' "$installdir(/.*)?/rootimg(/.*)?" + semanage fcontext -a -t '<>' "$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 diff --git a/xCAT-selinux/xcat.fc b/xCAT-selinux/xcat.fc index cb637372c6..b8ed67a361 100644 --- a/xCAT-selinux/xcat.fc +++ b/xCAT-selinux/xcat.fc @@ -37,8 +37,8 @@ # An entry of <> 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)