Skip to content

Commit 9d3ccd0

Browse files
committed
Add bootc internals cfs
This exposes the current functionality of the cfsctl binary. It's not a crate right now, and it's not a lot of code, so we just fork it. I did take the effort to use `git subtree merge` to do the import. For the record, here's how I did it: - In composefs-rs: git subtree split --prefix=crates/cfsctl - In bootc: git subtree add --prefix=crates/lib/cfsctl ../../containers/composefs-rs/ <git sha1 from above> In cfsctl I also: - Adjusted it to accept the bootc-configured composefs repo (which note is right now hardcoded to sha512, not sha256) - Dropped the http stuff since I don't think it really makes sense vs OCI Signed-off-by: Colin Walters <[email protected]>
1 parent 1cff1b3 commit 9d3ccd0

File tree

7 files changed

+52
-75
lines changed

7 files changed

+52
-75
lines changed

Cargo.lock

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

crates/lib/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ bootc-mount = { path = "../mount" }
2323
bootc-tmpfiles = { path = "../tmpfiles" }
2424
bootc-sysusers = { path = "../sysusers" }
2525
camino = { workspace = true, features = ["serde1"] }
26+
composefs = { workspace = true }
27+
composefs-boot = { workspace = true }
28+
composefs-oci = { workspace = true }
2629
ostree-ext = { path = "../ostree-ext", features = ["bootc"] }
2730
chrono = { workspace = true, features = ["serde"] }
2831
clap = { workspace = true, features = ["derive","cargo"] }

crates/lib/cfsctl/Cargo.toml

Lines changed: 0 additions & 33 deletions
This file was deleted.

crates/lib/cfsctl/src/main.rs renamed to crates/lib/src/cfsctl.rs

