Skip to content

Commit a58d0a3

Browse files
committed
Various composefs enhancements
- Change the install logic to detect UKIs and automatically enable composefs - Move sealing bits to the toplevel - Add Justfile entrypoints - Add CI coverage that builds a disk image - Change lints to ignore `/boot/EFI` Signed-off-by: Colin Walters <[email protected]>
1 parent 104ab2e commit a58d0a3

File tree

14 files changed

+365
-25
lines changed

14 files changed

+365
-25
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
name: 'Bootc Ubuntu Setup'
22
description: 'Default host setup'
3+
inputs:
4+
libvirt:
5+
description: 'Install libvirt and virtualization stack'
6+
required: false
7+
default: 'false'
38
runs:
49
using: 'composite'
510
steps:
@@ -45,3 +50,10 @@ runs:
4550
id: set_arch
4651
shell: bash
4752
run: echo "ARCH=$(arch)" >> $GITHUB_ENV
53+
# Install libvirt stack if requested
54+
- name: Install libvirt and virtualization stack
55+
if: ${{ inputs.libvirt == 'true' }}
56+
shell: bash
57+
run: |
58+
set -eux
59+
sudo apt install -y libkrb5-dev pkg-config libvirt-dev genisoimage qemu-utils qemu-kvm qemu-utils libvirt-daemon-system

.github/workflows/ci.yml

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ jobs:
131131
- uses: actions/checkout@v4
132132
- name: Bootc Ubuntu Setup
133133
uses: ./.github/actions/bootc-ubuntu-setup
134-
- name: Install qemu-utils
135-
run: sudo apt install -y qemu-utils
134+
with:
135+
libvirt: true
136136

137137
- name: Build container and disk image
138138
run: |
@@ -163,12 +163,10 @@ jobs:
163163
- uses: actions/checkout@v4
164164
- name: Bootc Ubuntu Setup
165165
uses: ./.github/actions/bootc-ubuntu-setup
166-
- name: Install deps
167-
run: |
168-
sudo apt-get update
169-
# see https://tmt.readthedocs.io/en/stable/overview.html#install
170-
sudo apt install -y libkrb5-dev pkg-config libvirt-dev genisoimage qemu-kvm qemu-utils libvirt-daemon-system just
171-
pip install --user "tmt[provision-virtual]"
166+
with:
167+
libvirt: true
168+
- name: Install tmt
169+
run: pip install --user "tmt[provision-virtual]"
172170

