@@ -18,6 +18,8 @@ source "${SCRIPT_PATH}/../../../.ci/lib.sh"
18
18
# runc is installed in /usr/local/sbin/ add that path
19
19
export PATH=" $PATH :/usr/local/sbin"
20
20
21
+ TEST_INITRD=" ${TEST_INITRD:- no} "
22
+
21
23
containerd_tarball_version=$( get_version " externals.containerd.version" )
22
24
23
25
# Runtime to be used for testing
@@ -97,7 +99,7 @@ ci_cleanup() {
97
99
fi
98
100
99
101
[ -f " $kata_config_backup " ] && sudo mv " $kata_config_backup " " $kata_config " || \
100
- sudo rm " $kata_config "
102
+ sudo rm " $kata_config " || true
101
103
}
102
104
103
105
create_containerd_config () {
431
433
create_containerd_config " ${containerd_runtime_test} "
432
434
}
433
435
436
+ TestContainerGuestApparmor () {
437
+ info " Test container guest AppArmor"
438
+
439
+ if [[ " ${TEST_INITRD} " == " yes" ]]; then
440
+ info " Skip the test because the guest AppArmor doesn't work with the agent init"
441
+ return
442
+ fi
443
+ if [ ! -e " ${KATA_APPARMOR_IMAGE} " ]; then
444
+ info " Skip the test becasue the guest AppArmor image doesn't exist"
445
+ return
446
+ fi
447
+
448
+ # Set the guest AppArmor rootfs image because the guest AppArmor doesn't work with the agent init.
449
+ sudo sed -i " /^image =/c image = " \" ${KATA_APPARMOR_IMAGE} \" " " " ${kata_config} "
450
+ # Enable the guest AppArmor.
451
+ sudo sed -i ' /^disable_guest_apparmor/ s/true/false/g' " ${kata_config} "
452
+ sudo sed -i ' s/^#\(debug_console_enabled\).*=.*$/\1 = true/g' " ${kata_config} "
453
+
454
+ local container_yaml=" ${REPORT_DIR} /container.yaml"
455
+ local image=" busybox:latest"
456
+ cat << EOF > "${container_yaml} "
457
+ metadata:
458
+ name: busybox-apparmor
459
+ image:
460
+ image: "$image "
461
+ command:
462
+ - top
463
+ EOF
464
+
465
+ info " Check the AppArmor profile is applied to the container executed by crictl start"
466
+ testContainerStart 1
467
+ aa_status=$( expect -c "
468
+ spawn -noecho kata-runtime exec $podid
469
+ expect " root@localhost:/# "
470
+ send \" aa-status\n\"
471
+ expect " root@localhost:/#"
472
+ send \" exit\n\"
473
+ expect eof
474
+ " )
475
+ echo " aa-status results:"
476
+ echo " ${aa_status} "
477
+ ret=$( echo " $aa_status " | grep " /bin/top.*kata-default" || true)
478
+ [ -n " $ret " ] || die " not found /bin/top kata-default profile"
479
+
480
+ info " Check the AppArmor profile is applied to the process executed by crictl exec"
481
+ sudo -E crictl exec $cid sleep 10 &
482
+ # sleep for 1s to make sure the exec process started.
483
+ sleep 1
484
+ aa_status=$( expect -c "
485
+ spawn -noecho kata-runtime exec $podid
486
+ expect " root@localhost:/# "
487
+ send \" aa-status\n\"
488
+ expect " root@localhost:/#"
489
+ send \" exit\n\"
490
+ expect eof
491
+ " )
492
+ echo " aa-status results:"
493
+ echo " ${aa_status} "
494
+ ret=$( echo " $aa_status " | grep " /bin/sleep.*kata-default" || true)
495
+ [ -n " $ret " ] || die " not found /bin/sleep kata-default profile"
496
+
497
+ testContainerStop
498
+
499
+ # Reset the Kata configuration file.
500
+ sudo rm " ${kata_config} "
501
+ ci_config
502
+ }
503
+
434
504
# k8s may restart docker which will impact on containerd stop
435
505
stop_containerd() {
436
506
local tmp=$( pgrep kubelet || true)
@@ -509,6 +579,8 @@ main() {
509
579
TestContainerMemoryUpdate 0
510
580
fi
511
581
582
+ TestContainerGuestApparmor
583
+
512
584
TestKilledVmmCleanup
513
585
514
586
popd
0 commit comments