From: Luke T. Shumaker Date: Wed, 21 Aug 2024 23:29:10 +0000 (-0600) Subject: test: add a testcase for unprivileged nspawn X-Git-Tag: v257-rc1~515^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=93c15c6d4354da9dc8a2f6e1fbb978004d1485c4;p=thirdparty%2Fsystemd.git test: add a testcase for unprivileged nspawn Right now it mostly duplicates a test that already exists in TEST-50-DISSECT.mountfsd.sh, but it serves as a template for more unprivileged nspawn tests. --- diff --git a/test/TEST-13-NSPAWN/test.sh b/test/TEST-13-NSPAWN/test.sh index 3ab52d0eee2..b1d9fb6c53a 100755 --- a/test/TEST-13-NSPAWN/test.sh +++ b/test/TEST-13-NSPAWN/test.sh @@ -20,6 +20,10 @@ test_append_files() { # for IPMasquerade= instmods "=net/netfilter" generate_module_dependencies + # For unprivileged mountfsd. + if command -v openssl >/dev/null 2>&1; then + inst_binary openssl + fi # Create a dummy container "template" with a minimal toolset, which we can # then use as a base for our nspawn/machinectl tests diff --git a/test/units/TEST-13-NSPAWN.nspawn.sh b/test/units/TEST-13-NSPAWN.nspawn.sh index 339ad6b3c4f..b0408e55b7e 100755 --- a/test/units/TEST-13-NSPAWN.nspawn.sh +++ b/test/units/TEST-13-NSPAWN.nspawn.sh @@ -42,6 +42,9 @@ at_exit() { mountpoint -q /var/lib/machines && umount --recursive /var/lib/machines rm -f /run/systemd/nspawn/*.nspawn + + rm -fr /var/tmp/TEST-13-NSPAWN.* + rm -f /run/verity.d/test-13-nspawn-*.crt } trap at_exit EXIT @@ -1031,4 +1034,82 @@ EOF rm -fr "$root" } +can_do_rootless_nspawn() { + # Our create_dummy_ddi() uses squashfs and openssl. + command -v mksquashfs && + command -v openssl && + + # mountfsd must be enabled... + [[ -S /run/systemd/io.systemd.MountFileSystem ]] && + # ...and have pidfd support for unprivileged operation. + systemd-analyze compare-versions "$(uname -r)" ge 6.5 && + systemd-analyze compare-versions "$(pkcheck --version | awk '{print $3}')" ge 124 && + + # nsresourced must be enabled... + [[ -S /run/systemd/userdb/io.systemd.NamespaceResource ]] && + # ...and must support the UserNamespaceInterface. + ! (SYSTEMD_LOG_TARGET=console varlinkctl call \ + /run/systemd/userdb/io.systemd.NamespaceResource \ + io.systemd.NamespaceResource.AllocateUserRange \ + '{"name":"test-supported","size":65536,"userNamespaceFileDescriptor":0}' \ + 2>&1 || true) | + grep -q "io.systemd.NamespaceResource.UserNamespaceInterfaceNotSupported" +} + +create_dummy_ddi() { + local outdir="${1:?}" + local container_name="${2:?}" + + cat >"$outdir"/openssl.conf <"$tmpdir/stdout.txt" + echo hello | cmp "$tmpdir/stdout.txt" - +} + run_testcases