Skip to content

Commit dbd9e44

Browse files
authored
Merge pull request #1175 from cgwalters/update-verity-required2
ostree-ext: Update parser to honor `composefs=verity`
2 parents b233fe0 + 06933ed commit dbd9e44

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

ostree-ext/src/ostree_prepareroot.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::str::FromStr;
99
use anyhow::{Context, Result};
1010
use camino::Utf8Path;
1111
use cap_std_ext::dirext::CapStdExtDirExt;
12+
use fn_error_context::context;
1213
use ocidir::cap_std::fs::Dir;
1314
use ostree::glib::object::Cast;
1415
use ostree::prelude::FileExt;
@@ -21,7 +22,8 @@ use crate::utils::ResultExt;
2122
/// The relative path to ostree-prepare-root's config.
2223
pub const CONF_PATH: &str = "ostree/prepare-root.conf";
2324

24-
pub(crate) fn load_config(root: &ostree::RepoFile) -> Result<Option<glib::KeyFile>> {
25+
/// Load the ostree prepare-root config from the given ostree repository.
26+
pub fn load_config(root: &ostree::RepoFile) -> Result<Option<glib::KeyFile>> {
2527
let cancellable = gio::Cancellable::NONE;
2628
let kf = glib::KeyFile::new();
2729
for path in ["etc", "usr/lib"].into_iter().map(Utf8Path::new) {
@@ -66,18 +68,22 @@ pub fn require_config_from_root(root: &Dir) -> Result<glib::KeyFile> {
6668

6769
/// Query whether the target root has the `root.transient` key
6870
/// which sets up a transient overlayfs.
69-
pub(crate) fn overlayfs_root_enabled(root: &ostree::RepoFile) -> Result<bool> {
71+
pub fn overlayfs_root_enabled(root: &ostree::RepoFile) -> Result<bool> {
7072
if let Some(config) = load_config(root)? {
7173
overlayfs_enabled_in_config(&config)
7274
} else {
7375
Ok(false)
7476
}
7577
}
7678

77-
#[derive(Debug, PartialEq, Eq)]
78-
enum Tristate {
79+
/// An option which can be enabled, disabled, or possibly enabled.
80+
#[derive(Debug, PartialEq, Eq, Clone)]
81+
pub enum Tristate {
82+
/// Enabled
7983
Enabled,
84+
/// Disabled
8085
Disabled,
86+
/// Maybe
8187
Maybe,
8288
}
8389

@@ -111,9 +117,14 @@ impl Tristate {
111117
}
112118
}
113119

120+
/// The state of a composefs for ostree
114121
#[derive(Debug, PartialEq, Eq)]
115-
enum ComposefsState {
122+
pub enum ComposefsState {
123+
/// The composefs must be signed and use fsverity
116124
Signed,
125+
/// The composefs must use fsverity
126+
Verity,
127+
/// The composefs may or may not be enabled.
117128
Tristate(Tristate),
118129
}
119130

@@ -126,9 +137,11 @@ impl Default for ComposefsState {
126137
impl FromStr for ComposefsState {
127138
type Err = anyhow::Error;
128139

140+
#[context("Parsing composefs.enabled value {s}")]
129141
fn from_str(s: &str) -> Result<Self> {
130142
let r = match s {
131143
"signed" => Self::Signed,
144+
"verity" => Self::Verity,
132145
o => Self::Tristate(Tristate::from_str(o)?),
133146
};
134147
Ok(r)
@@ -138,10 +151,15 @@ impl FromStr for ComposefsState {
138151
impl ComposefsState {
139152
pub(crate) fn maybe_enabled(&self) -> bool {
140153
match self {
141-
ComposefsState::Signed => true,
154+
ComposefsState::Signed | ComposefsState::Verity => true,
142155
ComposefsState::Tristate(t) => t.maybe_enabled(),
143156
}
144157
}
158+
159+
/// This configuration requires fsverity on the target filesystem.
160+
pub fn requires_fsverity(&self) -> bool {
161+
matches!(self, ComposefsState::Signed | ComposefsState::Verity)
162+
}
145163
}
146164

147165
/// Query whether the config uses an overlayfs model (composefs or plain overlayfs).

0 commit comments

Comments
 (0)