From e0be3ce5f7ccb3eb58e550625a4cbe3b6aff50aa Mon Sep 17 00:00:00 2001 From: Markus Hilger Date: Fri, 30 Oct 2026 17:18:25 +0100 Subject: [PATCH] Label disk installs of diskless images for SELinux at the end The install runs before a policy is loaded, so the module index from kernel-install and files of later post scripts stayed unlabeled and systemd-modules-load failed. Relabel every local filesystem last. --- .../el8-diskless/profiles/default/scripts/post.sh | 9 +++++---- .../el9-diskless/profiles/default/scripts/post.sh | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/confluent_osdeploy/el8-diskless/profiles/default/scripts/post.sh b/confluent_osdeploy/el8-diskless/profiles/default/scripts/post.sh index 23e13dfe..c1c8af11 100644 --- a/confluent_osdeploy/el8-diskless/profiles/default/scripts/post.sh +++ b/confluent_osdeploy/el8-diskless/profiles/default/scripts/post.sh @@ -25,10 +25,6 @@ mkdir -p /opt/confluent/bin curl -f https://$confluent_mgr/confluent-public/os/$confluent_profile/scripts/firstboot.sh > /opt/confluent/bin/firstboot.sh chmod +x /opt/confluent/bin/firstboot.sh systemctl enable firstboot -selinuxpolicy=$(grep ^SELINUXTYPE /etc/selinux/config |awk -F= '{print $2}') -if [ ! -z "$selinuxpolicy" ]; then - setfiles /etc/selinux/${selinuxpolicy}/contexts/files/file_contexts /etc/ -fi run_remote_python syncfileclient run_remote post.custom # post scripts may be placed into post.d, e.g. post.d/01-firstaction.sh, post.d/02-secondaction.sh @@ -39,6 +35,11 @@ run_remote_config post.d cd /root/ fetch_remote confignet +selinuxpolicy=$(grep ^SELINUXTYPE /etc/selinux/config |awk -F= '{print $2}') +if [ ! -z "$selinuxpolicy" ] && grep -Eq '^SELINUX=(enforcing|permissive)' /etc/selinux/config; then + # Label what the install wrote, setfiles does not cross mounts + setfiles /etc/selinux/${selinuxpolicy}/contexts/files/file_contexts $(awk '$3 ~ /^(xfs|ext[34]|btrfs)$/ {print $2}' /proc/mounts) || echo "Warning: SELinux labeling failed" +fi curl -sf -X POST -d 'status: staged' -H "CONFLUENT_NODENAME: $nodename" -H "CONFLUENT_APIKEY: $confluent_apikey" https://$confluent_mgr/confluent-api/self/updatestatus kill $logshowpid diff --git a/confluent_osdeploy/el9-diskless/profiles/default/scripts/post.sh b/confluent_osdeploy/el9-diskless/profiles/default/scripts/post.sh index 0a09299b..1c37913a 100644 --- a/confluent_osdeploy/el9-diskless/profiles/default/scripts/post.sh +++ b/confluent_osdeploy/el9-diskless/profiles/default/scripts/post.sh @@ -32,10 +32,6 @@ mkdir -p /opt/confluent/bin curl -f https://$confluent_websrv/confluent-public/os/$confluent_profile/scripts/firstboot.sh > /opt/confluent/bin/firstboot.sh chmod +x /opt/confluent/bin/firstboot.sh systemctl enable firstboot -selinuxpolicy=$(grep ^SELINUXTYPE /etc/selinux/config |awk -F= '{print $2}') -if [ ! -z "$selinuxpolicy" ]; then - setfiles /etc/selinux/${selinuxpolicy}/contexts/files/file_contexts /etc/ -fi run_remote_python syncfileclient run_remote post.custom # post scripts may be placed into post.d, e.g. post.d/01-firstaction.sh, post.d/02-secondaction.sh @@ -48,6 +44,11 @@ fetch_remote confignet # rebuild initrd, pick up new drivers if needed dracut -f /boot/initramfs-$(uname -r).img $(uname -r) +selinuxpolicy=$(grep ^SELINUXTYPE /etc/selinux/config |awk -F= '{print $2}') +if [ ! -z "$selinuxpolicy" ] && grep -Eq '^SELINUX=(enforcing|permissive)' /etc/selinux/config; then + # Label what the install wrote, setfiles does not cross mounts + setfiles /etc/selinux/${selinuxpolicy}/contexts/files/file_contexts $(awk '$3 ~ /^(xfs|ext[34]|btrfs)$/ {print $2}' /proc/mounts) || echo "Warning: SELinux labeling failed" +fi curl -sf -X POST -d 'status: staged' -H "CONFLUENT_NODENAME: $nodename" -H "CONFLUENT_APIKEY: $confluent_apikey" https://$confluent_websrv/confluent-api/self/updatestatus kill $logshowpid