@@ -1003,7 +1003,7 @@ pub(crate) fn finalize_filesystem(
10031003/// A heuristic check that we were invoked with --pid=host
10041004fn require_host_pidns ( ) -> Result < ( ) > {
10051005 if rustix:: process:: getpid ( ) . is_init ( ) {
1006- anyhow:: bail!( "This command must be run with --pid=host" )
1006+ anyhow:: bail!( "This command must be run with the podman --pid=host flag " )
10071007 }
10081008 tracing:: trace!( "OK: we're not pid 1" ) ;
10091009 Ok ( ( ) )
@@ -1019,9 +1019,7 @@ fn require_host_userns() -> Result<()> {
10191019 . uid ( ) ;
10201020 // We must really be in a rootless container, or in some way
10211021 // we're not part of the host user namespace.
1022- if pid1_uid != 0 {
1023- anyhow:: bail!( "{proc1} is owned by {pid1_uid}, not zero; this command must be run in the root user namespace (e.g. not rootless podman)" ) ;
1024- }
1022+ ensure ! ( pid1_uid == 0 , "{proc1} is owned by {pid1_uid}, not zero; this command must be run in the root user namespace (e.g. not rootless podman)" ) ;
10251023 tracing:: trace!( "OK: we're in a matching user namespace with pid1" ) ;
10261024 Ok ( ( ) )
10271025}
@@ -1154,18 +1152,17 @@ async fn prepare_install(
11541152 target_opts : InstallTargetOpts ,
11551153) -> Result < Arc < State > > {
11561154 tracing:: trace!( "Preparing install" ) ;
1157- // We need full root privileges, i.e. --privileged in podman
1158- crate :: cli:: require_root ( ) ?;
11591155 let rootfs = cap_std:: fs:: Dir :: open_ambient_dir ( "/" , cap_std:: ambient_authority ( ) )
11601156 . context ( "Opening /" ) ?;
11611157
11621158 let host_is_container = crate :: containerenv:: is_container ( & rootfs) ;
11631159 let external_source = source_opts. source_imgref . is_some ( ) ;
11641160 let source = match source_opts. source_imgref {
11651161 None => {
1166- if !host_is_container {
1167- anyhow:: bail!( "Either --source-imgref must be defined or this command must be executed inside a podman container." )
1168- }
1162+ ensure ! ( host_is_container, "Either --source-imgref must be defined or this command must be executed inside a podman container." ) ;
1163+
1164+ crate :: cli:: require_root ( true ) ?;
1165+
11691166 require_host_pidns ( ) ?;
11701167 // Out of conservatism we only verify the host userns path when we're expecting
11711168 // to do a self-install (e.g. not bootc-image-builder or equivalent).
@@ -1187,7 +1184,10 @@ async fn prepare_install(
11871184
11881185 SourceInfo :: from_container ( & rootfs, & container_info) ?
11891186 }
1190- Some ( source) => SourceInfo :: from_imageref ( & source, & rootfs) ?,
1187+ Some ( source) => {
1188+ crate :: cli:: require_root ( false ) ?;
1189+ SourceInfo :: from_imageref ( & source, & rootfs) ?
1190+ }
11911191 } ;
11921192
11931193 // Parse the target CLI image reference options and create the *target* image
0 commit comments