2
0
mirror of https://github.com/xcat2/confluent.git synced 2026-11-25 20:02:38 +00:00

Label overlay upper layer of suse16 diskless images for SELinux

The initramfs writes the overlay upper layer before the SELinux policy
is loaded, so those files are unlabeled_t. On an enforcing image /
itself is unlabeled, and logind, getty and sshd fail.

Label exactly the upper layer paths like el9-diskless does. The root
is an overlay in untethered mode too, so this covers both. chcon comes
from the image, the initramfs has none.
This commit is contained in:
Markus Hilger
2026-10-31 01:37:16 +01:00
parent 91370cb8a8
commit 551658b5fe
@@ -134,4 +134,38 @@ if [ -d /lib/firmware ]; then
fi
ln -s /sysroot/lib/firmware /lib/firmware
chroot /sysroot chkstat --system --set --noheader > /dev/null
if [ -x /sysroot/usr/sbin/matchpathcon ] && grep -Eq '^SELINUX=(enforcing|permissive)' /sysroot/etc/selinux/config 2> /dev/null; then
# Files written to the upper layer before policy load are unlabeled.
# Label only those, using globstar since the initramfs has no find.
selinuxpolicy=$(sed -n 's/^SELINUXTYPE=//p' /sysroot/etc/selinux/config)
fcontexts=/etc/selinux/$selinuxpolicy/contexts/files/file_contexts
shopt -s globstar dotglob nullglob
relabel=()
if [ -f /tmp/mountparts.sh ]; then
overlayparts=$(awk '{print $3}' /tmp/mountparts.sh)
else
overlayparts=/mnt/remote
fi
for srcmount in $overlayparts; do
upperdir=/mnt/overlay/upper
if [ -f /tmp/mountparts.sh ]; then
upperdir=/mnt/overlay${srcmount}/upper
fi
prefix=${srcmount#/mnt/remote}
prefix=${prefix%/}
relabel+=("${prefix:-/}")
for relpath in "$upperdir"/**; do
relabel+=("$prefix${relpath#$upperdir}")
done
done
shopt -u globstar dotglob nullglob
# Not setfiles (recurses into the image) or restorecon (no-op before policy load).
# The initramfs has no chcon, the image does.
chroot /sysroot /usr/sbin/matchpathcon -f $fcontexts "${relabel[@]}" | while IFS=$'\t' read -r relpath context; do
# deleted files leave whiteouts in the upper layer
if [ "$context" != "<<none>>" ] && { [ -e "/sysroot$relpath" ] || [ -L "/sysroot$relpath" ]; }; then
chroot /sysroot chcon -h "$context" "$relpath"
fi
done
fi
exec /opt/confluent/bin/start_root