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