Skip to content

Commit 45b1aba

Browse files
committed
test:cri: Add guest AppArmor support
Add a test case which check whether AppArmor inside the guest works properly using containerd. The test creates a container configured to apply the `kata-default` profile, then it checks the container process is running with the profile enforced. Fixes: kata-containers#5748 Depends-on: github.com/kata-containers/kata-containers#7587 Signed-off-by: Manabu Sugimoto <[email protected]>
1 parent de2c828 commit 45b1aba

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

integration/containerd/cri/integration-tests.sh

+80
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,84 @@ EOF
431431
create_containerd_config "${containerd_runtime_test}"
432432
}
433433

434+
build_install_apparmor_image() {
435+
info "Build AppArmor guest image"
436+
local rootfs_builder_dir="${katacontainers_repo_dir}/tools/osbuilder/rootfs-builder"
437+
pushd "$rootfs_builder_dir"
438+
sudo -E APPARMOR=yes USE_DOCKER=yes ./rootfs.sh ubuntu
439+
popd
440+
441+
info "Install AppArmor guest image"
442+
local rootfs_dir="${rootfs_builder_dir}/rootfs"
443+
local image_builder_dir="${katacontainers_repo_dir}/tools/osbuilder/image-builder"
444+
pushd "${image_builder_dir}"
445+
sudo -E USE_DOCKER=yes ./image_builder.sh "${rootfs_dir}"
446+
popd
447+
apparmor_image="/opt/kata/share/kata-containers/kata-containers-apparmor.img"
448+
sudo install -o root -g root -m 0640 -D "${image_builder_dir}/kata-containers.img" "${apparmor_image}"
449+
}
450+
451+
TestContainerGuestApparmor() {
452+
info "Test container guest AppArmor"
453+
454+
build_install_apparmor_image
455+
456+
original_image=$(sudo sed -n 's/^image = \(.*\)/\1/p' ${kata_config})
457+
sudo sed -i "/image =/c image = "\"${apparmor_image}\""" "${kata_config}"
458+
sudo sed -i '/^disable_guest_apparmor/ s/true/false/g' "${kata_config}"
459+
sudo sed -i 's/^#\(debug_console_enabled\).*=.*$/\1 = true/g' "${kata_config}"
460+
461+
local container_yaml="${REPORT_DIR}/container.yaml"
462+
local image="busybox:latest"
463+
cat << EOF > "${container_yaml}"
464+
metadata:
465+
name: busybox-apparmor
466+
image:
467+
image: "$image"
468+
command:
469+
- top
470+
EOF
471+
472+
testContainerStart 1
473+
474+
info "check kata-runtime exec"
475+
aa_status=$(expect -c "
476+
spawn -noecho kata-runtime exec $podid
477+
expect "root@localhost:/#"
478+
send \"aa-status\n\"
479+
expect "root@localhost:/#"
480+
send \"exit\n\"
481+
expect eof
482+
")
483+
echo "aa-status results:"
484+
echo "${aa_status}"
485+
ret=$(echo "$aa_status" | grep "/pause.*kata-default" || true)
486+
[ -n "$ret" ] || die "not found /pause kata-default profile"
487+
ret=$(echo "$aa_status" | grep "/bin/top.*kata-default" || true)
488+
[ -n "$ret" ] || die "not found /bin/top kata-default profile"
489+
490+
info "check crictl exec"
491+
sudo -E crictl exec $cid sleep 10 &
492+
493+
aa_status=$(expect -c "
494+
spawn -noecho kata-runtime exec $podid
495+
expect "root@localhost:/#"
496+
send \"aa-status\n\"
497+
expect "root@localhost:/#"
498+
send \"exit\n\"
499+
expect eof
500+
")
501+
echo "aa-status results:"
502+
echo "${aa_status}"
503+
ret=$(echo "$aa_status" | grep "/bin/sleep.*kata-default" || true)
504+
[ -n "$ret" ] || die "not found /bin/sleep kata-default profile"
505+
506+
testContainerStop
507+
508+
sudo sed -i '/^disable_guest_apparmor/ s/false/true/g' "${kata_config}"
509+
sudo sed -i "/image =/c image = "\"${original_image}\""" "$kata_config"
510+
}
511+
434512
# k8s may restart docker which will impact on containerd stop
435513
stop_containerd() {
436514
local tmp=$(pgrep kubelet || true)
@@ -509,6 +587,8 @@ main() {
509587
TestContainerMemoryUpdate 0
510588
fi
511589
590+
TestContainerGuestApparmor
591+
512592
TestKilledVmmCleanup
513593
514594
popd

0 commit comments

Comments
 (0)