Skip to content

Commit 1155ab4

Browse files
committed
tests: Use bcvk from git, provide secure boot chain to VMs
Provide our custom Secure Boot keys to bcvk when we're testing sealed images. Signed-off-by: Colin Walters <[email protected]>
1 parent 504df5f commit 1155ab4

File tree

2 files changed

+71
-9
lines changed

2 files changed

+71
-9
lines changed

.github/actions/bootc-ubuntu-setup/action.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ runs:
6565
- name: Install libvirt and virtualization stack
6666
if: ${{ inputs.libvirt == 'true' }}
6767
shell: bash
68+
env:
69+
GH_TOKEN: ${{ github.token }}
6870
run: |
6971
set -xeuo pipefail
7072
export BCVK_VERSION=0.8.0
@@ -73,9 +75,10 @@ runs:
7375
echo LIBVIRT_DEFAULT_URI=qemu:///session >> $GITHUB_ENV
7476
td=$(mktemp -d)
7577
cd $td
76-
# Install bcvk
78+
# Install bcvk from PR 170
79+
gh run download 19949430217 --name bcvk-binary --repo bootc-dev/bcvk
7780
target=bcvk-$(arch)-unknown-linux-gnu
78-
/bin/time -f '%E %C' curl -LO https://github.com/bootc-dev/bcvk/releases/download/v${BCVK_VERSION}/${target}.tar.gz
81+
# /bin/time -f '%E %C' curl -LO https://github.com/bootc-dev/bcvk/releases/download/v${BCVK_VERSION}/${target}.tar.gz
7982
tar xzf ${target}.tar.gz
8083
sudo install -T ${target} /usr/bin/bcvk
8184
cd -

crates/xtask/src/tmt.rs

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@ const VM_READY_TIMEOUT_SECS: u64 = 60;
1414
const SSH_CONNECTIVITY_MAX_ATTEMPTS: u32 = 60;
1515
const SSH_CONNECTIVITY_RETRY_DELAY_SECS: u64 = 3;
1616

17-
const COMMON_INST_ARGS: &[&str] = &[
18-
// TODO: Pass down the Secure Boot keys for tests if present
19-
"--firmware=uefi-insecure",
20-
"--label=bootc.test=1",
21-
];
17+
// Base args - firmware type will be added dynamically based on secure boot key availability
18+
const COMMON_INST_ARGS: &[&str] = &["--label=bootc.test=1"];
2219

2320
// Metadata field names
2421
const FIELD_TRY_BIND_STORAGE: &str = "try_bind_storage";
@@ -95,6 +92,18 @@ fn detect_distro_from_image(sh: &Shell, image: &str) -> Result<String> {
9592
Ok(distro.to_string())
9693
}
9794

95+
/// Detect if image is a sealed image by checking for /boot/EFI
96+
/// Sealed images have EFI boot components, non-sealed images don't
97+
/// TODO: Have `bootc container status` expose this in a nice way instead of running podman
98+
#[context("Detecting if image is sealed")]
99+
fn is_sealed_image(sh: &Shell, image: &str) -> Result<bool> {
100+
let result = cmd!(sh, "podman run --rm {image} test -d /boot/EFI")
101+
.ignore_stderr()
102+
.ignore_status()
103+
.run();
104+
Ok(result.is_ok())
105+
}
106+
98107
/// Check if a distro supports --bind-storage-ro
99108
/// CentOS 9 lacks systemd.extra-unit.* support required for bind-storage-ro
100109
fn distro_supports_bind_storage_ro(distro: &str) -> bool {
@@ -240,6 +249,30 @@ pub(crate) fn run_tmt(sh: &Shell, args: &RunTmtArgs) -> Result<()> {
240249
println!("Using bcvk image: {}", image);
241250
println!("Detected distro: {}", distro);
242251

252+
// Detect if this is a sealed image and build firmware args accordingly
253+
let is_sealed = is_sealed_image(sh, image)?;
254+
let sb_keys_dir = Utf8Path::new("target/test-secureboot").canonicalize_utf8()?;
255+
let firmware_args = if is_sealed && sb_keys_dir.try_exists()? {
256+
println!(
257+
"Sealed image detected, using secure boot with keys from: {}",
258+
sb_keys_dir
259+
);
260+
vec![
261+
"--firmware=uefi-secure".to_string(),
262+
format!("--secure-boot-keys={}", sb_keys_dir),
263+
]
264+
} else {
265+
if is_sealed {
266+
println!(
267+
"Sealed image detected but no secure boot keys found at {}, using insecure UEFI",
268+
sb_keys_dir
269+
);
270+
} else {
271+
println!("Non-sealed image, using insecure UEFI");
272+
}
273+
vec!["--firmware=uefi-insecure".to_string()]
274+
};
275+
243276
// Create tmt-workdir and copy tmt bits to it
244277
// This works around https://github.com/teemtee/tmt/issues/4062
245278
let workdir = Utf8Path::new("target/tmt-workdir");
@@ -348,9 +381,10 @@ pub(crate) fn run_tmt(sh: &Shell, args: &RunTmtArgs) -> Result<()> {
348381
};
349382

350383
// Launch VM with bcvk
384+
let firmware_args_slice = firmware_args.as_slice();
351385
let launch_result = cmd!(
352386
sh,
353-
"bcvk libvirt run --name {vm_name} --detach {COMMON_INST_ARGS...} {plan_bcvk_opts...} {image}"
387+
"bcvk libvirt run --name {vm_name} --detach {firmware_args_slice...} {COMMON_INST_ARGS...} {plan_bcvk_opts...} {image}"
354388
)
355389
.run()
356390
.context("Launching VM with bcvk");
@@ -597,11 +631,36 @@ pub(crate) fn tmt_provision(sh: &Shell, args: &TmtProvisionArgs) -> Result<()> {
597631
println!(" Image: {}", image);
598632
println!(" VM name: {}\n", vm_name);
599633

634+
// Detect if this is a sealed image and build firmware args accordingly
635+
let is_sealed = is_sealed_image(sh, image)?;
636+
let sb_keys_dir = Utf8Path::new("target/test-secureboot");
637+
let firmware_args = if is_sealed && sb_keys_dir.try_exists()? {
638+
println!(
639+
"Sealed image detected, using secure boot with keys from: {}",
640+
sb_keys_dir
641+
);
642+
vec![
643+
"--firmware=uefi-secure".to_string(),
644+
format!("--secure-boot-keys={}", sb_keys_dir),
645+
]
646+
} else {
647+
if is_sealed {
648+
println!(
649+
"Sealed image detected but no secure boot keys found at {}, using insecure UEFI",
650+
sb_keys_dir
651+
);
652+
} else {
653+
println!("Non-sealed image, using insecure UEFI");
654+
}
655+
vec!["--firmware=uefi-insecure".to_string()]
656+
};
657+
600658
// Launch VM with bcvk
601659
// Use ds=iid-datasource-none to disable cloud-init for faster boot
660+
let firmware_args_slice = firmware_args.as_slice();
602661
cmd!(
603662
sh,
604-
"bcvk libvirt run --name {vm_name} --detach {COMMON_INST_ARGS...} {image}"
663+
"bcvk libvirt run --name {vm_name} --detach {firmware_args_slice...} {COMMON_INST_ARGS...} {image}"
605664
)
606665
.run()
607666
.context("Launching VM with bcvk")?;

0 commit comments

Comments
 (0)