Skip to contentSkip to conversation

CI: Add a SecureBoot/UKI test

PATCH In review Andrew Cooper 2 participants 2 messages Nov 25 – Nov 26

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 CI: Add a SecureBoot/UKI test

Debian 13 ships an OVMF image that is pre-enrolled with the snakeoil key. The only problem using this is that sbsign requires an interactive prompt for the password, so arrange for container generation to strip the password; it's not a secret.

Extend the qemu-xtf infrasturcture with a UKI variant, sign the result with the snakeoil key, and use the snakeoil OVMF image.

---
CC: Anthony PERARD <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Doug Goldstein <[email protected]>
CC: Marek Marczykowski-Górecki <[email protected]>

Marek, I stol^W borrowed the vma and objtool runes from your related patch. I'm not overly happy with adding more tests which clone XTF like this, but it is easier to run manually than the full alpine version.

python3-virt-firmware isn't strictly needed right now, but it's useful to edit OVMF_VARS when debugging. A later strictnx test does need to use the package, although that's in a Fedora container for other reasons.

---
 automation/build/debian/13-x86_64.dockerfile  | 11 +++
 automation/gitlab-ci/test.yaml                |  7 ++
 automation/scripts/include/xtf-x86_64-efi-uki | 71 +++++++++++++++++++
 3 files changed, 89 insertions(+)
 create mode 100644 automation/scripts/include/xtf-x86_64-efi-uki
automation/build/debian/13-x86_64.dockerfile +11 -0
index 784299d52dc3..8efae0150a9b 100644
@@ -57,8 +57,11 @@ RUN <<EOF
         # for test phase, qemu-* jobs
         busybox-static
         expect
+        openssl
         ovmf
+        python3-virt-firmware
         qemu-system-x86
+        sbsigntool
 
         # for build-each-commit-gcc
         ccache
@@ -66,6 +69,14 @@ RUN <<EOF
 
     apt-get -y --no-install-recommends install "${DEPS[@]}"
 
+    # Strip the password off the snakeoil key to avoid sbsigntool wanting an
+    # interactive prompt
+    openssl rsa \
+            -in  /usr/share/ovmf/PkKek-1-snakeoil.key \
+            -out /usr/share/ovmf/PkKek-1-snakeoil-nopass.key \
+            -passin pass:snakeoil
+    chmod 644 /usr/share/ovmf/PkKek-1-snakeoil-nopass.key
+
     rm -rf /var/lib/apt/lists*
 EOF
 
automation/gitlab-ci/test.yaml +7 -0
index 96127995d7be..cf4b7ed416b0 100644
@@ -776,6 +776,13 @@ qemu-smoke-x86_64-gcc-efi:
   needs:
     - debian-13-x86_64-gcc-debug
 
+qemu-smoke-x86_64-gcc-efi-uki:
+  extends: .qemu-smoke-x86_64
+  script:
+    - ./automation/scripts/qemu-xtf.sh x86_64-efi-uki pv64 example 2>&1 | tee ${LOGFILE}
+  needs:
+    - debian-13-x86_64-gcc-debug
+
 qemu-xtf-argo-x86_64-gcc-debug:
   extends: .qemu-smoke-x86_64
   variables:
automation/scripts/include/xtf-x86_64-efi-uki new file +71 -0

71 lines not on this page · raw message

Signature · 1 line
2.39.5
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Andrew Cooper

Debian 13 ships an OVMF image that is pre-enrolled with the snakeoil key. The only problem using this is that sbsign requires an interactive prompt for the password, so arrange for container generation to strip the password; it's not a secret.

Extend the qemu-xtf infrasturcture with a UKI variant, sign the result with the snakeoil key, and use the snakeoil OVMF image.

Quoted 150 lines

---
CC: Anthony PERARD <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Doug Goldstein <[email protected]>
CC: Marek Marczykowski-Górecki <[email protected]>

Marek, I stol^W borrowed the vma and objtool runes from your related patch. I'm not overly happy with adding more tests which clone XTF like this, but it is easier to run manually than the full alpine version.

python3-virt-firmware isn't strictly needed right now, but it's useful to edit OVMF_VARS when debugging. A later strictnx test does need to use the package, although that's in a Fedora container for other reasons.

---
 automation/build/debian/13-x86_64.dockerfile  | 11 +++
 automation/gitlab-ci/test.yaml                |  7 ++
 automation/scripts/include/xtf-x86_64-efi-uki | 71 +++++++++++++++++++
 3 files changed, 89 insertions(+)
 create mode 100644 automation/scripts/include/xtf-x86_64-efi-uki
automation/build/debian/13-x86_64.dockerfile +11 -0
index 784299d52dc3..8efae0150a9b 100644
@@ -57,8 +57,11 @@ RUN <<EOF
         # for test phase, qemu-* jobs
         busybox-static
         expect
+        openssl
         ovmf
+        python3-virt-firmware
         qemu-system-x86
