Skip to content

Commit 00bfcab

Browse files
committed
test: Add a test for non-root user's capabilities
The test checks that a non-root uid has no effective capabilities. In other words, ambient capabilities are not in effect. Signed-off-by: Mrunal Patel <[email protected]>
1 parent 4e4f1e2 commit 00bfcab

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/ctr.bats

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,3 +1105,35 @@ function teardown() {
11051105
cleanup_pods
11061106
stop_crio
11071107
}
1108+
1109+
@test "ctr with non-root user has no effective capabilities" {
1110+
start_crio
1111+
run crictl runp "$TESTDATA"/sandbox_config.json
1112+
echo "$output"
1113+
[ "$status" -eq 0 ]
1114+
pod_id="$output"
1115+
1116+
newconfig=$(cat "$TESTDATA"/container_redis.json | python -c 'import json,sys;obj=json.load(sys.stdin);obj["linux"]["security_context"]["run_as_username"] = "redis"; json.dump(obj, sys.stdout)')
1117+
echo "$newconfig" > "$TESTDIR"/container_user.json
1118+
1119+
run crictl create "$pod_id" "$TESTDIR"/container_user.json "$TESTDATA"/sandbox_config.json
1120+
echo "$output"
1121+
[ "$status" -eq 0 ]
1122+
ctr_id="$output"
1123+
run crictl start "$ctr_id"
1124+
[ "$status" -eq 0 ]
1125+
1126+
run crictl exec --sync "$ctr_id" grep "CapEff:\s0000000000000000" /proc/1/status
1127+
echo "$output"
1128+
[ "$status" -eq 0 ]
1129+
1130+
run crictl stopp "$pod_id"
1131+
echo "$output"
1132+
[ "$status" -eq 0 ]
1133+
run crictl rmp "$pod_id"
1134+
echo "$output"
1135+
[ "$status" -eq 0 ]
1136+
cleanup_ctrs
1137+
cleanup_pods
1138+
stop_crio
1139+
}

0 commit comments

Comments
 (0)