Skip to content

Commit 7eacedc

Browse files
committed
Update composefs-rs
Note this also includes a repository format bump; this is known to break upgrades currently. Will aim to address that in the future. Assisted-by: OpenCode (Claude Opus 4) Signed-off-by: Colin Walters <walters@verbum.org>
1 parent d8785c6 commit 7eacedc

File tree

10 files changed

+460
-428
lines changed

10 files changed

+460
-428
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ clap_mangen = { version = "0.3.0" }
4444
# [patch."https://github.com/composefs/composefs-rs"]
4545
# cfsctl = { path = "/path/to/composefs-rs/crates/cfsctl" }
4646
# The Justfile will auto-detect these and bind-mount them into container builds.
47-
cfsctl = { git = "https://github.com/composefs/composefs-rs", rev = "2203e8f", package = "cfsctl", features = ["rhel9"] }
47+
cfsctl = { git = "https://github.com/composefs/composefs-rs", rev = "749466a", package = "cfsctl", features = ["rhel9"] }
4848
fn-error-context = "0.2.1"
4949
hex = "0.4.3"
5050
indicatif = "0.18.0"

crates/initramfs/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,9 @@ pub fn mount_composefs_image(
300300
allow_missing_fsverity: bool,
301301
) -> Result<OwnedFd> {
302302
let mut repo = Repository::<Sha512HashValue>::open_path(sysroot, "composefs")?;
303-
repo.set_insecure(allow_missing_fsverity);
303+
if allow_missing_fsverity {
304+
repo.set_insecure();
305+
}
304306
let rootfs = repo
305307
.mount(name)
306308
.context("Failed to mount composefs image")?;

crates/lib/src/bootc_composefs/boot.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ use composefs_boot::bootloader::{
8787
UsrLibModulesVmlinuz,
8888
};
8989
use composefs_boot::{cmdline::get_cmdline_composefs, os_release::OsReleaseInfo, uki};
90+
use composefs_oci::OciDigest;
9091
use composefs_oci::image::create_filesystem as create_composefs_filesystem;
9192
use fn_error_context::context;
9293
use rustix::{mount::MountFlags, path::Arg};
@@ -1257,23 +1258,25 @@ fn get_secureboot_keys(fs: &Dir, p: &str) -> Result<Option<SecurebootKeys>> {
12571258
pub(crate) async fn setup_composefs_boot(
12581259
root_setup: &RootSetup,
12591260
state: &State,
1260-
image_id: &str,
1261+
config_digest: &OciDigest,
12611262
allow_missing_fsverity: bool,
12621263
) -> Result<()> {
12631264
const COMPOSEFS_BOOT_SETUP_JOURNAL_ID: &str = "1f0e9d8c7b6a5f4e3d2c1b0a9f8e7d6c5";
12641265

12651266
tracing::info!(
12661267
message_id = COMPOSEFS_BOOT_SETUP_JOURNAL_ID,
12671268
bootc.operation = "boot_setup",
1268-
bootc.image_id = image_id,
1269+
bootc.config_digest = %config_digest,
12691270
bootc.allow_missing_fsverity = allow_missing_fsverity,
12701271
"Setting up composefs boot",
12711272
);
12721273

12731274
let mut repo = open_composefs_repo(&root_setup.physical_root)?;
1274-
repo.set_insecure(allow_missing_fsverity);
1275+
if allow_missing_fsverity {
1276+
repo.set_insecure();
1277+
}
12751278

1276-
let mut fs = create_composefs_filesystem(&repo, image_id, None)?;
1279+
let mut fs = create_composefs_filesystem(&repo, config_digest, None)?;
12771280
let entries = fs.transform_for_boot(&repo)?;
12781281
let id = fs.commit_image(&repo, None)?;
12791282
let mounted_fs = Dir::reopen_dir(

crates/lib/src/bootc_composefs/digest.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@ pub(crate) fn new_temp_composefs_repo() -> Result<(TempDir, Arc<ComposefsReposit
2727
let td_path = td_guard.path();
2828
let td_dir = Dir::open_ambient_dir(td_path, cap_std::ambient_authority())?;
2929

30-
td_dir.create_dir("repo")?;
31-
let repo_dir = td_dir.open_dir("repo")?;
32-
let mut repo = ComposefsRepository::open_path(&repo_dir, ".").context("Init cfs repo")?;
30+
let (mut repo, _) = ComposefsRepository::init_path(
31+
&td_dir,
32+
"repo",
33+
composefs::fsverity::Algorithm::SHA512,
34+
false,
35+
)
36+
.context("Init cfs repo")?;
3337
// We don't need to hard require verity on the *host* system, we're just computing a checksum here
34-
repo.set_insecure(true);
38+
repo.set_insecure();
3539
Ok((td_guard, Arc::new(repo)))
3640
}
3741

crates/lib/src/bootc_composefs/export.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ pub async fn export_repo_to_image(
4545

4646
let imginfo = get_imginfo(storage, &depl_verity, None).await?;
4747

48-
// We want the digest in the form of "sha256:abc123"
49-
let config_digest = format!("{}", imginfo.manifest.config().digest());
48+
let config_digest = imginfo.manifest.config().digest();
5049

5150
let var_tmp =
5251
Dir::open_ambient_dir("/var/tmp", ambient_authority()).context("Opening /var/tmp")?;
@@ -56,7 +55,7 @@ pub async fn export_repo_to_image(
5655

5756
// Use composefs_oci::open_config to get the config and layer map
5857
let (config, layer_map) =
59-
open_config(&*booted_cfs.repo, &config_digest, None).context("Opening config")?;
58+
open_config(&*booted_cfs.repo, config_digest, None).context("Opening config")?;
6059

6160
// We can't guarantee that we'll get the same tar stream as the container image
6261
// So we create new config and manifest

crates/lib/src/bootc_composefs/repo.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ pub(crate) fn open_composefs_repo(rootfs_dir: &Dir) -> Result<crate::store::Comp
2323
.context("Failed to open composefs repository")
2424
}
2525

26+
/// Initialize (or idempotently re-open) a composefs repository.
27+
/// Used during install when the repo may not exist yet.
28+
pub(crate) fn init_composefs_repo(rootfs_dir: &Dir) -> Result<crate::store::ComposefsRepository> {
29+
let (repo, _created) = crate::store::ComposefsRepository::init_path(
30+
rootfs_dir,
31+
"composefs",
32+
composefs::fsverity::Algorithm::SHA512,
33+
false,
34+
)
35+
.context("Failed to initialize composefs repository")?;
36+
Ok(repo)
37+
}
38+
2639
pub(crate) async fn initialize_composefs_repository(
2740
state: &State,
2841
root_setup: &RootSetup,
@@ -47,8 +60,10 @@ pub(crate) async fn initialize_composefs_repository(
4760

4861
crate::store::ensure_composefs_dir(rootfs_dir)?;
4962

50-
let mut repo = open_composefs_repo(rootfs_dir)?;
51-
repo.set_insecure(allow_missing_fsverity);
63+
let mut repo = init_composefs_repo(rootfs_dir)?;
64+
if allow_missing_fsverity {
65+
repo.set_insecure();
66+
}
5267

5368
let OstreeExtImgRef {
5469
name: image_name,
@@ -117,7 +132,9 @@ pub(crate) async fn pull_composefs_repo(
117132
let rootfs_dir = Dir::open_ambient_dir("/sysroot", ambient_authority())?;
118133

119134
let mut repo = open_composefs_repo(&rootfs_dir).context("Opening composefs repo")?;
120-
repo.set_insecure(allow_missing_fsverity);
135+
if allow_missing_fsverity {
136+
repo.set_insecure();
137+
}
121138

122139
let final_imgref = get_imgref(transport, image);
123140

@@ -132,13 +149,15 @@ pub(crate) async fn pull_composefs_repo(
132149

133150
tracing::info!(
134151
message_id = COMPOSEFS_PULL_JOURNAL_ID,
135-
id = pull_result.config_digest,
152+
id = %pull_result.config_digest,
136153
verity = pull_result.config_verity.to_hex(),
137154
"Pulled image into repository"
138155
);
139156

140157
let mut repo = open_composefs_repo(&rootfs_dir)?;
141-
repo.set_insecure(allow_missing_fsverity);
158+
if allow_missing_fsverity {
159+
repo.set_insecure();
160+
}
142161

143162
let mut fs: crate::store::ComposefsFilesystem =
144163
create_composefs_filesystem(&repo, &pull_result.config_digest, None)

crates/lib/src/bootc_composefs/switch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub(crate) async fn switch_composefs(
6363
storage,
6464
booted_cfs,
6565
&host,
66-
img_config.manifest.config().digest().digest(),
66+
img_config.manifest.config().digest(),
6767
&cfg_verity,
6868
true,
6969
)?;

crates/lib/src/bootc_composefs/update.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use cfsctl::composefs_boot;
66
use cfsctl::composefs_oci;
77
use composefs::fsverity::{FsVerityHashValue, Sha512HashValue};
88
use composefs_boot::BootOps;
9+
use composefs_oci::OciDigest;
910
use composefs_oci::image::create_filesystem;
1011
use fn_error_context::context;
1112
use ocidir::cap_std::ambient_authority;
@@ -59,10 +60,10 @@ pub(crate) async fn is_image_pulled(
5960
let imgref_repr = get_imgref(&imgref.transport, &imgref.image);
6061
let img_config_manifest = get_container_manifest_and_config(&imgref_repr).await?;
6162

62-
let img_digest = img_config_manifest.manifest.config().digest().digest();
63+
let config_digest = img_config_manifest.manifest.config().digest();
6364

6465
// TODO: export config_identifier function from composefs-oci/src/lib.rs and use it here
65-
let img_id = format!("oci-config-sha256:{img_digest}");
66+
let img_id = format!("oci-config-{config_digest}");
6667

6768
// NB: add deep checking?
6869
let container_pulled = repo.has_stream(&img_id).context("Checking stream")?;
@@ -132,13 +133,13 @@ pub(crate) fn validate_update(
132133
storage: &Storage,
133134
booted_cfs: &BootedComposefs,
134135
host: &Host,
135-
img_digest: &str,
136+
config_digest: &OciDigest,
136137
config_verity: &Sha512HashValue,
137138
is_switch: bool,
138139
) -> Result<UpdateAction> {
139140
let repo = &*booted_cfs.repo;
140141

141-
let mut fs = create_filesystem(repo, img_digest, Some(config_verity))?;
142+
let mut fs = create_filesystem(repo, config_digest, Some(config_verity))?;
142143
fs.transform_for_boot(&repo)?;
143144

144145
let image_id = fs.compute_image_id();
@@ -409,7 +410,8 @@ pub(crate) async fn upgrade_composefs(
409410
let repo = &*composefs.repo;
410411

411412
let (img_pulled, mut img_config) = is_image_pulled(&repo, booted_imgref).await?;
412-
let booted_img_digest = img_config.manifest.config().digest().digest().to_owned();
413+
let booted_config_digest = img_config.manifest.config().digest().clone();
414+
let booted_img_digest = booted_config_digest.to_string();
413415

414416
// Check if we already have this update staged
415417
// Or if we have another staged deployment with a different image
@@ -441,7 +443,7 @@ pub(crate) async fn upgrade_composefs(
441443
storage,
442444
composefs,
443445
&host,
444-
img_config.manifest.config().digest().digest(),
446+
img_config.manifest.config().digest(),
445447
&cfg_verity,
446448
false,
447449
)?;
@@ -477,7 +479,7 @@ pub(crate) async fn upgrade_composefs(
477479
storage,
478480
composefs,
479481
&host,
480-
&booted_img_digest,
482+
&booted_config_digest,
481483
&cfg_verity,
482484
false,
483485
)?;

crates/lib/src/store/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl BootedStorage {
194194
let (physical_root, run) = get_physical_root_and_run()?;
195195
let mut composefs = ComposefsRepository::open_path(&physical_root, COMPOSEFS)?;
196196
if cmdline.allow_missing_fsverity {
197-
composefs.set_insecure(true);
197+
composefs.set_insecure();
198198
}
199199
let composefs = Arc::new(composefs);
200200

@@ -471,11 +471,15 @@ impl Storage {
471471
let ostree = self.get_ostree()?;
472472
let ostree_repo = &ostree.repo();
473473
let ostree_verity = ostree_ext::fsverity::is_verity_enabled(ostree_repo)?;
474-
let mut composefs =
475-
ComposefsRepository::open_path(self.physical_root.open_dir(COMPOSEFS)?, ".")?;
474+
let (mut composefs, _) = ComposefsRepository::init_path(
475+
&self.physical_root,
476+
COMPOSEFS,
477+
composefs::fsverity::Algorithm::SHA512,
478+
false,
479+
)?;
476480
if !ostree_verity.enabled {
477481
tracing::debug!("Setting insecure mode for composefs repo");
478-
composefs.set_insecure(true);
482+
composefs.set_insecure();
479483
}
480484
let composefs = Arc::new(composefs);
481485
let r = Arc::clone(self.composefs.get_or_init(|| composefs));

0 commit comments

Comments
 (0)