@@ -1003,7 +1003,7 @@ pub(crate) fn finalize_filesystem(
1003
1003
/// A heuristic check that we were invoked with --pid=host
1004
1004
fn require_host_pidns ( ) -> Result < ( ) > {
1005
1005
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 " )
1007
1007
}
1008
1008
tracing:: trace!( "OK: we're not pid 1" ) ;
1009
1009
Ok ( ( ) )
@@ -1019,9 +1019,7 @@ fn require_host_userns() -> Result<()> {
1019
1019
. uid ( ) ;
1020
1020
// We must really be in a rootless container, or in some way
1021
1021
// 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)" ) ;
1025
1023
tracing:: trace!( "OK: we're in a matching user namespace with pid1" ) ;
1026
1024
Ok ( ( ) )
1027
1025
}
@@ -1154,18 +1152,17 @@ async fn prepare_install(
1154
1152
target_opts : InstallTargetOpts ,
1155
1153
) -> Result < Arc < State > > {
1156
1154
tracing:: trace!( "Preparing install" ) ;
1157
- // We need full root privileges, i.e. --privileged in podman
1158
- crate :: cli:: require_root ( ) ?;
1159
1155
let rootfs = cap_std:: fs:: Dir :: open_ambient_dir ( "/" , cap_std:: ambient_authority ( ) )
1160
1156
. context ( "Opening /" ) ?;
1161
1157
1162
1158
let host_is_container = crate :: containerenv:: is_container ( & rootfs) ;
1163
1159
let external_source = source_opts. source_imgref . is_some ( ) ;
1164
1160
let source = match source_opts. source_imgref {
1165
1161
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
+
1169
1166
require_host_pidns ( ) ?;
1170
1167
// Out of conservatism we only verify the host userns path when we're expecting
1171
1168
// to do a self-install (e.g. not bootc-image-builder or equivalent).
@@ -1187,7 +1184,10 @@ async fn prepare_install(
1187
1184
1188
1185
SourceInfo :: from_container ( & rootfs, & container_info) ?
1189
1186
}
1190
- Some ( source) => SourceInfo :: from_imageref ( & source, & rootfs) ?,
1187
+ Some ( source) => {
1188
+ crate :: cli:: require_root ( false ) ?;
1189
+ SourceInfo :: from_imageref ( & source, & rootfs) ?
1190
+ }
1191
1191
} ;
1192
1192
1193
1193
// Parse the target CLI image reference options and create the *target* image
0 commit comments