@@ -9,6 +9,7 @@ use std::str::FromStr;
9
9
use anyhow:: { Context , Result } ;
10
10
use camino:: Utf8Path ;
11
11
use cap_std_ext:: dirext:: CapStdExtDirExt ;
12
+ use fn_error_context:: context;
12
13
use ocidir:: cap_std:: fs:: Dir ;
13
14
use ostree:: glib:: object:: Cast ;
14
15
use ostree:: prelude:: FileExt ;
@@ -21,7 +22,8 @@ use crate::utils::ResultExt;
21
22
/// The relative path to ostree-prepare-root's config.
22
23
pub const CONF_PATH : & str = "ostree/prepare-root.conf" ;
23
24
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 > > {
25
27
let cancellable = gio:: Cancellable :: NONE ;
26
28
let kf = glib:: KeyFile :: new ( ) ;
27
29
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> {
66
68
67
69
/// Query whether the target root has the `root.transient` key
68
70
/// 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 > {
70
72
if let Some ( config) = load_config ( root) ? {
71
73
overlayfs_enabled_in_config ( & config)
72
74
} else {
73
75
Ok ( false )
74
76
}
75
77
}
76
78
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
79
83
Enabled ,
84
+ /// Disabled
80
85
Disabled ,
86
+ /// Maybe
81
87
Maybe ,
82
88
}
83
89
@@ -111,9 +117,14 @@ impl Tristate {
111
117
}
112
118
}
113
119
120
+ /// The state of a composefs for ostree
114
121
#[ derive( Debug , PartialEq , Eq ) ]
115
- enum ComposefsState {
122
+ pub enum ComposefsState {
123
+ /// The composefs must be signed and use fsverity
116
124
Signed ,
125
+ /// The composefs must use fsverity
126
+ Verity ,
127
+ /// The composefs may or may not be enabled.
117
128
Tristate ( Tristate ) ,
118
129
}
119
130
@@ -126,9 +137,11 @@ impl Default for ComposefsState {
126
137
impl FromStr for ComposefsState {
127
138
type Err = anyhow:: Error ;
128
139
140
+ #[ context( "Parsing composefs.enabled value {s}" ) ]
129
141
fn from_str ( s : & str ) -> Result < Self > {
130
142
let r = match s {
131
143
"signed" => Self :: Signed ,
144
+ "verity" => Self :: Verity ,
132
145
o => Self :: Tristate ( Tristate :: from_str ( o) ?) ,
133
146
} ;
134
147
Ok ( r)
@@ -138,10 +151,15 @@ impl FromStr for ComposefsState {
138
151
impl ComposefsState {
139
152
pub ( crate ) fn maybe_enabled ( & self ) -> bool {
140
153
match self {
141
- ComposefsState :: Signed => true ,
154
+ ComposefsState :: Signed | ComposefsState :: Verity => true ,
142
155
ComposefsState :: Tristate ( t) => t. maybe_enabled ( ) ,
143
156
}
144
157
}
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
+ }
145
163
}
146
164
147
165
/// Query whether the config uses an overlayfs model (composefs or plain overlayfs).
0 commit comments