Skip to content

eBPF-based security platform

testing: build the runtime image without passt as root

Daniel Borkmann85fd5f7f5579
diff --git a/testing/functional/build/t1007-test-vm-cli.sh b/testing/functional/build/t1007-test-vm-cli.sh
index ca8ea0f2..918e9f03 100755
--- a/testing/functional/build/t1007-test-vm-cli.sh
+++ b/testing/functional/build/t1007-test-vm-cli.sh
@@ -339,6 +339,28 @@ test_expect_success 'a failed runtime image shows what apt could not fetch' '
grep -q "Temporary failure resolving archive.ubuntu.com" "$WORK/aptfail.out"
'
+test_expect_success 'as root the runtime image is built without passt' '
+ mkdir -p "$WORK/passt-bin" &&
+ printf "%s\n" "#!/bin/sh" "exit 0" >"$WORK/passt-bin/passt" &&
+ printf "%s\n" "#!/bin/sh" \
+ "passt --help >/dev/null 2>&1; echo \$? >\"\$GF_OUT\"" \
+ >"$WORK/passt-bin/virt-customize" &&
+ chmod +x "$WORK/passt-bin/passt" "$WORK/passt-bin/virt-customize" &&
+ env PATH="$WORK/passt-bin:$WORK/dns-bin:$PATH" GF_OUT="$WORK/passt-out" \
+ TMPDIR="$WORK" LIBGUESTFS_CACHEDIR="$WORK/passt-cache" \
+ vm/prepare-runtime.sh \
+ --rootfs "$WORK/dns-rootfs" --cache-dir "$WORK/passt-cache/img" \
+ --package-file vm/runtime-packages \
+ --runtime-key passt --key-output "$WORK/passt-cache/key" \
+ >/dev/null 2>&1 &&
+ if [ "$(id -u)" = 0 ]; then
+ test "$(cat "$WORK/passt-out")" = 127
+ else
+ test "$(cat "$WORK/passt-out")" = 0
+ fi &&
+ ! ls -a "$WORK/passt-cache/img" | grep -q no-passt
+'
+
test_expect_success 'the kernel package format follows the host package manager' '
printf "print:\n\t@echo \$(PACKAGE_FORMAT)\n" >"$WORK/print.mk" &&
format() {
diff --git a/testing/vm/prepare-runtime.sh b/testing/vm/prepare-runtime.sh
index 6185e5de..7bf64067 100755
--- a/testing/vm/prepare-runtime.sh
+++ b/testing/vm/prepare-runtime.sh
@@ -69,9 +69,24 @@ fi
TMP_IMAGE="$CACHE_DIR/.${RUNTIME_KEY}.tmp.$$"
MARKER="${TMP_IMAGE}.marker"
-cleanup() { rm -f -- "$TMP_IMAGE" "$MARKER" "${TMP_IMAGE}.nameservers"; }
+NO_PASST="${TMP_IMAGE}.no-passt"
+cleanup() {
+ rm -f -- "$TMP_IMAGE" "$MARKER" "${TMP_IMAGE}.nameservers"
+ rm -rf -- "$NO_PASST"
+}
trap cleanup EXIT
+# Started as root, passt changes to nobody before it writes its PID file
+# into the directory libguestfs keeps for root, and the appliance never
+# starts. libguestfs takes passt to be missing when "passt --help" exits
+# with neither 0 nor 1, and then networks the appliance through qemu.
+if [[ "$EUID" == 0 ]]; then
+ mkdir -p -- "$NO_PASST"
+ printf '%s\n' '#!/bin/sh' 'exit 127' >"$NO_PASST/passt"
+ chmod +x -- "$NO_PASST/passt"
+ PATH="$NO_PASST:$PATH"
+fi
+
# The cloud image is intentionally small. Enlarge the backing overlay and
# grow its existing root partition before installing the runtime packages.
qemu-img create -q -f qcow2 -F qcow2 -b "$ROOTFS" "$TMP_IMAGE"
@@ -151,4 +166,5 @@ mv -- "$TMP_IMAGE" "$IMAGE"
printf '%s\n' "$RUNTIME_KEY" >"$KEY_OUTPUT"
trap - EXIT
rm -f -- "$MARKER"
+rm -rf -- "$NO_PASST"
printf '[test-vm-runtime] ready: %s\n' "$IMAGE" >&2