Skip to content
This repository was archived by the owner on Jun 28, 2024. It is now read-only.

Commit af9870b

Browse files
Alex-Carter01Alex Carter
authored andcommitted
CC: Add image signature tests for SEV
Inserts resource information to kbs for signing adds example cosign and policy files to be used along with signing tests Add currently one test for: signed imagage with no required measurement Fixes: #5412
1 parent 69baf08 commit af9870b

5 files changed

Lines changed: 173 additions & 3 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-----BEGIN PUBLIC KEY-----
2+
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE1gHGbfk1AqOweLEM8HfT0bmfQE3b
3+
9fcp/LU75FMfxVZXmNVtUprsHM1thuuiBKOofv8KV7TrFl4p8NJCiXUkhA==
4+
-----END PUBLIC KEY-----
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-----BEGIN PUBLIC KEY-----
2+
MFkwEwkHKoZIzj0CAQYIKoZIzj0DAkcDQgAE1gHGbfk1AqOweoEM8HfT0bmf2E3b
3+
9fcp/LU75FMfxVZXmNVtUprsHM1thuuiBKOofv8KV7TrFl4p8NJCiXUkhA==
4+
-----END PUBLIC KEY-----
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"default": [
3+
{
4+
"type": "insecureAcceptAnything"
5+
}
6+
],
7+
"transports": {
8+
"docker": {
9+
"quay.io/kata-containers/confidential-containers": [
10+
{
11+
"type": "signedBy",
12+
"keyType": "GPGKeys",
13+
"keyPath": "/run/image-security/simple_signing/pubkey.gpg"
14+
}
15+
],
16+
"quay.io/kata-containers/confidential-containers:cosign-signed": [
17+
{
18+
"type": "sigstoreSigned",
19+
"keyPath": "/run/image-security/cosign/cosign.pub"
20+
}
21+
],
22+
"quay.io/kata-containers/confidential-containers:cosign-signed-key2": [
23+
{
24+
"type": "sigstoreSigned",
25+
"keyPath": "/run/image-security/cosign/cosign.pub"
26+
}
27+
]
28+
}
29+
}
30+
}

integration/kubernetes/confidential/sev.bats

Lines changed: 134 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,22 @@ 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)
153154

154-
# Delete both encrypted and unencrypted pods
155+
# Delete encrypted, unencrypted, and signed pods
155156
esudo kubectl delete -f \
156157
"${TEST_DIR}/unencrypted-image-tests.yaml" 2>/dev/null || true
157158
esudo kubectl delete -f \
158159
"${TEST_DIR}/encrypted-image-tests.yaml" 2>/dev/null || true
159160
esudo kubectl delete -f \
160161
"${TEST_DIR}/encrypted-image-tests-es.yaml" 2>/dev/null || true
161-
162+
esudo kubectl delete -f \
163+
"${TEST_DIR}/signed-image-tests.yaml" 2>/dev/null || true
164+
162165
[ -z "${encrypted_pod_name}" ] || (kubernetes_wait_for_pod_delete_state "${encrypted_pod_name}" || true)
163166
[ -z "${unencrypted_pod_name}" ] || (kubernetes_wait_for_pod_delete_state "${unencrypted_pod_name}" || true)
164167
[ -z "${encrypted_pod_name_es}" ] || (kubernetes_wait_for_pod_delete_state "${encrypted_pod_name_es}" || true)
168+
[ -z "${signed_pod_name}" ] || (kubernetes_wait_for_pod_delete_state "${signed_pod_name}" || true)
165169
}
166170

