2016-12-01 13:15:47 +00:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load helpers
|
|
|
|
|
|
|
|
function teardown() {
|
|
|
|
cleanup_test
|
|
|
|
}
|
|
|
|
|
|
|
|
# 1. test running with loading the default apparmor profile.
|
2016-12-02 07:13:41 +00:00
|
|
|
# test that we can run with the default apparmor profile which will not block touching a file in `.`
|
|
|
|
@test "load default apparmor profile and run a container with it" {
|
|
|
|
# this test requires apparmor, so skip this test if apparmor is not enabled.
|
2016-12-07 11:32:50 +00:00
|
|
|
enabled=$(is_apparmor_enabled)
|
|
|
|
if [[ "$enabled" -eq 0 ]]; then
|
2016-12-02 07:13:41 +00:00
|
|
|
skip "skip this test since apparmor is not enabled."
|
|
|
|
fi
|
|
|
|
|
2017-05-12 13:36:15 +00:00
|
|
|
start_crio
|
2016-12-01 13:15:47 +00:00
|
|
|
|
|
|
|
sed -e 's/%VALUE%/,"container\.apparmor\.security\.beta\.kubernetes\.io\/testname1": "runtime\/default"/g' "$TESTDATA"/sandbox_config_seccomp.json > "$TESTDIR"/apparmor1.json
|
|
|
|
|
2017-05-12 13:36:15 +00:00
|
|
|
run crioctl pod run --name apparmor1 --config "$TESTDIR"/apparmor1.json
|
2016-12-01 13:15:47 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
pod_id="$output"
|
2017-05-12 13:36:15 +00:00
|
|
|
run crioctl ctr create --name testname1 --config "$TESTDATA"/container_redis.json --pod "$pod_id"
|
2016-12-01 13:15:47 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
ctr_id="$output"
|
2017-05-12 13:36:15 +00:00
|
|
|
run crioctl ctr execsync --id "$ctr_id" touch test.txt
|
2016-12-01 13:15:47 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
|
|
|
|
cleanup_ctrs
|
|
|
|
cleanup_pods
|
2017-05-12 13:36:15 +00:00
|
|
|
stop_crio
|
2016-12-01 13:15:47 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 13:36:15 +00:00
|
|
|
# 2. test running with loading a specific apparmor profile as crio default apparmor profile.
|
|
|
|
# test that we can run with a specific apparmor profile which will block touching a file in `.` as crio default apparmor profile.
|
2016-12-02 07:13:41 +00:00
|
|
|
@test "load a specific apparmor profile as default apparmor and run a container with it" {
|
|
|
|
# this test requires apparmor, so skip this test if apparmor is not enabled.
|
2016-12-07 11:32:50 +00:00
|
|
|
enabled=$(is_apparmor_enabled)
|
|
|
|
if [[ "$enabled" -eq 0 ]]; then
|
2016-12-02 07:13:41 +00:00
|
|
|
skip "skip this test since apparmor is not enabled."
|
|
|
|
fi
|
|
|
|
|
2016-12-07 11:32:50 +00:00
|
|
|
load_apparmor_profile "$APPARMOR_TEST_PROFILE_PATH"
|
2017-05-12 13:36:15 +00:00
|
|
|
start_crio "" "$APPARMOR_TEST_PROFILE_NAME"
|
2016-12-01 13:15:47 +00:00
|
|
|
|
2016-12-02 07:13:41 +00:00
|
|
|
sed -e 's/%VALUE%/,"container\.apparmor\.security\.beta\.kubernetes\.io\/testname2": "apparmor-test-deny-write"/g' "$TESTDATA"/sandbox_config_seccomp.json > "$TESTDIR"/apparmor2.json
|
2016-12-01 13:15:47 +00:00
|
|
|
|
2017-05-12 13:36:15 +00:00
|
|
|
run crioctl pod run --name apparmor2 --config "$TESTDIR"/apparmor2.json
|
2016-12-01 13:15:47 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
pod_id="$output"
|
2017-05-12 13:36:15 +00:00
|
|
|
run crioctl ctr create --name testname2 --config "$TESTDATA"/container_redis.json --pod "$pod_id"
|
2016-12-01 13:15:47 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
ctr_id="$output"
|
2017-05-12 13:36:15 +00:00
|
|
|
run crioctl ctr execsync --id "$ctr_id" touch test.txt
|
2016-12-01 13:15:47 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -ne 0 ]
|
|
|
|
[[ "$output" =~ "Permission denied" ]]
|
|
|
|
|
|
|
|
cleanup_ctrs
|
|
|
|
cleanup_pods
|
2017-05-12 13:36:15 +00:00
|
|
|
stop_crio
|
2016-12-07 11:32:50 +00:00
|
|
|
remove_apparmor_profile "$APPARMOR_TEST_PROFILE_PATH"
|
2016-12-01 13:15:47 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 13:36:15 +00:00
|
|
|
# 3. test running with loading a specific apparmor profile but not as crio default apparmor profile.
|
2016-12-01 13:15:47 +00:00
|
|
|
# test that we can run with a specific apparmor profile which will block touching a file in `.`
|
2016-12-02 07:13:41 +00:00
|
|
|
@test "load default apparmor profile and run a container with another apparmor profile" {
|
|
|
|
# this test requires apparmor, so skip this test if apparmor is not enabled.
|
2016-12-07 11:32:50 +00:00
|
|
|
enabled=$(is_apparmor_enabled)
|
|
|
|
if [[ "$enabled" -eq 0 ]]; then
|
2016-12-02 07:13:41 +00:00
|
|
|
skip "skip this test since apparmor is not enabled."
|
|
|
|
fi
|
|
|
|
|
2016-12-07 11:32:50 +00:00
|
|
|
load_apparmor_profile "$APPARMOR_TEST_PROFILE_PATH"
|
2017-05-12 13:36:15 +00:00
|
|
|
start_crio
|
2016-12-01 13:15:47 +00:00
|
|
|
|
2016-12-02 07:13:41 +00:00
|
|
|
sed -e 's/%VALUE%/,"container\.apparmor\.security\.beta\.kubernetes\.io\/testname3": "apparmor-test-deny-write"/g' "$TESTDATA"/sandbox_config_seccomp.json > "$TESTDIR"/apparmor3.json
|
2016-12-01 13:15:47 +00:00
|
|
|
|
2017-05-12 13:36:15 +00:00
|
|
|
run crioctl pod run --name apparmor3 --config "$TESTDIR"/apparmor3.json
|
2016-12-01 13:15:47 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
pod_id="$output"
|
2017-05-12 13:36:15 +00:00
|
|
|
run crioctl ctr create --name testname3 --config "$TESTDATA"/container_redis.json --pod "$pod_id"
|
2016-12-01 13:15:47 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
ctr_id="$output"
|
2017-05-12 13:36:15 +00:00
|
|
|
run crioctl ctr execsync --id "$ctr_id" touch test.txt
|
2016-12-01 13:15:47 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -ne 0 ]
|
|
|
|
[[ "$output" =~ "Permission denied" ]]
|
|
|
|
|
|
|
|
cleanup_ctrs
|
|
|
|
cleanup_pods
|
2017-05-12 13:36:15 +00:00
|
|
|
stop_crio
|
2016-12-07 11:32:50 +00:00
|
|
|
remove_apparmor_profile "$APPARMOR_TEST_PROFILE_PATH"
|
2016-12-01 13:15:47 +00:00
|
|
|
}
|
|
|
|
|
2016-12-02 07:13:41 +00:00
|
|
|
# 4. test running with wrong apparmor profile name.
|
2016-12-01 13:15:47 +00:00
|
|
|
# test that we can will fail when running a ctr with rong apparmor profile name.
|
|
|
|
@test "run a container with wrong apparmor profile name" {
|
2016-12-02 07:13:41 +00:00
|
|
|
# this test requires apparmor, so skip this test if apparmor is not enabled.
|
2016-12-07 11:32:50 +00:00
|
|
|
enabled=$(is_apparmor_enabled)
|
|
|
|
if [[ "$enabled" -eq 0 ]]; then
|
2016-12-02 07:13:41 +00:00
|
|
|
skip "skip this test since apparmor is not enabled."
|
|
|
|
fi
|
|
|
|
|
2017-05-12 13:36:15 +00:00
|
|
|
start_crio
|
2016-12-01 13:15:47 +00:00
|
|
|
|
|
|
|
sed -e 's/%VALUE%/,"container\.apparmor\.security\.beta\.kubernetes\.io\/testname4": "not-exists"/g' "$TESTDATA"/sandbox_config_seccomp.json > "$TESTDIR"/apparmor4.json
|
|
|
|
|
2017-05-12 13:36:15 +00:00
|
|
|
run crioctl pod run --name apparmor4 --config "$TESTDIR"/apparmor4.json
|
2016-12-01 13:15:47 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
pod_id="$output"
|
2017-05-12 13:36:15 +00:00
|
|
|
run crioctl ctr create --name testname4 --config "$TESTDATA"/container_redis.json --pod "$pod_id"
|
2016-12-01 13:15:47 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -ne 0 ]
|
|
|
|
[[ "$output" =~ "Creating container failed" ]]
|
|
|
|
|
|
|
|
|
2016-12-07 11:32:50 +00:00
|
|
|
cleanup_ctrs
|
|
|
|
cleanup_pods
|
2017-05-12 13:36:15 +00:00
|
|
|
stop_crio
|
2016-12-07 11:32:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# 5. test running with default apparmor profile unloaded.
|
|
|
|
# test that we can will fail when running a ctr with rong apparmor profile name.
|
|
|
|
@test "run a container after unloading default apparmor profile" {
|
|
|
|
# this test requires apparmor, so skip this test if apparmor is not enabled.
|
|
|
|
enabled=$(is_apparmor_enabled)
|
|
|
|
if [[ "$enabled" -eq 0 ]]; then
|
|
|
|
skip "skip this test since apparmor is not enabled."
|
|
|
|
fi
|
|
|
|
|
2017-05-12 13:36:15 +00:00
|
|
|
start_crio
|
2017-05-15 22:05:58 +00:00
|
|
|
remove_apparmor_profile "$FAKE_CRIO_DEFAULT_PROFILE_PATH"
|
2016-12-07 11:32:50 +00:00
|
|
|
|
|
|
|
sed -e 's/%VALUE%/,"container\.apparmor\.security\.beta\.kubernetes\.io\/testname5": "runtime\/default"/g' "$TESTDATA"/sandbox_config_seccomp.json > "$TESTDIR"/apparmor5.json
|
|
|
|
|
2017-05-12 13:36:15 +00:00
|
|
|
run crioctl pod run --name apparmor5 --config "$TESTDIR"/apparmor5.json
|
2016-12-07 11:32:50 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
pod_id="$output"
|
2017-05-12 13:36:15 +00:00
|
|
|
run crioctl ctr create --name testname5 --config "$TESTDATA"/container_redis.json --pod "$pod_id"
|
2016-12-07 11:32:50 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
ctr_id="$output"
|
2017-05-12 13:36:15 +00:00
|
|
|
run crioctl ctr execsync --id "$ctr_id" touch test.txt
|
2016-12-07 11:32:50 +00:00
|
|
|
echo "$output"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
|
2016-12-01 13:15:47 +00:00
|
|
|
cleanup_ctrs
|
|
|
|
cleanup_pods
|
2017-05-12 13:36:15 +00:00
|
|
|
stop_crio
|
2016-12-01 13:15:47 +00:00
|
|
|
}
|