File tree Expand file tree Collapse file tree 3 files changed +17
-1
lines changed Expand file tree Collapse file tree 3 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ once_cell = "1.9"
24
24
openssl = " ^0.10"
25
25
nix = " >= 0.24, < 0.26"
26
26
regex = " 1.7.1"
27
+ rustix = { "version" = " 0.36" , features = [" thread" ] }
27
28
serde = { features = [" derive" ], version = " 1.0.125" }
28
29
serde_json = " 1.0.64"
29
30
serde_with = " >= 1.9.4, < 2"
Original file line number Diff line number Diff line change 4
4
5
5
use anyhow:: { Context , Result } ;
6
6
use camino:: Utf8PathBuf ;
7
+ use cap_std_ext:: rustix;
7
8
use clap:: Parser ;
8
9
use fn_error_context:: context;
9
10
use ostree:: { gio, glib} ;
@@ -124,7 +125,7 @@ pub(crate) enum Opt {
124
125
/// we can depend on a new enough ostree
125
126
#[ context( "Ensuring mountns" ) ]
126
127
pub ( crate ) async fn ensure_self_unshared_mount_namespace ( ) -> Result < ( ) > {
127
- let uid = cap_std_ext :: rustix:: process:: getuid ( ) ;
128
+ let uid = rustix:: process:: getuid ( ) ;
128
129
if !uid. is_root ( ) {
129
130
tracing:: debug!( "Not root, assuming no need to unshare" ) ;
130
131
return Ok ( ( ) ) ;
@@ -224,6 +225,18 @@ async fn stage(
224
225
Ok ( ( ) )
225
226
}
226
227
228
+ #[ context( "Querying root privilege" ) ]
229
+ pub ( crate ) fn require_root ( ) -> Result < ( ) > {
230
+ let uid = rustix:: process:: getuid ( ) ;
231
+ if !uid. is_root ( ) {
232
+ anyhow:: bail!( "This command requires root privileges" ) ;
233
+ }
234
+ if !rustix:: thread:: is_in_capability_bounding_set ( rustix:: thread:: Capability :: SystemAdmin ) ? {
235
+ anyhow:: bail!( "This command requires full root privileges (CAP_SYS_ADMIN)" ) ;
236
+ }
237
+ Ok ( ( ) )
238
+ }
239
+
227
240
/// A few process changes that need to be made for writing.
228
241
#[ context( "Preparing for write" ) ]
229
242
async fn prepare_for_write ( ) -> Result < ( ) > {
Original file line number Diff line number Diff line change @@ -580,6 +580,8 @@ async fn prepare_install(
580
580
config_opts : InstallConfigOpts ,
581
581
target_opts : InstallTargetOpts ,
582
582
) -> Result < Arc < State > > {
583
+ // We need full root privileges, i.e. --privileged in podman
584
+ crate :: cli:: require_root ( ) ?;
583
585
// We require --pid=host
584
586
let pid = std:: fs:: read_link ( "/proc/1/exe" ) . context ( "reading /proc/1/exe" ) ?;
585
587
let pid = pid
You can’t perform that action at this time.
0 commit comments