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