Skip to content

Commit

Permalink
test: enable unpriv user namespaces
Browse files Browse the repository at this point in the history
These are disabled by default in some distros; we would like to test
rootless, however.

Signed-off-by: Casey Callendrello <[email protected]>
  • Loading branch information
squeed committed Jan 14, 2025
1 parent ba8bc7d commit 0312003
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion test_linux.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
#!/usr/bin/env bash
#
# Run CNI plugin tests.
#
Expand All @@ -18,6 +18,23 @@ testrun() {
sudo -E sh -c "umask 0; PATH=${GOPATH}/bin:$(pwd)/bin:${PATH} go test -race $*"
}

ensure_sysctl() {
local key
local val
local existing

key="$1"
val="$2"
existing="$(sysctl -ben "$key")"

sysctl -r

if [ "$val" -ne "$existing" ]; then
echo "sudo sysctl -we '$key'='$val'"
sudo sysctl -we "$key"="$val"
fi
}

COVERALLS=${COVERALLS:-""}

if [ -n "${COVERALLS}" ]; then
Expand All @@ -40,4 +57,7 @@ done

# Run the pkg/ns tests as non root user
mkdir -p /tmp/cni-rootless
ensure_sysctl kernel.unprivileged_userns_clone 1
ensure_sysctl kernel.apparmor_restrict_unprivileged_userns 0

(export XDG_RUNTIME_DIR=/tmp/cni-rootless; cd pkg/ns/; unshare -rmn go test)

0 comments on commit 0312003

Please sign in to comment.