173171
- name: Create folder to save disk image
174172
run: mkdir -p target
@@ -192,3 +190,29 @@ jobs:
192190
with:
193191
name: tmt-log-PR-${{ github.event.number }}-${{ matrix.test_os }}-${{ env.ARCH }}-${{ matrix.tmt_plan }}
194192
path: /var/tmp/tmt
193+
# This variant does composefs testing
194+
test-integration-cfs:
195+
strategy:
196+
fail-fast: false
197+
matrix:
198+
test_os: [centos-10]
199+
200+
runs-on: ubuntu-24.04
201+
202+
steps:
203+
- uses: actions/checkout@v4
204+
- name: Bootc Ubuntu Setup
205+
uses: ./.github/actions/bootc-ubuntu-setup
206+
with:
207+
libvirt: true
208+
209+
- name: Build container and disk image
210+
run: |
211+
sudo just build-sealed-integration-test-disk
212+
213+
- name: Archive disk image
214+
uses: actions/upload-artifact@v4
215+
with:
216+
name: PR-${{ github.event.number }}-${{ matrix.test_os }}-${{ env.ARCH }}-sealed-disk
217+
path: target/bootc-integration-test.qcow2
218+
retention-days: 1

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile.cfsuki

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Override via --build-arg=base=<image> to use a different base
2+
ARG base=localhost/bootc
3+
# This is where we get the tools to build the UKI
4+
ARG buildroot=quay.io/fedora/fedora:42
5+
FROM $base AS base
6+
7+
FROM $buildroot as buildroot-base
8+
RUN <<EORUN
9+
set -xeuo pipefail
10+
dnf install -y systemd-ukify sbsigntools systemd-boot-unsigned
11+
dnf clean all
12+
EORUN
13+
14+
FROM buildroot-base as kernel
15+
# Must be passed
16+
ARG COMPOSEFS_FSVERITY
17+
RUN --mount=type=secret,id=key \
18+
--mount=type=secret,id=cert \
19+
--mount=type=bind,from=base,target=/target \
20+
<<EOF
21+
set -eux
22+
23+
# Should be generated externally
24+
test -n "${COMPOSEFS_FSVERITY}"
25+
26+
# Inject the composefs kernel argument and specify a root with the x86_64 DPS UUID.
27+
# TODO: Discoverable partition fleshed out, or drop root UUID as systemd-stub extension
28+
# TODO: https://github.com/containers/composefs-rs/issues/183
29+
cmdline="composefs=${COMPOSEFS_FSVERITY} root=UUID=4f68bce3-e8cd-4db1-96e7-fbcaf984b709 console=ttyS0,114800n8 enforcing=0 rw"
30+
31+
kver=$(cd /target/usr/lib/modules && echo *)
32+
ukify build \
33+
--linux "/target/usr/lib/modules/$kver/vmlinuz" \
34+
--initrd "/target/usr/lib/modules/$kver/initramfs.img" \
35+
--uname="${kver}" \
36+
--cmdline "${cmdline}" \
37+
--os-release "@/target/usr/lib/os-release" \
38+
--signtool sbsign \
39+
--secureboot-private-key "/run/secrets/key" \
40+
--secureboot-certificate "/run/secrets/cert" \
41+
--measure \
42+
--json pretty \
43+
--output "/boot/$kver.efi"
44+
sbsign \
45+
--key "/run/secrets/key" \
46+
--cert "/run/secrets/cert" \
47+
"/usr/lib/systemd/boot/efi/systemd-bootx64.efi" \
48+
--output "/boot/systemd-bootx64.efi"
49+
EOF
50+
51+
FROM base as final
52+
53+
RUN --mount=type=bind,from=kernel,target=/run/kernel <<EOF
54+
kver=$(cd /usr/lib/modules && echo *)
55+
mkdir -p /boot/EFI/Linux
56+
# We put the UKI in /boot for now due to composefs verity not being the
57+
# same due to mtime of /usr/lib/modules being changed
58+
cp /run/kernel/boot/$kver.efi /boot/EFI/Linux/$kver.efi
59+
bootc container lint --fatal-warnings
60+
EOF
61+
62+
FROM base as final-final
63+
COPY --from=final /boot /boot
64+
# Override the default
65+
LABEL containers.bootc=sealed

Justfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,26 @@
1313
build *ARGS:
1414
podman build --jobs=4 -t localhost/bootc {{ARGS}} .
1515

16+
build-sealed *ARGS:
17+
podman build --jobs=4 -t localhost/bootc-unsealed {{ARGS}} .
18+
./tests/build-sealed localhost/bootc-unsealed localhost/bootc
19+
1620
# This container image has additional testing content and utilities
1721
build-integration-test-image *ARGS:
1822
cd hack && podman build --jobs=4 -t localhost/bootc-integration -f Containerfile {{ARGS}} .
1923
# Keep these in sync with what's used in hack/lbi
2024
podman pull -q --retry 5 --retry-delay 5s quay.io/curl/curl:latest quay.io/curl/curl-base:latest registry.access.redhat.com/ubi9/podman:latest
2125

26+
# Like build-integration-test-image but sealed
27+
build-sealed-integration-test-image *ARGS:
28+
just build {{ARGS}}
29+
just build-integration-test-image
30+
./tests/build-sealed localhost/bootc-integration localhost/bootc-integration-sealed
31+
32+
build-sealed-integration-test-disk: build-sealed-integration-test-image
33+
mkdir -p target
34+
just build-disk-image localhost/bootc-integration-sealed target/bootc-integration.qcow2
35+
2236
# Only used by ci.yml right now
2337
build-install-test-image: build-integration-test-image
2438
cd hack && podman build -t localhost/bootc-integration-install -f Containerfile.drop-lbis

crates/lib/src/bootc_composefs/boot.rs

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use crate::install::{RootSetup, State};
5151
/// Contains the EFP's filesystem UUID. Used by grub
5252
pub(crate) const EFI_UUID_FILE: &str = "efiuuid.cfg";
5353
/// The EFI Linux directory
54-
const EFI_LINUX: &str = "EFI/Linux";
54+
pub(crate) const EFI_LINUX: &str = "EFI/Linux";
5555

