@@ -310,6 +310,8 @@ pub(crate) struct State {
310
310
pub ( crate ) install_config : Option < config:: InstallConfiguration > ,
311
311
/// The parsed contents of the authorized_keys (not the file path)
312
312
pub ( crate ) root_ssh_authorized_keys : Option < String > ,
313
+ /// The root filesystem of the running container
314
+ pub ( crate ) container_root : Dir ,
313
315
}
314
316
315
317
impl State {
@@ -320,8 +322,7 @@ impl State {
320
322
return Ok ( None ) ;
321
323
}
322
324
// We always use the physical container root to bootstrap policy
323
- let rootfs = & Dir :: open_ambient_dir ( "/" , cap_std:: ambient_authority ( ) ) ?;
324
- let r = ostree:: SePolicy :: new_at ( rootfs. as_raw_fd ( ) , gio:: Cancellable :: NONE ) ?;
325
+ let r = ostree:: SePolicy :: new_at ( self . container_root . as_raw_fd ( ) , gio:: Cancellable :: NONE ) ?;
325
326
let csum = r
326
327
. csum ( )
327
328
. ok_or_else ( || anyhow:: anyhow!( "SELinux enabled, but no policy found in root" ) ) ?;
@@ -449,7 +450,10 @@ impl SourceInfo {
449
450
// Inspect container information and convert it to an ostree image reference
450
451
// that pulls from containers-storage.
451
452
#[ context( "Gathering source info from container env" ) ]
452
- pub ( crate ) fn from_container ( container_info : & ContainerExecutionInfo ) -> Result < Self > {
453
+ pub ( crate ) fn from_container (
454
+ root : & Dir ,
455
+ container_info : & ContainerExecutionInfo ,
456
+ ) -> Result < Self > {
453
457
if !container_info. engine . starts_with ( "podman" ) {
454
458
anyhow:: bail!( "Currently this command only supports being executed via podman" ) ;
455
459
}
@@ -463,7 +467,6 @@ impl SourceInfo {
463
467
tracing:: debug!( "Finding digest for image ID {}" , container_info. imageid) ;
464
468
let digest = crate :: podman:: imageid_to_digest ( & container_info. imageid ) ?;
465
469
466
- let root = Dir :: open_ambient_dir ( "/" , cap_std:: ambient_authority ( ) ) ?;
467
470
let have_host_container_storage = Utf8Path :: new ( crate :: podman:: CONTAINER_STORAGE )
468
471
. try_exists ( ) ?
469
472
&& ostree_ext:: mountutil:: is_mountpoint (
@@ -483,19 +486,26 @@ impl SourceInfo {
483
486
require_skopeo_with_containers_storage ( ) ?;
484
487
}
485
488
486
- Self :: new ( imageref, Some ( digest) , true , have_host_container_storage)
489
+ Self :: new (
490
+ imageref,
491
+ Some ( digest) ,
492
+ root,
493
+ true ,
494
+ have_host_container_storage,
495
+ )
487
496
}
488
497
489
498
#[ context( "Creating source info from a given imageref" ) ]
490
- pub ( crate ) fn from_imageref ( imageref : & str ) -> Result < Self > {
499
+ pub ( crate ) fn from_imageref ( imageref : & str , root : & Dir ) -> Result < Self > {
491
500
let imageref = ostree_container:: ImageReference :: try_from ( imageref) ?;
492
- Self :: new ( imageref, None , false , false )
501
+ Self :: new ( imageref, None , root , false , false )
493
502
}
494
503
495
504
/// Construct a new source information structure
496
505
fn new (
497
506
imageref : ostree_container:: ImageReference ,
498
507
digest : Option < String > ,
508
+ root : & Dir ,
499
509
in_host_mountns : bool ,
500
510
have_host_container_storage : bool ,
501
511
) -> Result < Self > {
@@ -504,7 +514,6 @@ impl SourceInfo {
504
514
. args ( [ "--repo=/ostree/repo" , "rev-parse" , "--single" ] )
505
515
. quiet ( )
506
516
. read ( ) ?;
507
- let root = cap_std:: fs:: Dir :: open_ambient_dir ( "/" , cap_std:: ambient_authority ( ) ) ?;
508
517
let repo = ostree:: Repo :: open_at_dir ( root. as_fd ( ) , "ostree/repo" ) ?;
509
518
let root = repo
510
519
. read_commit ( commit. trim ( ) , cancellable)
@@ -1110,9 +1119,9 @@ async fn prepare_install(
1110
1119
} ;
1111
1120
tracing:: trace!( "Read container engine info {:?}" , container_info) ;
1112
1121
1113
- SourceInfo :: from_container ( & container_info) ?
1122
+ SourceInfo :: from_container ( & rootfs , & container_info) ?
1114
1123
}
1115
- Some ( source) => SourceInfo :: from_imageref ( & source) ?,
1124
+ Some ( source) => SourceInfo :: from_imageref ( & source, & rootfs ) ?,
1116
1125
} ;
1117
1126
1118
1127
// Parse the target CLI image reference options and create the *target* image
@@ -1190,6 +1199,7 @@ async fn prepare_install(
1190
1199
target_imgref,
1191
1200
install_config,
1192
1201
root_ssh_authorized_keys,
1202
+ container_root : rootfs,
1193
1203
} ) ;
1194
1204
1195
1205
Ok ( state)
0 commit comments