Skip to content

Commit e8c7d9b

Browse files
committed
test: enable unpriv user namespaces
These are disabled by default in some distros; we would like to test rootless, however. Signed-off-by: Casey Callendrello <c1@caseyc.net>
1 parent ba8bc7d commit e8c7d9b

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

test_linux.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env sh
1+
#!/usr/bin/env bash
22
#
33
# Run CNI plugin tests.
44
#
@@ -18,6 +18,23 @@ testrun() {
1818
sudo -E sh -c "umask 0; PATH=${GOPATH}/bin:$(pwd)/bin:${PATH} go test -race $*"
1919
}
2020

21+
ensure_sysctl() {
22+
local key
23+
local val
24+
local existing
25+
26+
key="$1"
27+
val="$2"
28+
existing="$(sysctl -ben "$key")"
29+
30+
sysctl -r
31+
32+
if [ "$val" -ne "$existing" ]; then
33+
echo "sudo sysctl -we '$key'='$val'"
34+
sudo sysctl -we "$key"="$val"
35+
fi
36+
}
37+
2138
COVERALLS=${COVERALLS:-""}
2239

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

4158
# Run the pkg/ns tests as non root user
4259
mkdir -p /tmp/cni-rootless
60+
ensure_sysctl kernel.unprivileged_userns_clone 1
61+
ensure_sysctl kernel.apparmor_restrict_unprivileged_userns 0
62+
4363
(export XDG_RUNTIME_DIR=/tmp/cni-rootless; cd pkg/ns/; unshare -rmn go test)

0 commit comments

Comments
 (0)