Skip to content

Commit f20a3d6

Browse files
committed
ostree-ext: Update parser to honor composefs=verity
We have duplicate code to parse this between C and Rust unfortunately; update the Rust side to honor what landed in ostreedev/ostree#3354
1 parent cca41fb commit f20a3d6

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 glib::Cast;
1314
use ocidir::cap_std::fs::Dir;
1415
use ostree::prelude::FileExt;
@@ -20,7 +21,8 @@ use crate::utils::ResultExt;
2021

2122
pub(crate) const CONF_PATH: &str = "ostree/prepare-root.conf";
2223

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

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

76-
#[derive(Debug, PartialEq, Eq)]
77-
enum Tristate {
78+
/// An option which can be enabled, disabled, or possibly enabled.
79+
#[derive(Debug, PartialEq, Eq, Clone)]
80+
pub enum Tristate {
81+
/// Enabled
7882
Enabled,
83+
/// Disabled
7984
Disabled,
85+
/// Maybe
8086
Maybe,
8187
}
8288

@@ -110,9 +116,14 @@ impl Tristate {
110116
}
111117
}
112118

119+
/// The state of a composefs for ostree
113120
#[derive(Debug, PartialEq, Eq)]
114-
enum ComposefsState {
121+
pub enum ComposefsState {
122+
/// The composefs must be signed and use fsverity
115123
Signed,
124+
/// The composefs must use fsverity
125+
Verity,
126+
/// The composefs may or may not be enabled.
116127
Tristate(Tristate),
117128
}
118129

@@ -125,9 +136,11 @@ impl Default for ComposefsState {
125136
impl FromStr for ComposefsState {
126137
type Err = anyhow::Error;
127138

139+
#[context("Parsing composefs.enabled value {s}")]
128140
fn from_str(s: &str) -> Result<Self> {
129141
let r = match s {
130142
"signed" => Self::Signed,
143+
"verity" => Self::Verity,
131144
o => Self::Tristate(Tristate::from_str(o)?),
132145
};
133146
Ok(r)
@@ -137,10 +150,15 @@ impl FromStr for ComposefsState {
137150
impl ComposefsState {
138151
pub(crate) fn maybe_enabled(&self) -> bool {
139152
match self {
140-
ComposefsState::Signed => true,
153+
ComposefsState::Signed | ComposefsState::Verity => true,
141154
ComposefsState::Tristate(t) => t.maybe_enabled(),
142155
}
143156
}
157+
158+
/// This configuration requires fsverity on the target filesystem.
159+
pub fn requires_fsverity(&self) -> bool {
160+
matches!(self, ComposefsState::Signed | ComposefsState::Verity)
161+
}
144162
}
145163

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

0 commit comments

Comments
 (0)