@@ -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
+ # The ppc64le job uses the initrd image, so the test will be skipped.
440
+ if [[ " ${TEST_INITRD} " == " yes" ]]; then
441
+ info " Skip the test because the guest AppArmor doesn't work with the agent init"
442
+ return
443
+ fi
444
+ if [ ! -e " ${KATA_APPARMOR_IMAGE} " ]; then
445
+ info " Skip the test becasue the guest AppArmor image doesn't exist"
446
+ return
447
+ fi
448
+
449
+ # Set the guest AppArmor rootfs image because the guest AppArmor doesn't work with the agent init.
450
+ sudo sed -i " /^image =/c image = " \" ${KATA_APPARMOR_IMAGE} \" " " " ${kata_config} "
451
+ # Enable the guest AppArmor.
452
+ sudo sed -i ' /^disable_guest_apparmor/ s/true/false/g' " ${kata_config} "
453
+ sudo sed -i ' s/^#\(debug_console_enabled\).*=.*$/\1 = true/g' " ${kata_config} "
454
+
455
+ local container_yaml=" ${REPORT_DIR} /container.yaml"
456
+ local image=" busybox:latest"
457
+ cat << EOF > "${container_yaml} "
458
+ metadata:
459
+ name: busybox-apparmor
460
+ image:
461
+ image: "$image "
462
+ command:
463
+ - top
464
+ EOF
465
+
466
+ info " Check the AppArmor profile is applied to the container executed by crictl start"
467
+ testContainerStart 1
468
+ aa_status=$( expect -c "
469
+ spawn -noecho kata-runtime exec $podid
470
+ expect " root@localhost:/# "
471
+ send \" aa-status\n\"
472
+ expect " root@localhost:/#"
473
+ send \" exit\n\"
474
+ expect eof
475
+ " )
476
+ echo " aa-status results:"
477
+ echo " ${aa_status} "
478
+ ret=$( echo " $aa_status " | grep " /bin/top.*kata-default" || true)
479
+ [ -n " $ret " ] || die " not found /bin/top kata-default profile"
480
+
481
+ info " Check the AppArmor profile is applied to the process executed by crictl exec"
482
+ sudo -E crictl exec $cid sleep 10 &
483
+ # sleep for 1s to make sure the exec process started.
484
+ sleep 1
485
+ aa_status=$( expect -c "
486
+ spawn -noecho kata-runtime exec $podid
487
+ expect " root@localhost:/# "
488
+ send \" aa-status\n\"
489
+ expect " root@localhost:/#"
490
+ send \" exit\n\"
491
+ expect eof
492
+ " )
493
+ echo " aa-status results:"
494
+ echo " ${aa_status} "
495
+ ret=$( echo " $aa_status " | grep " /bin/sleep.*kata-default" || true)
496
+ [ -n " $ret " ] || die " not found /bin/sleep kata-default profile"
497
+
498
+ testContainerStop
499
+
500
+ # Reset the Kata configuration file.
501
+ sudo rm " ${kata_config} "
502
+ ci_config
503
+ }
504
+
434
505
# k8s may restart docker which will impact on containerd stop
435
506
stop_containerd() {
436
507
local tmp=$( pgrep kubelet || true)
@@ -509,6 +580,8 @@ main() {
509
580
TestContainerMemoryUpdate 0
510
581
fi
511
582
583
+ TestContainerGuestApparmor
584
+
512
585
TestKilledVmmCleanup
513
586
514
587
popd
0 commit comments