@@ -150,18 +150,26 @@ delete_pods() {
150150 local encrypted_pod_name=$( esudo kubectl get pod -o wide | grep encrypted-image-tests | awk ' {print $1;}' || true)
151151 local unencrypted_pod_name=$( esudo kubectl get pod -o wide | grep unencrypted-image-tests | awk ' {print $1;}' || true)
152152 local encrypted_pod_name_es=$( esudo kubectl get pod -o wide | grep encrypted-image-tests-es | awk ' {print $1;}' || true)
153+ local signed_pod_name=$( esudo kubectl get pod -o wide | grep signed-image-tests | awk ' {print $1;}' || true)
154+ local signed_pod_wrong_name=$( esudo kubectl get pod -o wide | grep signed-image-tests | awk ' {print $1;}' || true)
153155
154- # Delete both encrypted and unencrypted pods
156+ # Delete encrypted, unencrypted, and signed pods
155157 esudo kubectl delete -f \
156158 " ${TEST_DIR} /unencrypted-image-tests.yaml" 2> /dev/null || true
157159 esudo kubectl delete -f \
158160 " ${TEST_DIR} /encrypted-image-tests.yaml" 2> /dev/null || true
159161 esudo kubectl delete -f \
160162 " ${TEST_DIR} /encrypted-image-tests-es.yaml" 2> /dev/null || true
161-
163+ esudo kubectl delete -f \
164+ " ${TEST_DIR} /signed-image-tests.yaml" 2> /dev/null || true
165+ esudo kubectl delete -f \
166+ " ${TEST_DIR} /signed-image-wrong.yaml" 2> /dev/null || true
167+
162168 [ -z " ${encrypted_pod_name} " ] || (kubernetes_wait_for_pod_delete_state " ${encrypted_pod_name} " || true)
163169 [ -z " ${unencrypted_pod_name} " ] || (kubernetes_wait_for_pod_delete_state " ${unencrypted_pod_name} " || true)
164170 [ -z " ${encrypted_pod_name_es} " ] || (kubernetes_wait_for_pod_delete_state " ${encrypted_pod_name_es} " || true)
171+ [ -z " ${signed_pod_name} " ] || (kubernetes_wait_for_pod_delete_state " ${signed_pod_name} " || true)
172+ [ -z " ${signed_pod_wrong_name} " ] || (kubernetes_wait_for_pod_delete_state " ${signed_pod_wrong_name} " || true)
165173}
166174
167175run_kbs () {
@@ -177,6 +185,12 @@ run_kbs() {
177185
178186 pushd simple-kbs
179187 git checkout -b " branch_${simple_kbs_tag} " " ${simple_kbs_tag} "
188+
189+ # copy resources
190+ cp ${TESTS_REPO_DIR} /integration/kubernetes/confidential/fixtures/policy.json resources/
191+ cp ${TESTS_REPO_DIR} /integration/kubernetes/confidential/fixtures/cosign.pub resources/
192+ # cp ${TESTS_REPO_DIR}/integration/kubernetes/confidential/fixtures/cosignWrong.pub resources/
193+
180194 esudo docker-compose build
181195
182196 esudo docker-compose up -d
@@ -315,6 +329,8 @@ setup_file() {
315329
316330 generate_service_yaml " unencrypted-image-tests" " ${IMAGE_REPO} :unencrypted"
317331 generate_service_yaml " encrypted-image-tests" " ${IMAGE_REPO} :encrypted"
332+ generate_service_yaml " signed-image-tests" " quay.io/kata-containers/confidential-containers:cosign-signed"
333+ generate_service_yaml " signed-image-wrong" " quay.io/kata-containers/confidential-containers:cosign-signed-key2"
318334
319335 # SEV-ES policy is 7:
320336 # - NODBG (1): Debugging of the guest is disallowed when set
@@ -336,13 +352,35 @@ setup() {
336352 DELETE FROM secrets WHERE id = 10;
337353 DELETE FROM keysets WHERE id = 10;
338354 DELETE FROM policy WHERE id = 10;
355+ DELETE FROM resources WHERE id = 10;
356+ EOF
357+ }
358+
359+ setup_cosign_signatures_files () {
360+ measurement=${1}
361+
362+ if [ -n " ${measurement} " ]; then
363+ mysql -u${KBS_DB_USER} -p${KBS_DB_PW} -h ${KBS_DB_HOST} -D ${KBS_DB} << EOF
364+ INSERT INTO resources SET resource_type="Policy", resource_path="policy.json", polid=10;
365+ INSERT INTO resources SET resource_type="Cosign Key", resource_path="cosign.pub", polid=10;
366+ INSERT INTO policy VALUES (10, '["${measurement} "]', '[]', 0, 0, '[]', now(), NULL, 1);
367+ EOF
368+
369+ else
370+ mysql -u${KBS_DB_USER} -p${KBS_DB_PW} -h ${KBS_DB_HOST} -D ${KBS_DB} << EOF
371+ INSERT INTO resources SET resource_type="Policy", resource_path="policy.json";
372+ INSERT INTO resources SET resource_type="Cosign Key", resource_path="cosign.pub";
339373EOF
374+ fi
340375}
341376
342377@test " $test_tag Test SEV unencrypted container launch success" {
343378 # Turn off pre-attestation. It is not necessary for an unencrypted image.
344379 esudo sed -i ' s/guest_pre_attestation = true/guest_pre_attestation = false/g' ${SEV_CONFIG}
345380
381+ # Turn off signature verification
382+ esudo sed -i ' s/agent.enable_signature_verification=true/agent.enable_signature_verification=false/g' ${SEV_CONFIG}
383+
346384 # Start the service/deployment/pod
347385 esudo kubectl apply -f " ${TEST_DIR} /unencrypted-image-tests.yaml"
348386
514552 fi
515553}
516554
555+ @test " $test_tag Test signed image with no required measurement" {
556+ # Add resource files to
557+ setup_cosign_signatures_files
558+
559+ # change kernel command line for signature validation
560+ esudo sed -i ' s/agent.enable_signature_verification=false/agent.enable_signature_verification=true/g' ${SEV_CONFIG}
561+
562+ # Start the service/deployment/pod
563+ esudo kubectl apply -f " ${TEST_DIR} /signed-image-tests.yaml"
564+
565+ # Retrieve pod name, wait for it to come up, retrieve pod ip
566+ pod_name=$( esudo kubectl get pod -o wide | grep signed-image-tests | awk ' {print $1;}' )
567+ kubernetes_wait_for_pod_ready_state " $pod_name " 20
568+
569+ print_service_info
570+ }
571+
572+ @test " $test_tag Test signed image with no required measurement, but wrong key (failure)" {
573+ # Add resource files to
574+ setup_cosign_signatures_files # "cosignWrong.pub"
575+
576+ # change kernel command line for signature validation
577+ esudo sed -i ' s/agent.enable_signature_verification=false/agent.enable_signature_verification=true/g' ${SEV_CONFIG}
578+
579+ # Start the service/deployment/pod
580+ esudo kubectl apply -f " ${TEST_DIR} /signed-image-wrong.yaml"
581+
582+ # Retrieve pod name, wait for it to come up, retrieve pod ip
583+ pod_name=$( esudo kubectl get pod -o wide | grep signed-image-wrong | awk ' {print $1;}' )
584+ # kubernetes_wait_for_pod_ready_state "$pod_name" 50 || true
517585
586+ print_service_info
587+
588+ # Get pod info
589+ pod_info=$( esudo kubectl describe pod ${pod_name} )
590+
591+ # Check failure condition
592+ if [[ ! ${pod_info} =~ " Validate image failed" ]]; then
593+ >&2 echo -e " ${RED} TEST - FAIL${NC} "
594+ return 1
595+ else
596+ echo " Pod message contains: Validate image failed"
597+ echo -e " ${GREEN} TEST - PASS${NC} "
598+ fi
599+ }
600+
601+ @test " $test_tag Test signed image with required measurement" {
602+ # Generate firmware measurement
603+ local append=$( cat ${TEST_DIR} /guest-kernel-append)
604+ echo " Kernel Append: ${append} "
605+ measurement=$( generate_firmware_measurement_with_append " ${append} " )
606+ echo " Firmware Measurement: ${measurement} "
607+
608+ # Add resource files to
609+ setup_cosign_signatures_files ${measurement}
610+
611+ # change kernel command line for signature validation
612+ esudo sed -i ' s/agent.enable_signature_verification=false/agent.enable_signature_verification=true/g' ${SEV_CONFIG}
613+
614+ # Start the service/deployment/pod
615+ esudo kubectl apply -f " ${TEST_DIR} /signed-image-tests.yaml"
616+
617+ # Retrieve pod name, wait for it to come up, retrieve pod ip
618+ pod_name=$( esudo kubectl get pod -o wide | grep signed-image-tests | awk ' {print $1;}' )
619+ kubernetes_wait_for_pod_ready_state " $pod_name " 50
620+
621+ print_service_info
622+ }
623+
624+ @test " $test_tag Test signed image with INVALID measurement" {
625+ # Generate firmware measurement
626+ local append=" INVALID-INPUT"
627+ measurement=$( generate_firmware_measurement_with_append ${append} )
628+ echo " Firmware Measurement: ${measurement} "
629+
630+ # Add resource files to
631+ setup_cosign_signatures_files ${measurement}
632+
633+ # change kernel command line for signature validation
634+ esudo sed -i ' s/agent.enable_signature_verification=false/agent.enable_signature_verification=true/g' ${SEV_CONFIG}
635+
636+ # Start the service/deployment/pod
637+ esudo kubectl apply -f " ${TEST_DIR} /signed-image-tests.yaml"
638+
639+ # Retrieve pod name, wait for it to come up, retrieve pod ip
640+ pod_name=$( esudo kubectl get pod -o wide | grep signed-image-tests | awk ' {print $1;}' )
641+ kubernetes_wait_for_pod_ready_state " $pod_name " 20 || true
642+
643+ print_service_info
644+ }
518645
519646teardown_file () {
520647 echo " ###############################################################################"
0 commit comments