2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-30 14:22:23 +00:00
Commit Graph

19 Commits

Author SHA1 Message Date
Daniel Hilst 78f6d65a7c 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>
2026-10-22 18:25:33 -03:00
Daniel Hilst 6f578741af fix(xcat-core): the comment says an unlabeled kernel stops netboot, and it does not
The file contexts leave the published kernel of a middle-rootimg image
root out of the relabel. The comment and the SELinux page read that as
the kernel being unlabeled, httpd refusing to serve it, and that osimage
losing netboot, with restorecon as the repair. Three of those four
claims are wrong.

Measured. An entry of <<none>> keeps the label a path has: restorecon
-R, restorecon -RF and setfiles -F all left a kernel at default_t, while
the same setfiles call relabeled a path that has a rule. A new file
inherits the type of its directory, so a kernel that genimage writes
into an image root already made public_content_t is public_content_t. In
the policy with the xcat module loaded, httpd_t holds one allow rule to
read public_content_t and none for default_t. So the ordinary case
serves and netboot works, and restorecon is not the repair for the case
that does not: chcon -R -t public_content_t over the image root is, and
a later relabel leaves that value alone.

selinux_file_contexts.t now starts half the custom roots at
public_content_t, which is what genimage produces, and half at
default_t, and requires each to keep its own type. It fails 324 of its
618 checks against the previous xcat.fc.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-10-21 20:03:44 -03:00
Daniel Hilst fa703a5943 fix(xcat-core): restorecon relabels a guest tree below a common directory
The published-name rules end with /install(/.*)?/rootimg(-statelite)?/common(/.*)?
and the same entry for overlay. The trailing (/.*)? takes a whole
subtree, so the entry matches a guest tree as well as a published
directory. With rootimgdir=/install/rootimg/common/compute, the guest
files rootimg/etc/shadow and rootimg-statelite/etc/shadow resolve to
public_content_t, and so does a directory called common or overlay at
the root of any guest tree. %posttrans runs restorecon -R /install, so
an install or an upgrade of the package overwrites the labels of the
guest operating system.

A common or an overlay directory one component below a rootimg component
has the same path as the same directory at the root of a guest tree, so
no rule can keep one and leave the other. Remove both entries. The
remaining entries each name one file and cannot take a tree with them.
A published common or overlay of an image root called rootimg is left
unlabeled, which restorecon over the image root repairs.

selinux_file_contexts.t fails 360 of its 618 checks without this change,
measured in a privileged almalinux:10 container on rome01.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-10-21 19:25:30 -03:00
Daniel Hilst 745d7f4d19 fix(xcat-core): the policy omits three accesses an EL9 management node makes
The policy was measured on EL10. An enforcing AlmaLinux 9.8 management
node running the same bundle logged 38 denials in xcat_t that the EL10
node did not log at all. The domain is permissive, so nothing failed,
but each one has to be granted before the domain can enforce.

Three causes, all of them EL9 running ISC DHCP where EL10 runs Kea:

- omshell reads /proc/sys/net/ipv4/ip_local_port_range before it opens
  the OMAPI socket, which is 9 read, 9 open, 9 getattr on sysctl_net_t
  and 8 dir search. makedhcp runs omshell on every ISC backend.
  kernel_read_net_sysctls covers it.
- makedhcp asks systemd to start and query dhcpd.service, whose unit
  carries dhcpd_unit_file_t. The Kea units carry systemd_unit_file_t,
  which the policy already grants, so EL10 recorded nothing.
- copycds loop-mounts the install DVD, and mount asks the kernel for the
  iso9660 and loop modules. kernel_request_load_module covers it.

The module compiles against the EL9 and the EL10 policy headers.
selinux_file_contexts.t keeps its 224 checks on EL10.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-10-21 18:04:35 -03:00
Daniel Hilst d7f579440d test(xcat-core): nothing starts xcatd without the recorded prefix file
%post writes /etc/xcat/xcatroot.env and %preun removes it, so the file
is absent on rpm --justdb, before %post runs, and after an interrupted
install. Both subtests of xcatd_relocated_startup.t have the file
present, so neither reads what happens without it.

