Skip to content

Commit 63f49d3

Browse files
authored
Merge pull request #1068 from cgwalters/install-config-verity-prep
Install config verity prep
2 parents c54fefa + cca41fb commit 63f49d3

File tree

14 files changed

+219
-61
lines changed

14 files changed

+219
-61
lines changed

.packit.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ jobs:
5151
# rawhide is basically nil.
5252
- fedora-rawhide-x86_64
5353
- fedora-rawhide-aarch64
54-
- rhel-9-x86_64
55-
- rhel-9-aarch64
54+
# Temporarily disabled due to too old Rust...reenable post 9.6
55+
# - rhel-9-x86_64
56+
# - rhel-9-aarch64
5657

5758
- job: tests
5859
trigger: pull_request

Cargo.lock

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

cli/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ license = "MIT OR Apache-2.0"
66
repository = "https://github.com/containers/bootc"
77
readme = "README.md"
88
publish = false
9-
# For now don't bump this above what is currently shipped in RHEL9.
10-
rust-version = "1.75.0"
119
default-run = "bootc"
1210

1311
# See https://github.com/coreos/cargo-vendor-filterer

contrib/packaging/bootc.spec

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ Provides: ostree-cli(ostree-container)
6464

6565
%prep
6666
%autosetup -p1 -a1
67-
%cargo_prep -v vendor
67+
# Default -v vendor config doesn't support non-crates.io deps (i.e. git)
68+
cp .cargo/vendor-config.toml .
69+
%cargo_prep -N
70+
cat vendor-config.toml >> .cargo/config.toml
71+
rm vendor-config.toml
6872

6973
%build
7074
%if 0%{?fedora} || 0%{?rhel} >= 10
@@ -74,6 +78,8 @@ Provides: ostree-cli(ostree-container)
7478
%endif
7579

7680
%cargo_vendor_manifest
81+
# https://pagure.io/fedora-rust/rust-packaging/issue/33
82+
sed -i -e '/https:\/\//d' cargo-vendor.txt
7783
%cargo_license_summary
7884
%{cargo_license} > LICENSE.dependencies
7985

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"]

hack/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -xeu
33
. /usr/lib/os-release
44
case $ID in
55
centos|rhel) dnf config-manager --set-enabled crb;;
6-
fedora) dnf -y install dnf-utils ;;
6+
fedora) dnf -y install dnf-utils 'dnf5-command(builddep)';;
77
esac
88
dnf -y builddep ./contrib/packaging/bootc.spec
99
# Extra dependencies

lib/Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ name = "bootc-lib"
66
readme = "README.md"
77
repository = "https://github.com/containers/bootc"
88
version = "1.1.4"
9-
# For now don't bump this above what is currently shipped in RHEL9;
10-
# also keep in sync with the version in cli.
11-
rust-version = "1.75.0"
9+
# In general we try to keep this pinned to what's in the latest RHEL9.
10+
# However right now, we bumped to 1.82 as that's what composefs-rs uses.
11+
rust-version = "1.82.0"
1212

1313
include = ["/src", "LICENSE-APACHE", "LICENSE-MIT"]
1414

