Skip to content

Commit 4ee06a3

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 <walters@verbum.org>
1 parent 0c70e44 commit 4ee06a3

File tree

3 files changed

+78
-15
lines changed

3 files changed

+78
-15
lines changed

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

Lines changed: 10 additions & 5 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,11 +75,14 @@ runs:
7375
echo LIBVIRT_DEFAULT_URI=qemu:///session >> $GITHUB_ENV
7476
td=$(mktemp -d)
7577
cd $td
76-
# Install bcvk
77-
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
79-
tar xzf ${target}.tar.gz
80-
sudo install -T ${target} /usr/bin/bcvk
78+
# Install bcvk from PR 172
79+
gh run download 20107212783 --name bcvk-binary-tests --repo bootc-dev/bcvk
80+
sudo install -m 755 bcvk /usr/bin/bcvk
81+
# Install bcvk from release
82+
# target=bcvk-$(arch)-unknown-linux-gnu
83+
# /bin/time -f '%E %C' curl -LO https://github.com/bootc-dev/bcvk/releases/download/v${BCVK_VERSION}/${target}.tar.gz
84+
# tar xzf ${target}.tar.gz
85+
# sudo install -T ${target} /usr/bin/bcvk
8186
cd -
8287
rm -rf "$td"
8388

Justfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ testimage_label := "bootc.testimage=1"
3434
# /bin/sh: line 3: cd: /run/context/: Permission denied
3535
# ```
3636
# TODO: Gather more info and file a buildah bug
37-
base_buildargs := ""
38-
buildargs := "--build-arg=base=" + base + " --build-arg=variant=" + variant + " --secret=id=secureboot_key,src=target/test-secureboot/db.key --secret=id=secureboot_cert,src=target/test-secureboot/db.crt"
37+
generic_buildargs := ""
38+
# Args for package building (no secrets needed, just builds RPMs)
39+
base_buildargs := generic_buildargs + " --build-arg=base=" + base + " --build-arg=variant=" + variant
40+
buildargs := base_buildargs + " --secret=id=secureboot_key,src=target/test-secureboot/db.key --secret=id=secureboot_cert,src=target/test-secureboot/db.crt"
3941
# Args for build-sealed (no base arg, it sets that itself)
4042
sealed_buildargs := "--build-arg=variant=" + variant + " --secret=id=secureboot_key,src=target/test-secureboot/db.key --secret=id=secureboot_cert,src=target/test-secureboot/db.crt"
4143

@@ -69,7 +71,7 @@ _packagecontainer:
6971
VERSION="${TIMESTAMP}.g${COMMIT}"
7072
fi
7173
echo "Building RPM with version: ${VERSION}"
72-
podman build {{base_buildargs}} {{buildargs}} --build-arg=pkgversion=${VERSION} -t localhost/bootc-pkg --target=build .
74+
podman build {{base_buildargs}} --build-arg=pkgversion=${VERSION} -t localhost/bootc-pkg --target=build .
7375

7476
# Build packages (e.g. RPM) into target/packages/
7577
# Any old packages will be removed.

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)