Skip to content

Commit f64f6d7

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 f64f6d7

File tree

2 files changed

+68
-9
lines changed

2 files changed

+68
-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 19967777682 --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: 63 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,15 @@ 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} ls /boot").read()?;
101+
Ok(!result.is_empty())
102+
}
103+
98104
/// Check if a distro supports --bind-storage-ro
99105
/// CentOS 9 lacks systemd.extra-unit.* support required for bind-storage-ro
100106
fn distro_supports_bind_storage_ro(distro: &str) -> bool {
@@ -240,6 +246,30 @@ pub(crate) fn run_tmt(sh: &Shell, args: &RunTmtArgs) -> Result<()> {
240246
println!("Using bcvk image: {}", image);
241247
println!("Detected distro: {}", distro);
242248

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

350380
// Launch VM with bcvk
381+
let firmware_args_slice = firmware_args.as_slice();
351382
let launch_result = cmd!(
352383
sh,
353-
"bcvk libvirt run --name {vm_name} --detach {COMMON_INST_ARGS...} {plan_bcvk_opts...} {image}"
384+
"bcvk libvirt run --name {vm_name} --detach {firmware_args_slice...} {COMMON_INST_ARGS...} {plan_bcvk_opts...} {image}"
354385
)
355386
.run()
356387
.context("Launching VM with bcvk");
@@ -597,11 +628,36 @@ pub(crate) fn tmt_provision(sh: &Shell, args: &TmtProvisionArgs) -> Result<()> {
597628
println!(" Image: {}", image);
598629
println!(" VM name: {}\n", vm_name);
599630

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

0 commit comments

Comments
 (0)