+        sbsigntool
 
         # for build-each-commit-gcc
         ccache
@@ -66,6 +69,14 @@ RUN <<EOF
 
     apt-get -y --no-install-recommends install "${DEPS[@]}"
 
+    # Strip the password off the snakeoil key to avoid sbsigntool wanting an
+    # interactive prompt
+    openssl rsa \
+            -in  /usr/share/ovmf/PkKek-1-snakeoil.key \
+            -out /usr/share/ovmf/PkKek-1-snakeoil-nopass.key \
+            -passin pass:snakeoil
+    chmod 644 /usr/share/ovmf/PkKek-1-snakeoil-nopass.key
+
     rm -rf /var/lib/apt/lists*
 EOF
 
automation/gitlab-ci/test.yaml +7 -0
index 96127995d7be..cf4b7ed416b0 100644
@@ -776,6 +776,13 @@ qemu-smoke-x86_64-gcc-efi:
   needs:
     - debian-13-x86_64-gcc-debug
 
+qemu-smoke-x86_64-gcc-efi-uki:
+  extends: .qemu-smoke-x86_64
+  script:
+    - ./automation/scripts/qemu-xtf.sh x86_64-efi-uki pv64 example 2>&1 | tee ${LOGFILE}
+  needs:
+    - debian-13-x86_64-gcc-debug
+
 qemu-xtf-argo-x86_64-gcc-debug:
   extends: .qemu-smoke-x86_64
   variables:
automation/scripts/include/xtf-x86_64-efi-uki new file +71 -0
new file mode 100644
index 000000000000..b47def06d49c
@@ -0,0 +1,71 @@
+#!/bin/bash
+#
+# XTF test utilities (x86_64, EFI).
+#
+
+# Arch-specific environment overrides.
+function xtf_arch_prepare()
+{
+    export FW_PREFIX="${FW_PREFIX:-/usr/share/OVMF}"
+    export QEMU_PREFIX="${QEMU_PREFIX:-}"
+    export XEN_BINARY="${XEN_BINARY:-${WORKDIR}/xen.efi}"
+    export XEN_CMDLINE="${XEN_CMDLINE:-loglvl=all noreboot console_timestamps=boot console=com1}"
+    export XTF_SRC_BRANCH="${XTF_SRC_BRANCH:-master}"
+    export XTF_SRC_URI="${XTF_SRC_URI:-https://xenbits.xen.org/git-http/xtf.git}"
+    export XTF_SRC_VARIANTS="hvm64 pv64"
+}
+
+# Perform arch-specific XTF environment setup.
+function xtf_arch_setup()
+{
+    local esp_dir="${WORKDIR}/boot-esp"
+    local efi_dir="${esp_dir}/EFI/BOOT"
+
+    cat > ${WORKDIR}/xen.cfg <<EOF
+[global]
+default=test
+
+[test]
+options=${XEN_CMDLINE}
+kernel=kernel
+EOF
+
+    vma=$(objdump -h ${XEN_BINARY} | \
+              perl -ane 'if (/\..*/) { $vma=hex($F[2]) + hex($F[3]) }
+                         END { printf "0x%016x\n", ($vma + 0xfff) & ~0xfff }')
+
+    objcopy \
+        --add-section .config=${WORKDIR}/xen.cfg \
+        --change-section-vma .config=$vma \
+        --add-section .kernel=${XTF_BINARY} \
+        --change-section-vma .kernel=$(( $vma + 0x100000 )) \
+        ${XEN_BINARY} \
+        ${XEN_BINARY}.uki
+
+    mkdir -p ${efi_dir}
+
+    sbsign --key  /usr/share/ovmf/PkKek-1-snakeoil-nopass.key \
+           --cert /usr/share/ovmf/PkKek-1-snakeoil.pem \
+           --output ${efi_dir}/BOOTX64.EFI \
+           ${XEN_BINARY}.uki
+
+    local ovmf_code=${FW_PREFIX}/OVMF_CODE_4M.snakeoil.fd
+    local ovmf_vars=${FW_PREFIX}/OVMF_VARS_4M.snakeoil.fd
+    local ovmf_format=raw
+
+    cp $ovmf_code ${WORKDIR}/OVMF_CODE
+    cp $ovmf_vars ${WORKDIR}/OVMF_VARS
+
+    export TEST_CMD="${QEMU_PREFIX}qemu-system-x86_64 \
+        -no-reboot \
+        -nographic \
+        -monitor none \
+        -serial stdio \
+        -m 2048 \
+        -smp 2 \
+        -M q35,kernel-irqchip=split \
+        -drive if=pflash,format=${ovmf_format},readonly=on,file=${WORKDIR}/OVMF_CODE \
+        -drive if=pflash,format=${ovmf_format},file=${WORKDIR}/OVMF_VARS \
+        -drive file=fat:rw:${esp_dir},media=disk,index=0,format=raw \
+    "
+}
Signature · 1 line
2.39.5