Skip to content

Commit a2a5a7c

Browse files
committed
install: Parse and load the prepare-root config
Prep for using this to determine fsverity. Signed-off-by: Colin Walters <[email protected]>
1 parent 2b175ad commit a2a5a7c

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

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,

0 commit comments

Comments
 (0)