@@ -97,7 +97,7 @@ ci_cleanup() {
97
97
fi
98
98
99
99
[ -f " $kata_config_backup " ] && sudo mv " $kata_config_backup " " $kata_config " || \
100
- sudo rm " $kata_config "
100
+ sudo rm " $kata_config " || true
101
101
}
102
102
103
103
create_containerd_config () {
431
431
create_containerd_config " ${containerd_runtime_test} "
432
432
}
433
433
434
+ TestContainerGuestApparmor () {
435
+ info " Test container guest AppArmor"
436
+
437
+ # Set the guest AppArmor rootfs image because the guest AppArmor doesn't work with the agent init.
438
+ sudo sed -i " /^image =\|^initrd =/c image = " \" ${KATA_APPARMOR_IMAGE} \" " " " ${kata_config} "
439
+ # Enable the guest AppArmor.
440
+ sudo sed -i ' /^disable_guest_apparmor/ s/true/false/g' " ${kata_config} "
441
+ sudo sed -i ' s/^#\(debug_console_enabled\).*=.*$/\1 = true/g' " ${kata_config} "
442
+
443
+ local container_yaml=" ${REPORT_DIR} /container.yaml"
444
+ local image=" busybox:latest"
445
+ cat << EOF > "${container_yaml} "
446
+ metadata:
447
+ name: busybox-apparmor
448
+ image:
449
+ image: "$image "
450
+ command:
451
+ - top
452
+ EOF
453
+
454
+ info " Check the AppArmor profile is applied to the container executed by crictl start"
455
+ testContainerStart 1
456
+ aa_status=$( expect -c "
457
+ spawn -noecho kata-runtime exec $podid
458
+ expect " root@localhost:/# "
459
+ send \" aa-status\n\"
460
+ expect " root@localhost:/#"
461
+ send \" exit\n\"
462
+ expect eof
463
+ " )
464
+ echo " aa-status results:"
465
+ echo " ${aa_status} "
466
+ ret=$( echo " $aa_status " | grep " /bin/top.*kata-default" || true)
467
+ [ -n " $ret " ] || die " not found /bin/top kata-default profile"
468
+
469
+ info " Check the AppArmor profile is applied to the process executed by crictl exec"
470
+ sudo -E crictl exec $cid sleep 10 &
471
+ # sleep for 1s to make sure the exec process started.
472
+ sleep 1
473
+ aa_status=$( expect -c "
474
+ spawn -noecho kata-runtime exec $podid
475
+ expect " root@localhost:/# "
476
+ send \" aa-status\n\"
477
+ expect " root@localhost:/#"
478
+ send \" exit\n\"
479
+ expect eof
480
+ " )
481
+ echo " aa-status results:"
482
+ echo " ${aa_status} "
483
+ ret=$( echo " $aa_status " | grep " /bin/sleep.*kata-default" || true)
484
+ [ -n " $ret " ] || die " not found /bin/sleep kata-default profile"
485
+
486
+ testContainerStop
487
+
488
+ # Reset the Kata configuration file.
489
+ sudo rm " ${kata_config} "
490
+ ci_config
491
+ }
492
+
434
493
# k8s may restart docker which will impact on containerd stop
435
494
stop_containerd() {
436
495
local tmp=$( pgrep kubelet || true)
@@ -509,6 +568,8 @@ main() {
509
568
TestContainerMemoryUpdate 0
510
569
fi
511
570
571
+ TestContainerGuestApparmor
572
+
512
573
TestKilledVmmCleanup
513
574
514
575
popd
0 commit comments