@@ -119,6 +119,15 @@ fn bind_storage_roots(cmd: &mut Command, storage_root: &Dir, run_root: &Dir) ->
119119 Ok ( ( ) )
120120}
121121
122+ /// Get the global authfile from the host root filesystem.
123+ /// This is used as a fallback when the authfile is not found in the sysroot,
124+ /// such as during upgrades where the new image may not have auth.json
125+ /// but the running system does.
126+ fn get_host_authfile ( ) -> Result < Option < ( camino:: Utf8PathBuf , std:: fs:: File ) > > {
127+ let host_root = Dir :: open_ambient_dir ( "/" , cap_std:: ambient_authority ( ) ) ?;
128+ ostree_ext:: globals:: get_global_authfile ( & host_root)
129+ }
130+
122131// Initialize a `podman` subprocess with:
123132// - storage overridden to point to to storage_root
124133// - Authentication (auth.json) using the bootc/ostree owned auth
@@ -133,10 +142,22 @@ fn new_podman_cmd_in(sysroot: &Dir, storage_root: &Dir, run_root: &Dir) -> Resul
133142
134143 // Keep this in sync with https://github.com/bootc-dev/containers-image-proxy-rs/blob/b5e0861ad5065f47eaf9cda0d48da3529cc1bc43/src/imageproxy.rs#L310
135144 // We always override the auth to match the bootc setup.
136- let authfile_fd = ostree_ext:: globals:: get_global_authfile ( sysroot) ?. map ( |v| v. 1 ) ;
137- if let Some ( mut fd) = authfile_fd {
145+ // First try to get the authfile from the sysroot (e.g., upgrade image), and if not found,
146+ // fall back to the host root. This handles the case where during an upgrade, the new image
147+ // may not have auth.json but the running system does.
148+ let authfile = if let Some ( ( path, file) ) = ostree_ext:: globals:: get_global_authfile ( sysroot) ? {
149+ tracing:: debug!( "Using authfile from sysroot: {path}" ) ;
150+ Some ( file)
151+ } else if let Some ( ( path, file) ) = get_host_authfile ( ) ? {
152+ tracing:: debug!( "Using authfile from host root: {path}" ) ;
153+ Some ( file)
154+ } else {
155+ None
156+ } ;
157+ if let Some ( mut fd) = authfile {
138158 std:: io:: copy ( & mut fd, & mut tempfile) ?;
139159 } else {
160+ tracing:: debug!( "No authfile found, using empty auth" ) ;
140161 // Note that if there's no bootc-owned auth, then we force an empty authfile to ensure
141162 // that podman doesn't fall back to searching the user-owned paths.
142163 tempfile. write_all ( b"{}" ) ?;
0 commit comments