diff options
Diffstat (limited to 'data')
| -rw-r--r-- | data/live-build-config/hooks/live/00-drop-file-caps.chroot | 15 | ||||
| -rw-r--r-- | data/live-build-config/hooks/live/99-restore-file-caps.chroot | 31 |
2 files changed, 46 insertions, 0 deletions
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 |
