Skip to content

Commit cca41fb

Browse files
committed
lib: Depend on composefs-rs
And expose some fsverity helpers. This is just to get the ball rolling on integration. Signed-off-by: Colin Walters <[email protected]>
1 parent c947f0a commit cca41fb

File tree

4 files changed

+99
-3
lines changed

4 files changed

+99
-3
lines changed

Cargo.lock

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

deny.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ name = "ring"
1212
[sources]
1313
unknown-registry = "deny"
1414
unknown-git = "deny"
15-
allow-git = []
15+
allow-git = ["https://github.com/containers/composefs-rs"]

lib/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ ostree-ext = { path = "../ostree-ext", features = ["bootc"] }
2323
chrono = { workspace = true, features = ["serde"] }
2424
clap = { workspace = true, features = ["derive","cargo"] }
2525
clap_mangen = { workspace = true, optional = true }
26+
#composefs = "0.2.0"
27+
composefs = { git = "https://github.com/containers/composefs-rs", rev = "55ae2e9ba72f6afda4887d746e6b98f0a1875ac4" }
2628
cap-std-ext = { workspace = true, features = ["fs_utf8"] }
2729
hex = { workspace = true }
2830
fn-error-context = { workspace = true }

lib/src/cli.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use cap_std_ext::cap_std;
1313
use cap_std_ext::cap_std::fs::Dir;
1414
use clap::Parser;
1515
use clap::ValueEnum;
16+
use composefs::fsverity;
1617
use fn_error_context::context;
1718
use ostree::gio;
1819
use ostree_container::store::PrepareResult;
@@ -376,6 +377,21 @@ pub(crate) enum SchemaType {
376377
Progress,
377378
}
378379

380+
/// Options for consistency checking
381+
#[derive(Debug, clap::Subcommand, PartialEq, Eq)]
382+
pub(crate) enum FsverityOpts {
383+
/// Measure the fsverity digest of the target file.
384+
Measure {
385+
/// Path to file
386+
path: Utf8PathBuf,
387+
},
388+
/// Enable fsverity on the target file.
389+
Enable {
390+
/// Ptah to file
391+
path: Utf8PathBuf,
392+
},
393+
}
394+
379395
/// Hidden, internal only options
380396
#[derive(Debug, clap::Subcommand, PartialEq, Eq)]
381397
pub(crate) enum InternalsOpts {
@@ -392,6 +408,8 @@ pub(crate) enum InternalsOpts {
392408
#[clap(long)]
393409
of: SchemaType,
394410
},
411+
#[clap(subcommand)]
412+
Fsverity(FsverityOpts),
395413
/// Perform cleanup actions
396414
Cleanup,
397415
/// Proxy frontend for the `ostree-ext` CLI.
@@ -1113,6 +1131,24 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
11131131
)
11141132
.await
11151133
}
1134+
// We don't depend on fsverity-utils today, so re-expose some helpful CLI tools.
1135+
InternalsOpts::Fsverity(args) => match args {
1136+
FsverityOpts::Measure { path } => {
1137+
let fd =
1138+
std::fs::File::open(&path).with_context(|| format!("Reading {path}"))?;
1139+
let digest =
1140+
fsverity::measure_verity_digest::<_, fsverity::Sha256HashValue>(&fd)?;
1141+
let digest = hex::encode(digest);
1142+
println!("{digest}");
1143+
Ok(())
1144+
}
1145+
FsverityOpts::Enable { path } => {
1146+
let fd =
1147+
std::fs::File::open(&path).with_context(|| format!("Reading {path}"))?;
1148+
fsverity::ioctl::fs_ioc_enable_verity::<_, fsverity::Sha256HashValue>(&fd)?;
1149+
Ok(())
1150+
}
1151+
},
11161152
InternalsOpts::FixupEtcFstab => crate::deploy::fixup_etc_fstab(&root),
11171153
InternalsOpts::PrintJsonSchema { of } => {
11181154
let schema = match of {

0 commit comments

Comments
 (0)