2017-09-27 18:46:31 +00:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load helpers
|
|
|
|
|
|
|
|
function teardown() {
|
|
|
|
cleanup_test
|
|
|
|
}
|
|
|
|
|
|
|
|
# 1. test running with ctr unconfined
|
|
|
|
# test that we can run with a syscall which would be otherwise blocked
|
|
|
|
@test "ctr seccomp profiles unconfined" {
|
|
|
|
# this test requires seccomp, so skip this test if seccomp is not enabled.
|
|
|
|
enabled=$(is_seccomp_enabled)
|
|
|
|
if [[ "$enabled" -eq 0 ]]; then
|
|
|
|
skip "skip this test since seccomp is not enabled."
|
|
|
|
fi
|
|
|
|
|
2017-11-01 21:02:51 +00:00
|
|
|
sed -e 's/"chmod",//' "$SECCOMP_PROFILE" > "$TESTDIR"/seccomp_profile1.json
|
2017-09-27 18:46:31 +00:00
|
|
|
sed -i 's/"fchmod",//' "$TESTDIR"/seccomp_profile1.json
|
|
|
|
sed -i 's/"fchmodat",//g' "$TESTDIR"/seccomp_profile1.json
|
|
|
|
|
|
|
|
start_crio "$TESTDIR"/seccomp_profile1.json
|
|
|
|
|
|
|
|
sed -e 's/%VALUE%/unconfined/g' "$TESTDATA"/container_config_seccomp.json > "$TESTDIR"/seccomp1.json
|
2018-01-26 02:06:38 +00:00
|
|
|
run crictl runp "$TESTDATA"/sandbox_config.json
|
2017-09-27 18:46:31 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
pod_id="$output"
|
2017-11-15 15:24:20 +00:00
|
|
|
run crictl create "$pod_id" "$TESTDIR"/seccomp1.json "$TESTDATA"/sandbox_config.json
|
2017-09-27 18:46:31 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
ctr_id="$output"
|
2017-11-15 15:24:20 +00:00
|
|
|
run crictl start "$ctr_id"
|
2017-09-27 18:46:31 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
2017-11-15 15:24:20 +00:00
|
|
|
run crictl exec --sync "$ctr_id" chmod 777 .
|
2017-09-27 18:46:31 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
cleanup_ctrs
|
|
|
|
cleanup_pods
|
|
|
|
stop_crio
|
|
|
|
}
|
|
|
|
|
|
|
|
# 2. test running with ctr runtime/default
|
|
|
|
# test that we cannot run with a syscall blocked by the default seccomp profile
|
|
|
|
@test "ctr seccomp profiles runtime/default" {
|
|
|
|
# this test requires seccomp, so skip this test if seccomp is not enabled.
|
|
|
|
enabled=$(is_seccomp_enabled)
|
|
|
|
if [[ "$enabled" -eq 0 ]]; then
|
|
|
|
skip "skip this test since seccomp is not enabled."
|
|
|
|
fi
|
|
|
|
|
2017-11-01 21:02:51 +00:00
|
|
|
sed -e 's/"chmod",//' "$SECCOMP_PROFILE" > "$TESTDIR"/seccomp_profile1.json
|
2017-09-27 18:46:31 +00:00
|
|
|
sed -i 's/"fchmod",//' "$TESTDIR"/seccomp_profile1.json
|
|
|
|
sed -i 's/"fchmodat",//g' "$TESTDIR"/seccomp_profile1.json
|
|
|
|
|
|
|
|
start_crio "$TESTDIR"/seccomp_profile1.json
|
|
|
|
|
|
|
|
sed -e 's/%VALUE%/runtime\/default/g' "$TESTDATA"/container_config_seccomp.json > "$TESTDIR"/seccomp2.json
|
2018-01-26 02:06:38 +00:00
|
|
|
run crictl runp "$TESTDATA"/sandbox_config.json
|
2017-09-27 18:46:31 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
pod_id="$output"
|
2017-11-15 15:24:20 +00:00
|
|
|
run crictl create "$TESTDIR"/seccomp2.json "$TESTDATA"/sandbox_config.json
|
2017-09-27 18:46:31 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
ctr_id="$output"
|
2017-11-15 15:24:20 +00:00
|
|
|
run crictl start "$ctr_id"
|
2017-09-27 18:46:31 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
2017-11-15 15:24:20 +00:00
|
|
|
run crictl exec --sync "$ctr_id" chmod 777 .
|
2017-09-27 18:46:31 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[[ "$output" =~ "Exit code: 1" ]]
|
|
|
|
[[ "$output" =~ "Operation not permitted" ]]
|
|
|
|
|
|
|
|
cleanup_ctrs
|
|
|
|
cleanup_pods
|
|
|
|
stop_crio
|
|
|
|
}
|
|
|
|
|
|
|
|
# 3. test running with ctr unconfined and profile empty
|
|
|
|
# test that we can run with a syscall which would be otherwise blocked
|
|
|
|
@test "ctr seccomp profiles unconfined by empty field" {
|
|
|
|
# this test requires seccomp, so skip this test if seccomp is not enabled.
|
|
|
|
enabled=$(is_seccomp_enabled)
|
|
|
|
if [[ "$enabled" -eq 0 ]]; then
|
|
|
|
skip "skip this test since seccomp is not enabled."
|
|
|
|
fi
|
|
|
|
|
2017-11-01 21:02:51 +00:00
|
|
|
sed -e 's/"chmod",//' "$SECCOMP_PROFILE" > "$TESTDIR"/seccomp_profile1.json
|
2017-09-27 18:46:31 +00:00
|
|
|
sed -i 's/"fchmod",//' "$TESTDIR"/seccomp_profile1.json
|
|
|
|
sed -i 's/"fchmodat",//g' "$TESTDIR"/seccomp_profile1.json
|
|
|
|
|
|
|
|
start_crio "$TESTDIR"/seccomp_profile1.json
|
|
|
|
|
|
|
|
sed -e 's/%VALUE%//g' "$TESTDATA"/container_config_seccomp.json > "$TESTDIR"/seccomp1.json
|
2018-01-26 02:06:38 +00:00
|
|
|
run crictl runp "$TESTDATA"/sandbox_config.json
|
2017-09-27 18:46:31 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
pod_id="$output"
|
2017-11-15 15:24:20 +00:00
|
|
|
run crictl create "$pod_id" "$TESTDIR"/seccomp1.json "$TESTDATA"/sandbox_config.json
|
2017-09-27 18:46:31 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
ctr_id="$output"
|
2017-11-15 15:24:20 +00:00
|
|
|
run crictl start "$ctr_id"
|
2017-09-27 18:46:31 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
2017-11-15 15:24:20 +00:00
|
|
|
run crictl exec --sync "$ctr_id" chmod 777 .
|
2017-09-27 18:46:31 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
cleanup_ctrs
|
|
|
|
cleanup_pods
|
|
|
|
stop_crio
|
|
|
|
}
|
|
|
|
|
|
|
|
# 4. test running with ctr wrong profile name
|
|
|
|
@test "ctr seccomp profiles wrong profile name" {
|
|
|
|
# this test requires seccomp, so skip this test if seccomp is not enabled.
|
|
|
|
enabled=$(is_seccomp_enabled)
|
|
|
|
if [[ "$enabled" -eq 0 ]]; then
|
|
|
|
skip "skip this test since seccomp is not enabled."
|
|
|
|
fi
|
|
|
|
|
2017-11-01 21:02:51 +00:00
|
|
|
sed -e 's/"chmod",//' "$SECCOMP_PROFILE" > "$TESTDIR"/seccomp_profile1.json
|
2017-09-27 18:46:31 +00:00
|
|
|
sed -i 's/"fchmod",//' "$TESTDIR"/seccomp_profile1.json
|
|
|
|
sed -i 's/"fchmodat",//g' "$TESTDIR"/seccomp_profile1.json
|
|
|
|
|
|
|
|
start_crio "$TESTDIR"/seccomp_profile1.json
|
|
|
|
|
|
|
|
sed -e 's/%VALUE%/wontwork/g' "$TESTDATA"/container_config_seccomp.json > "$TESTDIR"/seccomp1.json
|
2018-01-26 02:06:38 +00:00
|
|
|
run crictl runp "$TESTDATA"/sandbox_config.json
|
2017-09-27 18:46:31 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
pod_id="$output"
|
2017-11-15 15:24:20 +00:00
|
|
|
run crictl create "$pod_id" "$TESTDIR"/seccomp1.json "$TESTDATA"/sandbox_config.json
|
2017-09-27 18:46:31 +00:00
|
|
|
echo "$output"
|
|
|
|
[[ "$status" -ne 0 ]]
|
|
|
|
[[ "$output" =~ "unknown seccomp profile option:" ]]
|
|
|
|
[[ "$output" =~ "wontwork" ]]
|
|
|
|
|
|
|
|
cleanup_ctrs
|
|
|
|
cleanup_pods
|
|
|
|
stop_crio
|
|
|
|
}
|
|
|
|
|
|
|
|
# 5. test running with ctr localhost/profile_name
|
|
|
|
@test "ctr seccomp profiles localhost/profile_name" {
|
|
|
|
# this test requires seccomp, so skip this test if seccomp is not enabled.
|
|
|
|
enabled=$(is_seccomp_enabled)
|
|
|
|
if [[ "$enabled" -eq 0 ]]; then
|
|
|
|
skip "skip this test since seccomp is not enabled."
|
|
|
|
fi
|
|
|
|
|
|
|
|
start_crio
|
|
|
|
|
2017-11-01 21:02:51 +00:00
|
|
|
sed -e 's/"chmod",//' "$SECCOMP_PROFILE" > "$TESTDIR"/seccomp_profile1.json
|
2017-09-27 18:46:31 +00:00
|
|
|
sed -i 's/"fchmod",//' "$TESTDIR"/seccomp_profile1.json
|
|
|
|
sed -i 's/"fchmodat",//g' "$TESTDIR"/seccomp_profile1.json
|
|
|
|
|
|
|
|
sed -e 's@%VALUE%@localhost/'"$TESTDIR"'/seccomp_profile1.json@g' "$TESTDATA"/container_config_seccomp.json > "$TESTDIR"/seccomp1.json
|
2018-01-26 02:06:38 +00:00
|
|
|
run crictl runp "$TESTDATA"/sandbox_config.json
|
2017-09-27 18:46:31 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
pod_id="$output"
|
2017-11-15 15:24:20 +00:00
|
|
|
run crictl create "$pod_id" "$TESTDIR"/seccomp1.json "$TESTDATA"/sandbox_config.json
|
2017-09-27 18:46:31 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
ctr_id="$output"
|
2017-11-15 15:24:20 +00:00
|
|
|
run crictl start "$ctr_id"
|
2017-09-27 18:46:31 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
2017-11-15 15:24:20 +00:00
|
|
|
run crictl exec --sync "$ctr_id" chmod 777 .
|
2017-09-27 18:46:31 +00:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[[ "$output" =~ "Exit code: 1" ]]
|
|
|
|
[[ "$output" =~ "Operation not permitted" ]]
|
|
|
|
|
|
|
|
cleanup_ctrs
|
|
|
|
cleanup_pods
|
|
|
|
stop_crio
|
|
|
|
}
|
|
|
|
|
|
|
|
# 6. test running with ctr docker/default
|
|
|
|
# test that we cannot run with a syscall blocked by the default seccomp profile
|
|
|
|
@test "ctr seccomp profiles runtime/default" {
|
|
|
|
# this test requires seccomp, so skip this test if seccomp is not enabled.
|
|
|
|
enabled=$(is_seccomp_enabled)
|
|
|
|
if [[ "$enabled" -eq 0 ]]; then
|
|
|
|
skip "skip this test since seccomp is not enabled."
|
|
|
|
fi
|
|
|
|
|
2017-11-01 21:02:51 +00:00
|
|
|
sed -e 's/"chmod",//' "$SECCOMP_PROFILE" > "$TESTDIR"/seccomp_profile1.json
|
2017-09-27 18:46:31 +00:00
|
|
|
sed -i 's/"fchmod",//' "$TESTDIR"/seccomp_profile1.json
|
|
|
|
sed -i 's/"fchmodat",//g' "$TESTDIR"/seccomp_profile1.json
|
|
|
|
|
|
|
|
start_crio "$TESTDIR"/seccomp_profile1.json
|
|
|
|
|
|
|
|
sed -e 's/%VALUE%/docker\/default/g' "$TESTDATA"/container_config_seccomp.json > "$TESTDIR"/seccomp2.json
|
2018-01-26 02:06:38 +00:00
|
|
|
run crictl runp "$TESTDATA"/sandbox_config.json
|
2017-09-27 18:46:31 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
pod_id="$output"
|
2017-11-15 15:24:20 +00:00
|
|
|
run crictl create "$pod_id" "$TESTDIR"/seccomp2.json "$TESTDIR"/seccomp_profile1.json
|
2017-09-27 18:46:31 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
ctr_id="$output"
|
2017-11-15 15:24:20 +00:00
|
|
|
run crictl start "$ctr_id"
|
2017-09-27 18:46:31 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
2017-11-15 15:24:20 +00:00
|
|
|
run crictl exec --sync "$ctr_id" chmod 777 .
|
2017-09-27 18:46:31 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[[ "$output" =~ "Exit code: 1" ]]
|
|
|
|
[[ "$output" =~ "Operation not permitted" ]]
|
|
|
|
|
|
|
|
cleanup_ctrs
|
|
|
|
cleanup_pods
|
|
|
|
stop_crio
|
|
|
|
}
|