Add a subtest that removes the file: each EnvironmentFile of the unit
carries a leading -, which makes a missing file not an error, XCATROOT
is the default of the unit, and the daemon starts with that default
instead of the installed prefix. Dropping the default XCATROOT from the
unit fails checks 4 and 7 of that subtest.

Record the trade the file contexts make for a rootimg component in the
middle of an image root: the guest labels are kept, which leaves the
published kernel of that one layout unlabeled, so httpd cannot serve it
and that osimage cannot netboot. The note names the recovery.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-10-21 17:16:06 -03:00
Daniel Hilst 07ef2be0de fix(xcat-core): a published kernel loses public_content_t beside an image root called rootimg
The exclusions match the component name rootimg anywhere under /install.
A profile may be called rootimg, and the image root is then
/install/netboot/<os>/<arch>/rootimg. The files genimage and packimage
publish in that image root, among them kernel and the initrds, sit one
component below a name the exclusions match, so each resolves to
<<none>> instead of public_content_t and httpd cannot serve it. The same
happens for a profile called rootimg-statelite.

Name each published file in the image root: kernel, hypervisor, the
initrds, the rootimg archives, rootimgtree, litefile.csv,
common.filelist, common and overlay. The entry names the component
directly below the rootimg component, so a guest file deeper in the tree
matches none of them and keeps the label of its own operating system.

selinux_file_contexts.t fails 54 of its 224 checks without this change.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-10-21 16:37:00 -03:00
Daniel Hilst 66e4cb6a6e fix(xcat-core): restorecon relabels a rootimg outside the default path
xcat.fc excluded a rootimg from the /install relabel only at
/install/netboot/<os>/<arch>/<profile>/rootimg. An osimage whose
rootimgdir has another depth got public_content_t on every guest file,
so installing or upgrading xCAT-selinux overwrote the labels of the guest
operating system.

genimage, packimage and statelite put the tree at <rootimgdir>/rootimg.
The two <<none>> entries now match a rootimg or rootimg-statelite path
component at any depth under /install. The published files beside the
tree, such as kernel, the initrds and rootimg.cpio.gz, keep
public_content_t.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-10-16 11:18:31 -03:00
Daniel Hilst 7332309040 fix(xcat-core): three paths the file contexts get wrong
The wrapper /opt/xcat/bin/genimage carried the image entrypoint, so a
command that writes a request to the socket ran with the authority to
relabel every type. It is now a client. The build still reaches
xcat_image_t: the plugin, and the --interactive mode of the wrapper, run the
per-OS program through a shell, and that exec transitions from either caller
domain.

The per-OS geninitrd gets its own line, because most of those names are
symlinks to their sibling genimage but netboot/fedora12/geninitrd is a real
program, and the genimage glob never matches it.

/opt/xcat/bin/xcatDBcmds is labelled as a client. It is the third
dispatcher, reached by 12 symlinks including lsdef, chdef, mkdef and rmdef,
and without this they ran in the caller's domain while rpower ran in xcat_t.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-10-15 16:23:54 -03:00
Daniel Hilst c4934af926 fix(xcat-core): xCAT cannot stop the TFTP server it started
setup_tftpd kills a stray in.tftpd before it starts its own (AAsn.pm:1382).
With the server now in tftpd_t the signal crossed a domain boundary and was
refused: xcat_t tftpd_t:process { signal signull }, found by the enforcing
check after the transition landed.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-10-15 15:35:08 -03:00
Daniel Hilst ef70cc4e79 fix(xcat-core): the setfiles transition costs denials and buys nothing
seutil_domtrans_setfiles(xcat_image_t) put restorecon in the stock
setfiles_t domain during an image build. That domain is enforcing, and it
cannot append to the pipe it inherits from its caller: every enforcing run
carried 20 denials in setfiles_t, 13 of them `etc_t:file map`, 4
`xcat_t:fifo_file append` and 3 `public_content_t:chr_file write`. The runs
passed, because restorecon only loses its output, and the denials were
invisible to a count filtered on the xCAT domains.

