mirror of
https://github.com/NixOS/nix
synced 2025-06-24 22:11:15 +02:00
functional-tests: skip tests if the kernel restricts unprivileged user namespaces
Update tests/functional/common/functions.sh Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
This commit is contained in:
parent
f1187cb696
commit
da7f7ba810
12 changed files with 22 additions and 6 deletions
|
@ -8,6 +8,7 @@ TODO_NixOS
|
|||
restartDaemon
|
||||
|
||||
requireSandboxSupport
|
||||
requiresUnprivilegedUserNamespaces
|
||||
[[ $busybox =~ busybox ]] || skipTest "no busybox"
|
||||
|
||||
unset NIX_STORE_DIR
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
# shellcheck disable=SC2154
|
||||
|
||||
requireSandboxSupport
|
||||
requiresUnprivilegedUserNamespaces
|
||||
[[ "$busybox" =~ busybox ]] || skipTest "no busybox"
|
||||
|
||||
unset NIX_STORE_DIR
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
: "${file?must be defined by caller (remote building test case using this)}"
|
||||
|
||||
requireSandboxSupport
|
||||
requiresUnprivilegedUserNamespaces
|
||||
[[ "${busybox-}" =~ busybox ]] || skipTest "no busybox"
|
||||
|
||||
# Avoid store dir being inside sandbox build-dir
|
||||
|
@ -27,6 +28,7 @@ builders=(
|
|||
chmod -R +w "$TEST_ROOT/machine"* || true
|
||||
rm -rf "$TEST_ROOT/machine"* || true
|
||||
|
||||
|
||||
# Note: ssh://localhost bypasses ssh, directly invoking nix-store as a
|
||||
# child process. This allows us to test LegacySSHStore::buildDerivation().
|
||||
# ssh-ng://... likewise allows us to test RemoteStore::buildDerivation().
|
||||
|
|
|
@ -40,6 +40,7 @@ EOF
|
|||
cp simple.nix shell.nix simple.builder.sh "${config_nix}" "$flakeDir/"
|
||||
|
||||
TODO_NixOS
|
||||
requiresUnprivilegedUserNamespaces
|
||||
|
||||
outPath=$(nix build --print-out-paths --no-link --sandbox-paths '/nix? /bin? /lib? /lib64? /usr?' --store "$TEST_ROOT/x" path:"$flakeDir")
|
||||
|
||||
|
|
|
@ -345,4 +345,15 @@ count() {
|
|||
|
||||
trap onError ERR
|
||||
|
||||
requiresUnprivilegedUserNamespaces() {
|
||||
if [[ -f /proc/sys/kernel/apparmor_restrict_unprivileged_userns ]] && [[ $(< /proc/sys/kernel/apparmor_restrict_unprivileged_userns) -eq 1 ]]; then
|
||||
skipTest "Unprivileged user namespaces are disabled. Run 'sudo sysctl -w /proc/sys/kernel/apparmor_restrict_unprivileged_userns=0' to allow, and run these tests."
|
||||
fi
|
||||
}
|
||||
|
||||
execUnshare () {
|
||||
requiresUnprivilegedUserNamespaces
|
||||
exec unshare --mount --map-root-user "$SHELL" "$@"
|
||||
}
|
||||
|
||||
fi # COMMON_FUNCTIONS_SH_SOURCED
|
||||
|
|
|
@ -9,6 +9,7 @@ TODO_NixOS
|
|||
clearStore
|
||||
|
||||
requireSandboxSupport
|
||||
requiresUnprivilegedUserNamespaces
|
||||
|
||||
# Note: we need to bind-mount $SHELL into the chroot. Currently we
|
||||
# only support the case where $SHELL is in the Nix store, because
|
||||
|
|
|
@ -19,7 +19,7 @@ TODO_NixOS
|
|||
|
||||
for i in "${storesBad[@]}"; do
|
||||
echo $i
|
||||
unshare --mount --map-root-user bash <<EOF
|
||||
execUnshare <<EOF
|
||||
source common.sh
|
||||
setupStoreDirs
|
||||
mountOverlayfs
|
||||
|
|
|
@ -94,10 +94,6 @@ initLowerStore () {
|
|||
pathInLowerStore=$(nix-store --store "$storeA" --realise $drvPath)
|
||||
}
|
||||
|
||||
execUnshare () {
|
||||
exec unshare --mount --map-root-user "$SHELL" "$@"
|
||||
}
|
||||
|
||||
addTextToStore() {
|
||||
storeDir=$1; shift
|
||||
filename=$1; shift
|
||||
|
|
|
@ -7,6 +7,7 @@ source common.sh
|
|||
TODO_NixOS
|
||||
|
||||
requireSandboxSupport
|
||||
requiresUnprivilegedUserNamespaces
|
||||
|
||||
start="$TEST_ROOT/start"
|
||||
mkdir -p "$start"
|
||||
|
|
|
@ -18,6 +18,7 @@ goodStoreUrl () {
|
|||
# whether this test is being run in a derivation as part of the nix build or
|
||||
# being manually run by a developer outside a derivation
|
||||
runNixBuild () {
|
||||
|
||||
local storeFun=$1
|
||||
local altitude=$2
|
||||
nix-build \
|
||||
|
|
|
@ -52,6 +52,7 @@ if isDaemonNewer "2.20.0pre20231220"; then
|
|||
fi
|
||||
|
||||
requireSandboxSupport
|
||||
requiresUnprivilegedUserNamespaces
|
||||
|
||||
chmod -R u+w "$TEST_ROOT/store0" || true
|
||||
rm -rf "$TEST_ROOT/store0"
|
||||
|
|
|
@ -9,7 +9,7 @@ needLocalStore "The test uses --store always so we would just be bypassing the d
|
|||
|
||||
TODO_NixOS
|
||||
|
||||
unshare --mount --map-root-user -- bash -e -x <<EOF
|
||||
execUnshare <<EOF
|
||||
source common.sh
|
||||
|
||||
# Avoid store dir being inside sandbox build-dir
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue