From 4cfde2bafb79e54ffdb3cb1e5f93c5cd37aa8ad7 Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Sat, 31 Oct 2026 10:04:11 +0000 Subject: hooks: T9553: drop file capabilities while running live-build chroot hooks vyos-1x grants cap_sys_module to kmod and cap_sys_time to date. In a build container whose capability bounding set lacks these (e.g. a default Proxmox LXC), the kernel refuses to execute both binaries, even as root. mkinitramfs ignores the failing modprobe calls and silently produces an initrd without any kernel modules - the ISO builds fine but cannot find its boot medium. The capabilities are now removed while the chroot hooks run and restored afterwards. The initramfs is regenerated before restoring them and live-build is told to skip its own final regeneration, which would otherwise run with the capabilities back in place. The build now fails if the initrd lacks the squashfs module. --- .../hooks/live/00-drop-file-caps.chroot | 15 +++++++++++ .../hooks/live/99-restore-file-caps.chroot | 31 ++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 data/live-build-config/hooks/live/00-drop-file-caps.chroot create mode 100644 data/live-build-config/hooks/live/99-restore-file-caps.chroot diff --git a/data/live-build-config/hooks/live/00-drop-file-caps.chroot b/data/live-build-config/hooks/live/00-drop-file-caps.chroot new file mode 100644 index 00000000..29612d8b --- /dev/null +++ b/data/live-build-config/hooks/live/00-drop-file-caps.chroot @@ -0,0 +1,15 @@ +#!/bin/sh + +# vyos-1x grants file capabilities to some binaries. If the build container's +# capability bounding set lacks them (e.g. Proxmox LXC drops sys_module and +# sys_time), exec fails with EPERM - mkinitramfs then silently produces an +# initrd without any kernel modules. Drop them for the duration of the hooks, +# 99-restore-file-caps.chroot puts them back. + +CAPS_FILE=/tmp/vyos-file-caps + +getcap /usr/bin/kmod /usr/bin/date > $CAPS_FILE +while read -r file caps; do + echo "I: Temporarily dropping file capabilities from $file" + setcap -r $file +done < $CAPS_FILE diff --git a/data/live-build-config/hooks/live/99-restore-file-caps.chroot b/data/live-build-config/hooks/live/99-restore-file-caps.chroot new file mode 100644 index 00000000..2243f4cc --- /dev/null +++ b/data/live-build-config/hooks/live/99-restore-file-caps.chroot @@ -0,0 +1,31 @@ +#!/bin/sh + +# Restore file capabilities dropped by 00-drop-file-caps.chroot + +CAPS_FILE=/tmp/vyos-file-caps + +if [ ! -f $CAPS_FILE ]; then + echo "E: $CAPS_FILE missing, cannot restore file capabilities" + exit 1 +fi + +# live-build's chroot_hacks regenerates the initramfs after all hooks, which +# would run with the capabilities restored. Do it here instead and tell +# live-build to skip it. +echo "I: Regenerating initramfs before restoring file capabilities" +update-initramfs -k all -t -u || exit 1 +touch /initrd.img_has_already_been_regenerated + +# mkinitramfs ignores modprobe failures - without squashfs the image is unbootable +for initrd in /boot/initrd.img-*; do + if ! lsinitramfs $initrd | grep -q '/squashfs\.ko'; then + echo "E: $initrd contains no squashfs module!" + exit 1 + fi +done + +while read -r file caps; do + echo "I: Restoring file capabilities $caps on $file" + setcap $caps $file || exit 1 +done < $CAPS_FILE +rm -f $CAPS_FILE -- cgit v1.2.3