From 8cfbccb6d99a1bcfad5b16fb3f0bbca97cb5be4c Mon Sep 17 00:00:00 2001 From: Aleksa Sarai Date: Sun, 20 Oct 2024 19:55:00 +1100 Subject: [PATCH] tests: integration: add helper to check if we're in a userns Signed-off-by: Aleksa Sarai --- tests/integration/helpers.bash | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/integration/helpers.bash b/tests/integration/helpers.bash index 31e7dee8438..789b83e5b92 100755 --- a/tests/integration/helpers.bash +++ b/tests/integration/helpers.bash @@ -368,6 +368,12 @@ function rootless_cgroup() { [[ "$ROOTLESS_FEATURES" == *"cgroup"* || -v RUNC_USE_SYSTEMD ]] } +function in_userns() { + # The kernel guarantees the root userns inode number (and thus the value of + # the magic-link) is always the same value (PROC_USER_INIT_INO). + [[ "$(readlink /proc/self/ns/user)" != "user:[$((0xEFFFFFFD))]" ]] +} + # Check if criu is available and working. function have_criu() { command -v criu &>/dev/null || return 1 @@ -396,7 +402,7 @@ function requires() { fi ;; root) - if [ $EUID -ne 0 ]; then + if [ $EUID -ne 0 ] || in_userns; then skip_me=1 fi ;;