@@ -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 {

lib/src/install.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub(crate) mod config;
1313
mod osbuild;
1414
pub(crate) mod osconfig;
1515

16+
use std::collections::HashMap;
1617
use std::io::Write;
1718
use std::os::fd::{AsFd, AsRawFd};
1819
use std::os::unix::process::CommandExt;
@@ -37,11 +38,11 @@ use chrono::prelude::*;
3738
use clap::ValueEnum;
3839
use fn_error_context::context;
3940
use ostree::gio;
40-
use ostree_ext::container as ostree_container;
4141
use ostree_ext::oci_spec;
4242
use ostree_ext::ostree;
4343
use ostree_ext::prelude::Cast;
4444
use ostree_ext::sysroot::SysrootLock;
45+
use ostree_ext::{container as ostree_container, ostree_prepareroot};
4546
#[cfg(feature = "install-to-disk")]
4647
use rustix::fs::FileTypeExt;
4748
use rustix::fs::MetadataExt as _;
@@ -349,6 +350,8 @@ pub(crate) struct State {
349350
#[allow(dead_code)]
350351
pub(crate) config_opts: InstallConfigOpts,
351352
pub(crate) target_imgref: ostree_container::OstreeImageReference,
353+
#[allow(dead_code)]
354+
pub(crate) prepareroot_config: HashMap<String, String>,
352355
pub(crate) install_config: Option<config::InstallConfiguration>,
353356
/// The parsed contents of the authorized_keys (not the file path)
354357
pub(crate) root_ssh_authorized_keys: Option<String>,
@@ -1267,6 +1270,20 @@ async fn prepare_install(
12671270
tracing::debug!("No install configuration found");
12681271
}
12691272

1273+
// Convert the keyfile to a hashmap because GKeyFile isnt Send for probably bad reasons.
1274+
let prepareroot_config = {
1275+
let kf = ostree_prepareroot::require_config_from_root(&rootfs)?;
1276+
let mut r = HashMap::new();
1277+
for grp in kf.groups() {
1278+
for key in kf.keys(&grp)? {
1279+
let key = key.as_str();
1280+
let value = kf.value(&grp, key)?;
1281+
r.insert(format!("{grp}.{key}"), value.to_string());
1282+
}
1283+
}
1284+
r
1285+
};
1286+
12701287
// Eagerly read the file now to ensure we error out early if e.g. it doesn't exist,
12711288
// instead of much later after we're 80% of the way through an install.
12721289
let root_ssh_authorized_keys = config_opts
@@ -1284,6 +1301,7 @@ async fn prepare_install(
12841301
config_opts,
12851302
target_imgref,
12861303
install_config,
1304+
prepareroot_config,
12871305
root_ssh_authorized_keys,
12881306
container_root: rootfs,
12891307
tempdir,

lib/src/lints.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ use std::collections::BTreeSet;
66
use std::env::consts::ARCH;
77
use std::os::unix::ffi::OsStrExt;
88

9-
use anyhow::{Context, Result};
9+
use anyhow::Result;
1010
use camino::{Utf8Path, Utf8PathBuf};
1111
use cap_std::fs::Dir;
1212
use cap_std_ext::cap_std;
1313
use cap_std_ext::cap_std::fs::MetadataExt;
1414
use cap_std_ext::dirext::CapStdExtDirExt as _;
1515
use fn_error_context::context;
1616
use indoc::indoc;
17+
use ostree_ext::ostree_prepareroot;
1718
use serde::Serialize;
1819

1920
/// Reference to embedded default baseimage content that should exist.
@@ -286,15 +287,8 @@ fn check_baseimage_root_norecurse(dir: &Dir) -> LintResult {
286287
return lint_err("Expected /ostree -> {expected}, not {link:?}");
287288
}
288289

289-
// Check the prepare-root config
290-
let prepareroot_path = "usr/lib/ostree/prepare-root.conf";
291-
let config_data = dir
292-
.read_to_string(prepareroot_path)
293-
.context(prepareroot_path)?;
294-
let config = ostree_ext::glib::KeyFile::new();
295-
config.load_from_data(&config_data, ostree_ext::glib::KeyFileFlags::empty())?;
296-
297-
if !ostree_ext::ostree_prepareroot::overlayfs_enabled_in_config(&config)? {
290+
let config = ostree_prepareroot::require_config_from_root(dir)?;
291+
if !ostree_prepareroot::overlayfs_enabled_in_config(&config)? {
298292
return lint_err("{prepareroot_path} does not have composefs enabled");
299293
}
300294

ostree-ext/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ name = "ostree-ext"
77
readme = "../README.md"
88
repository = "https://github.com/ostreedev/ostree-rs-ext"
99
version = "0.15.3"
10-
rust-version = "1.74.0"
1110

1211
[dependencies]
1312
# Note that we re-export the oci-spec types

0 commit comments

Comments
 (0)