Merge pull request #9951 from BbolroC/enable-attestation-for-ibm-se

tests: Enable attestation e2e tests for IBM SE
This commit is contained in:
Wainer Moschetta
2024-07-11 16:02:59 -03:00
committed by GitHub
6 changed files with 186 additions and 92 deletions

View File

@@ -12,6 +12,9 @@ kubernetes_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${kubernetes_dir}/../../gha-run-k8s-common.sh"
# shellcheck disable=1091
source "${kubernetes_dir}/../../../tests/common.bash"
source "${kubernetes_dir}/../../../tools/packaging/guest-image/lib_se.sh"
# For kata-runtime
export PATH="${PATH}:/opt/kata/bin"
KATA_HYPERVISOR="${KATA_HYPERVISOR:-qemu}"
# Where the trustee (includes kbs) sources will be cloned
@@ -180,7 +183,7 @@ kbs_uninstall_cli() {
#
function kbs_k8s_delete() {
pushd "$COCO_KBS_DIR"
kubectl delete -k config/kubernetes/overlays
kubectl delete -k config/kubernetes/overlays/$(uname -m)
# Verify that KBS namespace resources were properly deleted
cmd="kubectl get all -n $KBS_NS 2>&1 | grep 'No resources found'"
waitForProcess "120" "30" "$cmd"
@@ -237,7 +240,15 @@ function kbs_k8s_deploy() {
# Tests should fill kbs resources later, however, the deployment
# expects at least one secret served at install time.
echo "somesecret" > overlays/key.bin
echo "somesecret" > overlays/$(uname -m)/key.bin
# For qemu-se runtime, prepare the necessary resources
if [ "${KATA_HYPERVISOR}" == "qemu-se" ]; then
prepare_credentials_for_qemu_se
# SE_SKIP_CERTS_VERIFICATION should be set to true
# to skip the verification of the certificates
sed -i "s/false/true/g" overlays/s390x/patch.yaml
fi
echo "::group::Update the kbs container image"
install_kustomize
@@ -437,7 +448,7 @@ _handle_ingress_aks() {
return 1
fi
pushd "${COCO_KBS_DIR}/config/kubernetes/overlays"
pushd "${COCO_KBS_DIR}/config/kubernetes/overlays/common"
echo "::group::$(pwd)/ingress.yaml"
KBS_INGRESS_CLASS="addon-http-application-routing" \
@@ -456,3 +467,32 @@ _handle_ingress_nodeport() {
# By exporting this variable the kbs deploy script will install the nodeport service
export DEPLOYMENT_DIR=nodeport
}
# Prepare necessary resources for qemu-se runtime
# Documentation: https://github.com/confidential-containers/trustee/tree/main/attestation-service/verifier/src/se
prepare_credentials_for_qemu_se() {
echo "::group::Prepare credentials for qemu-se runtime"
if [ -z "${IBM_SE_CREDS_DIR:-}" ]; then
>&2 echo "ERROR: IBM_SE_CREDS_DIR is empty"
return 1
fi
config_file_path="/opt/kata/share/defaults/kata-containers/configuration-qemu-se.toml"
kata_base_dir=$(dirname $(kata-runtime --config ${config_file_path} env --json | jq -r '.Kernel.Path'))
if [ ! -d ${HKD_PATH} ]; then
>&2 echo "ERROR: HKD_PATH is not set"
return 1
fi
pushd "${IBM_SE_CREDS_DIR}"
mkdir {certs,crls,hdr,hkds,rsa}
openssl genrsa -aes256 -passout pass:test1234 -out encrypt_key-psw.pem 4096
openssl rsa -in encrypt_key-psw.pem -passin pass:test1234 -pubout -out rsa/encrypt_key.pub
openssl rsa -in encrypt_key-psw.pem -passin pass:test1234 -out rsa/encrypt_key.pem
cp ${kata_base_dir}/kata-containers-se.img hdr/hdr.bin
cp ${HKD_PATH}/HKD-*.crt hkds/
cp ${HKD_PATH}/ibm-z-host-key-gen2.crl crls/
cp ${HKD_PATH}/DigiCertCA.crt ${HKD_PATH}/ibm-z-host-key-signing-gen2.crt certs/
popd
ls -R ${IBM_SE_CREDS_DIR}
echo "::endgroup::"
}

View File

@@ -44,6 +44,15 @@ setup() {
set_metadata_annotation "${K8S_TEST_YAML}" \
"${kernel_params_annotation}" \
"${kernel_params_value}"
# A secure boot image for IBM SE should be rebuilt according to the KBS configuration.
if [ "${KATA_HYPERVISOR}" == "qemu-se" ]; then
if [ -z "${IBM_SE_CREDS_DIR:-}" ]; then
>&2 echo "ERROR: IBM_SE_CREDS_DIR is empty"
return 1
fi
repack_secure_image "${kernel_params_value}" "${IBM_SE_CREDS_DIR}" "true"
fi
}
@test "Get CDH resource" {