167171
run_kbs() {
@@ -177,6 +181,12 @@ run_kbs() {
177181

178182
pushd simple-kbs
179183
git checkout -b "branch_${simple_kbs_tag}" "${simple_kbs_tag}"
184+
185+
#copy resources
186+
cp ${TESTS_REPO_DIR}/integration/kubernetes/confidential/fixtures/policy.json resources/
187+
cp ${TESTS_REPO_DIR}/integration/kubernetes/confidential/fixtures/cosign.pub resources/
188+
cp ${TESTS_REPO_DIR}/integration/kubernetes/confidential/fixtures/cosignWrong.pub resources/
189+
180190
esudo docker-compose build
181191

182192
esudo docker-compose up -d
@@ -315,6 +325,8 @@ setup_file() {
315325

316326
generate_service_yaml "unencrypted-image-tests" "${IMAGE_REPO}:unencrypted"
317327
generate_service_yaml "encrypted-image-tests" "${IMAGE_REPO}:encrypted"
328+
generate_service_yaml "signed-image-tests" "quay.io/kata-containers/confidential-containers:cosign-signed"
329+
generate_service_yaml "signed-image-wrong" "quay.io/kata-containers/confidential-containers:cosign-signed-key2"
318330

319331
# SEV-ES policy is 7:
320332
# - NODBG (1): Debugging of the guest is disallowed when set
@@ -336,13 +348,43 @@ setup() {
336348
DELETE FROM secrets WHERE id = 10;
337349
DELETE FROM keysets WHERE id = 10;
338350
DELETE FROM policy WHERE id = 10;
351+
DELETE FROM resources WHERE id = 10;
339352
EOF
340353
}
341354

355+
setup_cosign_signatures_files() {
356+
measurement=${1}
357+
358+
if [ -n "${measurement}" ]; then
359+
mysql -u${KBS_DB_USER} -p${KBS_DB_PW} -h ${KBS_DB_HOST} -D ${KBS_DB} <<EOF
360+
INSERT INTO secrets VALUES (10, 'key_id1', '${ENCRYPTION_KEY}', 10);
361+
INSERT INTO keysets VALUES (10, 'KEYSET-1', '["key_id1"]', 10);
362+
# see https://github.com/confidential-containers/simple-kbs/blob/8507253e9060fb081fd1eac7bf2841ebf02c0847/db/db-mysql.sql#L140
363+
# INSERT INTO resources VALUES (10, 0, resource_type, resource_path, 10);
364+
INSERT INTO resources SET resource_type="Policy", resource_path="policy.json";
365+
INSERT INTO resources SET resource_type="Cosign Key", resource_path="cosign.pub";
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 secrets VALUES (10, 'key_id1', '${ENCRYPTION_KEY}', 10);
372+
INSERT INTO keysets VALUES (10, 'KEYSET-1', '["key_id1"]', 10);
373+
# see https://github.com/confidential-containers/simple-kbs/blob/8507253e9060fb081fd1eac7bf2841ebf02c0847/db/db-mysql.sql#L140
374+
# INSERT INTO resources VALUES (10, 0, resource_type, resource_path, 10);
375+
INSERT INTO resources SET resource_type="Policy", resource_path="policy.json";
376+
INSERT INTO resources SET resource_type="Cosign Key", resource_path="cosign.pub";
377+
EOF
378+
fi
379+
}
380+
342381
@test "$test_tag Test SEV unencrypted container launch success" {
343382
# Turn off pre-attestation. It is not necessary for an unencrypted image.
344383
esudo sed -i 's/guest_pre_attestation = true/guest_pre_attestation = false/g' ${SEV_CONFIG}
345384

385+
# Turn off signature verification
386+
esudo sed -i 's/agent.enable_signature_verification=true/agent.enable_signature_verification=false/g' ${SEV_CONFIG}
387+
346388
# Start the service/deployment/pod
347389
esudo kubectl apply -f "${TEST_DIR}/unencrypted-image-tests.yaml"
348390

@@ -514,7 +556,97 @@ EOF
514556
fi
515557
}
516558

559+
@test "$test_tag Test signed image with no required measurement" {
560+
# Add resource files to
561+
setup_cosign_signatures_files
562+
563+
#change kernel command line for signature validation
564+
esudo sed -i 's/agent.enable_signature_verification=false/agent.enable_signature_verification=true/g' ${SEV_CONFIG}
565+
566+
# Start the service/deployment/pod
567+
esudo kubectl apply -f "${TEST_DIR}/signed-image-tests.yaml"
568+
569+
# Retrieve pod name, wait for it to come up, retrieve pod ip
570+
pod_name=$(esudo kubectl get pod -o wide | grep signed-image-tests | awk '{print $1;}')
571+
kubernetes_wait_for_pod_ready_state "$pod_name" 20
572+
pod_ip=$(esudo kubectl get pod -o wide | grep signed-image-tests | awk '{print $6;}')
573+
574+
print_service_info
575+
}
576+
577+
@test "$test_tag Test signed image with no required measurement, but wrong key (failure)" {
578+
# Add resource files to
579+
setup_cosign_signatures_files #"cosignWrong.pub"
580+
581+
#change kernel command line for signature validation
582+
esudo sed -i 's/agent.enable_signature_verification=false/agent.enable_signature_verification=true/g' ${SEV_CONFIG}
583+
584+
# Start the service/deployment/pod
585+
esudo kubectl apply -f "${TEST_DIR}/signed-image-wrong.yaml"
586+
587+
# Retrieve pod name, wait for it to come up, retrieve pod ip
588+
pod_name=$(esudo kubectl get pod -o wide | grep signed-image-wrong | awk '{print $1;}')
589+
kubernetes_wait_for_pod_ready_state "$pod_name" 20
590+
pod_ip=$(esudo kubectl get pod -o wide | grep signed-image-wrong | awk '{print $6;}')
591+
592+
print_service_info
593+
}
594+
595+
@test "$test_tag Test signed image with required measurement" {
596+
# Generate firmware measurement
597+
local append=$(cat ${TEST_DIR}/guest-kernel-append)
598+
echo "Kernel Append: ${append}"
599+
measurement=$(generate_firmware_measurement_with_append "${append}")
600+
echo "Firmware Measurement: ${measurement}"
601+
602+
# Add resource files to
603+
setup_cosign_signatures_files ${measurement}
604+
605+
# Add key to KBS with policy measurement - SHOULD BE DONE AS PART OF COSIGN SAME SQL
606+
#add_key_to_kbs_db ${measurement}
607+
608+
#change kernel command line for signature validation
609+
esudo sed -i 's/agent.enable_signature_verification=false/agent.enable_signature_verification=true/g' ${SEV_CONFIG}
610+
611+
# Start the service/deployment/pod
612+
esudo kubectl apply -f "${TEST_DIR}/signed-image-tests.yaml"
613+
614+
# Retrieve pod name, wait for it to come up, retrieve pod ip
615+
pod_name=$(esudo kubectl get pod -o wide | grep signed-image-tests | awk '{print $1;}')
616+
kubernetes_wait_for_pod_ready_state "$pod_name" 20
617+
pod_ip=$(esudo kubectl get pod -o wide | grep signed-image-tests | awk '{print $6;}')
618+
619+
print_service_info
620+
}
621+
622+
@test "$test_tag Test signed image with INVALID measurement" {
623+
# Generate firmware measurement
624+
local append="INVALID-INPUT"
625+
measurement=$(generate_firmware_measurement_with_append ${append})
626+
echo "Firmware Measurement: ${measurement}"
627+
628+
# Add resource files to
629+
setup_cosign_signatures_files ${measurement}
630+
631+
# Add key to KBS with policy measurement - SHOULD BE DONE AS PART OF COSIGN SAME SQL
632+
#add_key_to_kbs_db ${measurement}
633+
634+
#change kernel command line for signature validation
635+
esudo sed -i 's/agent.enable_signature_verification=false/agent.enable_signature_verification=true/g' ${SEV_CONFIG}
636+
637+
# Make sure pre-attestation is enabled.
638+
esudo sed -i 's/guest_pre_attestation = false/guest_pre_attestation = true/g' ${SEV_CONFIG}
639+
640+
# Start the service/deployment/pod
641+
esudo kubectl apply -f "${TEST_DIR}/signed-image-tests.yaml"
642+
643+
# Retrieve pod name, wait for it to come up, retrieve pod ip
644+
pod_name=$(esudo kubectl get pod -o wide | grep signed-image-tests | awk '{print $1;}')
645+
kubernetes_wait_for_pod_ready_state "$pod_name" 20
646+
pod_ip=$(esudo kubectl get pod -o wide | grep signed-image-tests | awk '{print $6;}')
517647

648+
print_service_info
649+
}
518650

519651
teardown_file() {
520652
echo "###############################################################################"

versions.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ externals:
7272
simple-kbs:
7373
description: "Simple KBS that hosts key storage with release policies"
7474
url: "https://github.com/confidential-containers/simple-kbs.git"
75-
tag: "0.1.1"
75+
tag: "v0.1.2"
7676

7777
sonobuoy:
7878
description: "Tool to run kubernetes e2e conformance tests"

0 commit comments

Comments
 (0)