@@ -24,7 +24,6 @@ use ostree_ext::ostree;
24
24
use ostree_ext:: prelude:: Cast ;
25
25
use serde:: { Deserialize , Serialize } ;
26
26
27
- use crate :: containerenv:: ContainerExecutionInfo ;
28
27
use crate :: lsm:: lsm_label;
29
28
use crate :: task:: Task ;
30
29
use crate :: utils:: run_in_host_mountns;
@@ -234,7 +233,10 @@ pub(crate) struct InstallToFilesystemOpts {
234
233
235
234
// Shared read-only global state
236
235
struct State {
237
- container_info : ContainerExecutionInfo ,
236
+ /// Image reference we'll pull from (today always containers-storage: type)
237
+ source_imageref : ostree_container:: ImageReference ,
238
+ /// The digest to use for pulls
239
+ source_digest : String ,
238
240
/// Force SELinux off in target system
239
241
override_disable_selinux : bool ,
240
242
config_opts : InstallConfigOpts ,
@@ -416,20 +418,6 @@ async fn initialize_ostree_root_from_self(
416
418
let opts = & state. target_opts ;
417
419
let cancellable = gio:: Cancellable :: NONE ;
418
420
419
- if !state. container_info . engine . starts_with ( "podman" ) {
420
- anyhow:: bail!( "Currently this command only supports being executed via podman" ) ;
421
- }
422
- if state. container_info . imageid . is_empty ( ) {
423
- anyhow:: bail!( "Invalid empty imageid" ) ;
424
- }
425
- let digest = crate :: podman:: imageid_to_digest ( & state. container_info . imageid ) ?;
426
- let src_image = crate :: utils:: digested_pullspec ( & state. container_info . image , & digest) ;
427
-
428
- let src_imageref = ostree_container:: ImageReference {
429
- transport : ostree_container:: Transport :: ContainerStorage ,
430
- name : src_image. clone ( ) ,
431
- } ;
432
-
433
421
// Parse the target CLI image reference options
434
422
let target_sigverify = if opts. target_no_signature_verification {
435
423
SignatureSource :: ContainerPolicyAllowInsecure
@@ -451,10 +439,7 @@ async fn initialize_ostree_root_from_self(
451
439
} else {
452
440
ostree_container:: OstreeImageReference {
453
441
sigverify : target_sigverify,
454
- imgref : ostree_container:: ImageReference {
455
- transport : ostree_container:: Transport :: Registry ,
456
- name : state. container_info . image . clone ( ) ,
457
- } ,
442
+ imgref : state. source_imageref . clone ( ) ,
458
443
}
459
444
} ;
460
445
@@ -493,11 +478,17 @@ async fn initialize_ostree_root_from_self(
493
478
494
479
let mut temporary_dir = None ;
495
480
let src_imageref = if skopeo_supports_containers_storage ( ) ? {
496
- src_imageref
481
+ // We always use exactly the digest of the running image to ensure predictability.
482
+ let spec =
483
+ crate :: utils:: digested_pullspec ( & state. source_imageref . name , & state. source_digest ) ;
484
+ ostree_container:: ImageReference {
485
+ transport : ostree_container:: Transport :: ContainerStorage ,
486
+ name : spec,
487
+ }
497
488
} else {
498
489
let td = tempfile:: tempdir_in ( "/var/tmp" ) ?;
499
490
let path: & Utf8Path = td. path ( ) . try_into ( ) . unwrap ( ) ;
500
- let r = copy_to_oci ( & src_imageref , path) ?;
491
+ let r = copy_to_oci ( & state . source_imageref , path) ?;
501
492
temporary_dir = Some ( td) ;
502
493
r
503
494
} ;
@@ -555,7 +546,7 @@ async fn initialize_ostree_root_from_self(
555
546
let uname = cap_std_ext:: rustix:: process:: uname ( ) ;
556
547
557
548
let aleph = InstallAleph {
558
- image : src_image ,
549
+ image : src_imageref . imgref . name . clone ( ) ,
559
550
kernel : uname. release ( ) . to_str ( ) ?. to_string ( ) ,
560
551
} ;
561
552
@@ -903,6 +894,18 @@ async fn prepare_install(
903
894
904
895
// This command currently *must* be run inside a privileged container.
905
896
let container_info = crate :: containerenv:: get_container_execution_info ( ) ?;
897
+ if !container_info. engine . starts_with ( "podman" ) {
898
+ anyhow:: bail!( "Currently this command only supports being executed via podman" ) ;
899
+ }
900
+ if container_info. imageid . is_empty ( ) {
901
+ anyhow:: bail!( "Invalid empty imageid" ) ;
902
+ }
903
+ let source_imageref = ostree_container:: ImageReference {
904
+ transport : ostree_container:: Transport :: ContainerStorage ,
905
+ name : container_info. image . clone ( ) ,
906
+ } ;
907
+ // Find the exact digested image we are running
908
+ let source_digest = crate :: podman:: imageid_to_digest ( & container_info. imageid ) ?;
906
909
907
910
// Even though we require running in a container, the mounts we create should be specific
908
911
// to this process, so let's enter a private mountns to avoid leaking them.
@@ -943,7 +946,8 @@ async fn prepare_install(
943
946
bind_mount_from_host ( "/var/tmp" , "/var/tmp" ) ?;
944
947
let state = Arc :: new ( State {
945
948
override_disable_selinux,
946
- container_info,
949
+ source_imageref,
950
+ source_digest,
947
951
mntdir,
948
952
devdir,
949
953
config_opts,
0 commit comments