5656
/// Timeout for systemd-boot bootloader menu
5757
const SYSTEMD_TIMEOUT: &str = "timeout 5";
@@ -126,6 +126,26 @@ fi
126126
)
127127
}
128128

129+
/// Returns `true` if detect the target rootfs carries a UKI.
130+
pub(crate) fn container_root_has_uki(root: &Dir) -> Result<bool> {
131+
let Some(boot) = root.open_dir_optional(crate::install::BOOT)? else {
132+
return Ok(false);
133+
};
134+
let Some(efi_linux) = boot.open_dir_optional(EFI_LINUX)? else {
135+
return Ok(false);
136+
};
137+
for entry in efi_linux.entries()? {
138+
let entry = entry?;
139+
let name = entry.file_name();
140+
let name = Path::new(&name);
141+
let extension = name.extension().and_then(|v| v.to_str());
142+
if extension == Some("efi") {
143+
return Ok(true);
144+
}
145+
}
146+
Ok(false)
147+
}
148+
129149
pub fn get_esp_partition(device: &str) -> Result<(String, Option<String>)> {
130150
let device_info = bootc_blockdev::partitions_of(Utf8Path::new(device))?;
131151
let esp = device_info
@@ -1001,3 +1021,34 @@ pub(crate) fn setup_composefs_boot(
10011021

10021022
Ok(())
10031023
}
1024+
1025+
#[cfg(test)]
1026+
mod tests {
1027+
use super::*;
1028+
use cap_std_ext::cap_std;
1029+
1030+
#[test]
1031+
fn test_root_has_uki() -> Result<()> {
1032+
// Test case 1: No boot directory
1033+
let tempdir = cap_std_ext::cap_tempfile::tempdir(cap_std::ambient_authority())?;
1034+
assert_eq!(container_root_has_uki(&tempdir)?, false);
1035+
1036+
// Test case 2: boot directory exists but no EFI/Linux
1037+
tempdir.create_dir(crate::install::BOOT)?;
1038+
assert_eq!(container_root_has_uki(&tempdir)?, false);
1039+
1040+
// Test case 3: boot/EFI/Linux exists but no .efi files
1041+
tempdir.create_dir_all("boot/EFI/Linux")?;
1042+
assert_eq!(container_root_has_uki(&tempdir)?, false);
1043+
1044+
// Test case 4: boot/EFI/Linux exists with non-.efi file
1045+
tempdir.atomic_write("boot/EFI/Linux/readme.txt", b"some file")?;
1046+
assert_eq!(container_root_has_uki(&tempdir)?, false);
1047+
1048+
// Test case 5: boot/EFI/Linux exists with .efi file
1049+
tempdir.atomic_write("boot/EFI/Linux/bootx64.efi", b"fake efi binary")?;
1050+
assert_eq!(container_root_has_uki(&tempdir)?, true);
1051+
1052+
Ok(())
1053+
}
1054+
}

crates/lib/src/cli.rs

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ use std::ffi::{CString, OsStr, OsString};
66
use std::io::Seek;
77
use std::os::unix::process::CommandExt;
88
use std::process::Command;
9+
use std::sync::Arc;
910

1011
use anyhow::{ensure, Context, Result};
11-
use camino::Utf8PathBuf;
12+
use camino::{Utf8Path, Utf8PathBuf};
1213
use cap_std_ext::cap_std;
1314
use cap_std_ext::cap_std::fs::Dir;
1415
use clap::Parser;
1516
use clap::ValueEnum;
17+
use composefs_boot::BootOps as _;
1618
use etc_merge::{compute_diff, print_diff};
1719
use fn_error_context::context;
1820
use indoc::indoc;
@@ -23,11 +25,13 @@ use ostree_ext::composefs::fsverity::FsVerityHashValue;
2325
use ostree_ext::composefs::splitstream::SplitStreamWriter;
2426
use ostree_ext::container as ostree_container;
2527
use ostree_ext::container_utils::ostree_booted;
28+
use ostree_ext::containers_image_proxy::ImageProxyConfig;
2629
use ostree_ext::keyfileext::KeyFileExt;
2730
use ostree_ext::ostree;
2831
use ostree_ext::sysroot::SysrootLock;
2932
use schemars::schema_for;
3033
use serde::{Deserialize, Serialize};
34+
use tempfile::tempdir_in;
3135

3236
#[cfg(feature = "composefs-backend")]
3337
use crate::bootc_composefs::{
@@ -40,9 +44,11 @@ use crate::bootc_composefs::{
4044
};
4145
use crate::deploy::RequiredHostSpec;
4246
use crate::lints;
47+
use crate::podstorage::set_additional_image_store;
4348
use crate::progress_jsonl::{ProgressWriter, RawProgressFd};
4449
use crate::spec::Host;
4550
use crate::spec::ImageReference;
51+
use crate::store::ComposefsRepository;
4652
use crate::utils::sigpolicy_from_opt;
4753

4854
/// Shared progress options
@@ -315,6 +321,12 @@ pub(crate) enum ContainerOpts {
315321
#[clap(long)]
316322
no_truncate: bool,
317323
},
324+
/// Output the bootable composefs digest.
325+
#[clap(hide = true)]
326+
ComputeComposefsDigest {
327+
/// Identifier for image; if not provided, the running image will be used.
328+
image: Option<String>,
329+
},
318330
}
319331

320332
/// Subcommands which operate on images.
@@ -1335,6 +1347,55 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
13351347
)?;
13361348
Ok(())
13371349
}
1350+
ContainerOpts::ComputeComposefsDigest { image } => {
1351+
// Allocate a tempdir
1352+
let td = tempdir_in("/var/tmp")?;
1353+
let td = td.path();
1354+
let td = &Dir::open_ambient_dir(td, cap_std::ambient_authority())?;
1355+
1356+
td.create_dir("repo")?;
1357+
let repo = td.open_dir("repo")?;
1358+
let mut repo =
1359+
ComposefsRepository::open_path(&repo, ".").context("Init cfs repo")?;
1360+
// We don't need to hard require verity on the *host* system, we're just computing a checksum here
1361+
repo.set_insecure(true);
1362+
let repo = &Arc::new(repo);
1363+
1364+
let mut proxycfg = ImageProxyConfig::default();
1365+
1366+
let image = if let Some(image) = image {
1367+
image
1368+
} else {
1369+
let host_container_store = Utf8Path::new("/run/host-container-storage");
1370+
// If no image is provided, assume that we're running in a container in privileged mode
1371+
// with access to the container storage.
1372+
let container_info = crate::containerenv::get_container_execution_info(&root)?;
1373+
let iid = container_info.imageid;
1374+
tracing::debug!("Computing digest of {iid}");
1375+
1376+
if !host_container_store.try_exists()? {
1377+
anyhow::bail!("Must be readonly mount of host container store: {host_container_store}");
1378+
}
1379+
// And ensure we're finding the image in the host storage
1380+
let mut cmd = Command::new("skopeo");
1381+
set_additional_image_store(&mut cmd, "/run/host-container-storage");
1382+
proxycfg.skopeo_cmd = Some(cmd);
1383+
iid
1384+
};
1385+
1386+
let imgref = format!("containers-storage:{image}");
1387+
let (imgid, verity) = composefs_oci::pull(repo, &imgref, None, Some(proxycfg))
1388+
.await
1389+
.context("Pulling image")?;
1390+
let imgid = hex::encode(imgid);
1391+
let mut fs = composefs_oci::image::create_filesystem(repo, &imgid, Some(&verity))
1392+
.context("Populating fs")?;
1393+
fs.transform_for_boot(&repo).context("Preparing for boot")?;
1394+
let id = fs.compute_image_id();
1395+
println!("{}", id.to_hex());
1396+
1397+
Ok(())
1398+
}
13381399
},
13391400
Opt::Image(opts) => match opts {
13401401
ImageOpts::List {

crates/lib/src/generator.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ ExecStart=bootc internals fixup-etc-fstab\n\
139139
#[cfg(test)]
140140
mod tests {
141141
use camino::Utf8Path;
142-
use cap_std_ext::cmdext::CapStdExtCommandExt as _;
143142

144143
use super::*;
145144

0 commit comments

Comments
 (0)