The transition also removed no authority: xcat_image_t already relabels
every type, so the relabel is the same work in a different domain. The line
is gone and the comment records why.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-10-15 15:33:40 -03:00
Daniel Hilst 4e35eebfbd fix(xcat-core): the policy package does not repair a stale label
%posttrans relabelled /install only. A path under /opt/xcat whose context
was wrong before the package arrived kept it, because rpm does not relabel a
directory that already exists and nothing else ran restorecon there.

%posttrans now relabels /opt/xcat too, so installing or updating the policy
brings the product tree to the contexts the module declares.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-10-15 15:15:39 -03:00
Daniel Hilst 6eb1d71317 feat(xcat-core): keep the TFTP server out of the xCAT domain
AAsn.pm starts /usr/sbin/in.tftpd with system() and no systemd unit, so the
daemon inherited xcat_t: a persistent listener on UDP 69, reachable from every
node of the provisioning network, held the authority of the domain that also
writes the image tree and reaches the database.

xcat.te now transitions from xcat_t to the stock tftpd_t on tftpd_exec_t.
tftp.if carries no tftp_domtrans, so the pattern and the three inherited
process permissions are written out.

Measured on xcat163-mn-tmp-286 with both xCAT domains enforcing and dontaudit
disabled: in.tftpd runs as system_u:system_r:tftpd_t:s0 and still owns port 69,
a TFTP fetch of /tftpboot/xcat/xnba.kpxe returns the file, and both flat
provisioning cases pass -- diskless 1177 s, which netboots the compute node
over that server, and diskful 654 s. Zero denials in xcat_t, xcat_image_t and
tftpd_t.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-10-15 10:37:57 -03:00
Daniel Hilst ca04e2c8ae fix(xcat-core): the image build cannot open the fifo dnf writes its progress to
The last two enforced denials of the enforcing run were
xcat_image_t tmp_t:fifo_file create. Neither provisioning case failed on
them, because dnf falls back to its plain output, but the grant belongs
with the rest of the /tmp set of that domain.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-10-15 03:16:26 -03:00
Daniel Hilst 078f607448 feat(xcat-core): build the image in a domain of its own
The policy granted xcat_t everything the image build needs, so the domain
that listens on the xcatd port could also write and relabel a file of any
type. The rules were one per target type, 558 of them from the measured
denials, and 85 per cent of those repeated one of 58 permission patterns.

xcat.te now carries two domains. xcat_image_t is entered through
/opt/xcat/bin/genimage and the per-OS genimage program, from xcat_t and
from the administrator, and it holds the filesystem-wide manage and relabel
grants: the build creates an operating system tree, and the kernel cannot
tell a path inside that tree from the same type on the management node.
xcat_t keeps the daemon surface -- its sockets and ports, /install,
/tftpboot, /etc, the credentials, the service class for the units it
restarts -- and no grant over the file_type attribute.

The rules are Reference Policy interface calls where one exists:
domain_read_all_domains_state replaces 93 of them, dev_getattr_all_chr_files
31, files_read_etc_files, auth_read_shadow, seutil_read_config,
logging_send_syslog_msg, fs_mount_all_fs and corecmd_exec_bin the rest. The
module is 203 statements where the generated set was 806 rules.

packimage and liteimg are symlinks to xcatclientnnr, so their work runs in
the xcatd plugin and the tree authority stays in xcat_t with them. It can
move to xcat_image_t when the plugin execs a helper instead.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-10-15 02:28:20 -03:00
Daniel Hilst 7f5cf08ad8 fix(xcat-core): the erase of xCAT-selinux leaves three files unlabeled_t
%postun removed the module and relabelled nothing, so the two entrypoint
types left the policy while three files still carried them. The files
became unlabeled_t, and /install kept public_content_t, which the stock
policy does not define for it.