Lines changed: 32 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::{
2+
ffi::OsString,
23
fs::create_dir_all,
34
path::{Path, PathBuf},
45
sync::Arc,
@@ -12,7 +13,7 @@ use rustix::fs::CWD;
1213
use composefs_boot::{write_boot, BootOps};
1314

1415
use composefs::{
15-
fsverity::{FsVerityHashValue, Sha256HashValue},
16+
fsverity::{FsVerityHashValue, Sha512HashValue},
1617
repository::Repository,
1718
};
1819

@@ -37,7 +38,6 @@ pub struct App {
3738
cmd: Command,
3839
}
3940

40-
#[cfg(feature = "oci")]
4141
#[derive(Debug, Subcommand)]
4242
enum OciCommand {
4343
/// Stores a tar file as a splitstream in the repository.
@@ -109,7 +109,6 @@ enum Command {
109109
reference: String,
110110
},
111111
/// Commands for dealing with OCI layers
112-
#[cfg(feature = "oci")]
113112
Oci {
114113
#[clap(subcommand)]
115114
cmd: OciCommand,
@@ -146,39 +145,39 @@ enum Command {
146145
ImageObjects {
147146
name: String,
148147
},
149-
#[cfg(feature = "http")]
150-
Fetch {
151-
url: String,
152-
name: String,
153-
},
154148
}
155149

156-
fn verity_opt(opt: &Option<String>) -> Result<Option<Sha256HashValue>> {
157-
Ok(match opt {
158-
Some(value) => Some(FsVerityHashValue::from_hex(value)?),
159-
None => None,
160-
})
150+
fn verity_opt(opt: &Option<String>) -> Result<Option<Sha512HashValue>> {
151+
Ok(opt
152+
.as_ref()
153+
.map(|value| FsVerityHashValue::from_hex(value))
154+
.transpose()?)
161155
}
162156

163-
#[tokio::main]
164-
async fn main() -> Result<()> {
165-
env_logger::init();
157+
pub(crate) async fn run_from_iter<I>(system_store: &crate::store::Storage, args: I) -> Result<()>
158+
where
159+
I: IntoIterator,
160+
I::Item: Into<OsString> + Clone,
161+
{
162+
let args = App::parse_from(
163+
std::iter::once(OsString::from("cfs")).chain(args.into_iter().map(Into::into)),
164+
);
166165

167-
let args = App::parse();
168-
169-
let mut repo: Repository<Sha256HashValue> = (if let Some(path) = &args.repo {
170-
Repository::open_path(CWD, path)
171-
} else if args.system {
172-
Repository::open_system()
166+
let repo = if let Some(path) = &args.repo {
167+
let mut r = Repository::open_path(CWD, path)?;
168+
r.set_insecure(args.insecure);
169+
Arc::new(r)
173170
} else if args.user {
174-
Repository::open_user()
175-
} else if rustix::process::getuid().is_root() {
176-
Repository::open_system()
171+
let mut r = Repository::open_user()?;
172+
r.set_insecure(args.insecure);
173+
Arc::new(r)
177174
} else {
178-
Repository::open_user()
179-
})?;
180-
181-
repo.set_insecure(args.insecure);
175+
if args.insecure {
176+
anyhow::bail!("Cannot override insecure state for system repo");
177+
}
178+
system_store.get_ensure_composefs()?
179+
};
180+
let repo = &repo;
182181

183182
match args.cmd {
184183
Command::Transaction => {
@@ -194,11 +193,10 @@ async fn main() -> Result<()> {
194193
let image_id = repo.import_image(&reference, &mut std::io::stdin())?;
195194
println!("{}", image_id.to_id());
196195
}
197-
#[cfg(feature = "oci")]
198196
Command::Oci { cmd: oci_cmd } => match oci_cmd {
199197
OciCommand::ImportLayer { name, sha256 } => {
200198
let object_id = composefs_oci::import_layer(
201-
&Arc::new(repo),
199+
&repo,
202200
&composefs::util::parse_sha256(sha256)?,
203201
name.as_deref(),
204202
&mut std::io::stdin(),
@@ -247,8 +245,7 @@ async fn main() -> Result<()> {
247245
println!("{}", image_id.to_id());
248246
}
249247
OciCommand::Pull { ref image, name } => {
250-
let (sha256, verity) =
251-
composefs_oci::pull(&Arc::new(repo), image, name.as_deref()).await?;
248+
let (sha256, verity) = composefs_oci::pull(&repo, image, name.as_deref()).await?;
252249

253250
println!("sha256 {}", hex::encode(sha256));
254251
println!("verity {}", verity.to_hex());
@@ -258,8 +255,7 @@ async fn main() -> Result<()> {
258255
ref config_verity,
259256
} => {
260257
let verity = verity_opt(config_verity)?;
261-
let (sha256, verity) =
262-
composefs_oci::seal(&Arc::new(repo), config_name, verity.as_ref())?;
258+
let (sha256, verity) = composefs_oci::seal(&repo, config_name, verity.as_ref())?;
263259
println!("sha256 {}", hex::encode(sha256));
264260
println!("verity {}", verity.to_id());
265261
}
@@ -301,7 +297,7 @@ async fn main() -> Result<()> {
301297
let state = args
302298
.repo
303299
.as_ref()
304-
.map(|p: &PathBuf| p.parent().unwrap())
300+
.map(|p: &PathBuf| p.parent().unwrap_or(p))
305301
.unwrap_or(Path::new("/sysroot"))
306302
.join("state/deploy")
307303
.join(id.to_hex());
@@ -359,12 +355,6 @@ async fn main() -> Result<()> {
359355
Command::GC => {
360356
repo.gc()?;
361357
}
362-
#[cfg(feature = "http")]
363-
Command::Fetch { url, name } => {
364-
let (sha256, verity) = composefs_http::download(&url, &name, Arc::new(repo)).await?;
365-
println!("sha256 {}", hex::encode(sha256));
366-
println!("verity {}", verity.to_hex());
367-
}
368358
}
369359
Ok(())
370360
}

crates/lib/src/cli.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,11 @@ pub(crate) enum InternalsOpts {
458458
#[clap(allow_hyphen_values = true)]
459459
args: Vec<OsString>,
460460
},
461+
/// Proxy frontend for the `cfsctl` CLI
462+
Cfs {
463+
#[clap(allow_hyphen_values = true)]
464+
args: Vec<OsString>,
465+
},
461466
/// Proxy frontend for the legacy `ostree container` CLI.
462467
OstreeContainer {
463468
#[clap(allow_hyphen_values = true)]
@@ -1259,6 +1264,10 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
12591264
Ok(())
12601265
}
12611266
},
1267+
InternalsOpts::Cfs { args } => {
1268+
let sysroot = &get_storage().await?;
1269+
crate::cfsctl::run_from_iter(sysroot, args.iter()).await
1270+
}
12621271
InternalsOpts::Reboot => crate::reboot::reboot(),
12631272
InternalsOpts::Fsck => {
12641273
let sysroot = &get_storage().await?;

crates/lib/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! bootable container images.
66
77
mod boundimage;
8+
mod cfsctl;
89
pub mod cli;
910
pub(crate) mod deploy;
1011
pub(crate) mod fsck;

tmt/tests/booted/readonly/030-test-composefs.nu

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ tap begin "composefs integration smoke test"
55

66
bootc internals test-composefs
77

8+
bootc internals cfs --help
9+
bootc internals cfs oci pull docker://busybox busybox
10+
test -L /sysroot/composefs/streams/refs/busybox
11+
812
tap ok

0 commit comments

Comments
 (0)