%preun now saves the file contexts, because %pre does not run on an erase,
and %postun relabels after the module is removed, on an erase only.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-10-14 17:33:44 -03:00
Daniel Hilst 7086f2de95 fix(xcat-core): a client command cannot exec under enforcing
The transition into xcat_t computes unconfined_u:unconfined_r:xcat_t, and
the module did not authorize unconfined_r for that type. The context is
then invalid, so the kernel refuses the exec of the interpreter and the
command fails with "bad interpreter: Permission denied". Every client
command run by the administrator or the CI failed this way on an enforcing
node, while xcatd itself was unaffected: a daemon domain carries the daemon
attribute, which system_r already holds.

xcat.te now states "role unconfined_r types xcat_t" beside the transition.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-10-14 17:28:27 -03:00
Daniel Hilst 0f0c2a1f94 feat(xcat-core): run xcatd and the xCAT clients in the xcat_t domain
xCAT had no process domain. xcatd ran in unconfined_service_t, where the
policy constrains nothing, and each client command ran in the domain of its
caller. The module could therefore only grant access to other services.

xcat.te declares the xcat_t domain, the xcatd_exec_t and xcat_client_exec_t
entrypoints, the transition from systemd, and the transition from
unconfined_t for a client command. xcat.fc labels /opt/xcat/sbin/xcatd and
the two xcatclient scripts, which 115 command names reach through a symlink.

xcat_t is permissive, and the policy source declares it. The host stays
enforcing, and the CI collects the accesses the domain needs. The module
grants the domain one access of its own: the execute of the interpreter that
its Perl entrypoint names. A confined user domain gets no transition, so it
keeps its own confinement.

The module compiles at version 19 in the alma+epel-10-x86_64 mock root, and
the binary carries (typepermissive xcat_t) and both type transitions.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-10-14 16:55:21 -03:00
Daniel Hilst b293dfe744 fix(xcat-core): the policy module omits five measured accesses
The xcat policy module granted httpd read of /tftpboot and let xcatws.cgi
connect to the xcatd port. Five further accesses were measured denied on a
management node and are not granted, so an enforcing node fails at them.

httpd mmaps the per-node xnba boot config it serves out of /tftpboot.
read_file_perms does not hold map, so the module now grants
mmap_read_file_perms. Two sites recorded this denial three days apart, on
xCAT 2.19.1 and 2.20.

xdcp and "updatenode -F" copy /etc/shadow to the nodes and into a rootimg.
rsync_export_all_ro holds that read and rsync_full_access does not grant it,
because shadow_t is not in non_auth_file_type. rsync also writes a target it
created at mode 0000, which needs CAP_DAC_OVERRIDE. Both rules are reached only
where rsync runs in rsync_t, which needs a system-service caller.

genimage installs packages into a rootimg with yum in a chroot, and useradd and
groupadd read the rootimg /var/run symlink from the rpm scriptlets. The symlink
carries public_content_t because the rootimg is under /install, and the base
grant for that read names public_content_t nowhere.

The module compiles at version 19 in the alma+epel-10-x86_64 mock root, and the
five types reach the binary.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-10-14 16:45:20 -03:00
Daniel Hilst 414504d069 feat(xcat-core): add the xCAT-selinux policy package
xCAT shipped no SELinux policy. On an enforcing management node httpd
could not read /install, which had no file context, or the /tftpboot
files that xcat.conf serves, and xcatws.cgi could not connect to xcatd.

The new noarch xCAT-selinux package builds the xcat module with the
selinux-policy-devel Makefile. The module labels /install
public_content_t and leaves each rootimg tree out of the relabel. It lets
httpd read tftpdir_t and lets httpd_sys_script_t connect to ntop_port_t.
The scriptlets use the selinux-policy macros, and %posttrans relabels
/install. They do not change the SELinux mode.

checkmodule writes module version 19, so the package built in the EL10
mock root installs on EL8, EL9 and EL10. On a Red Hat family build,
xCAT-server and xCATsn require xCAT-selinux when selinux-policy-targeted
is installed. SUSE and Debian builds do not change.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-10-14 16:45:20 -03:00