@@ -19,7 +19,7 @@ use bootc_utils::{AsyncCommandRunExt, CommandRunExt, ExitStatusExt};
1919use camino:: { Utf8Path , Utf8PathBuf } ;
2020use cap_std_ext:: cap_std:: fs:: Dir ;
2121use cap_std_ext:: cap_tempfile:: TempDir ;
22- use cap_std_ext:: cmdext:: CapStdExtCommandExt ;
22+ use cap_std_ext:: cmdext:: { CapStdExtCommandExt , CmdFds } ;
2323use cap_std_ext:: dirext:: CapStdExtDirExt ;
2424use cap_std_ext:: { cap_std, cap_tempfile} ;
2525use fn_error_context:: context;
@@ -80,7 +80,12 @@ pub(crate) enum PullMode {
8080
8181#[ allow( unsafe_code) ]
8282#[ context( "Binding storage roots" ) ]
83- fn bind_storage_roots ( cmd : & mut Command , storage_root : & Dir , run_root : & Dir ) -> Result < ( ) > {
83+ pub ( crate ) fn bind_storage_roots (
84+ cmd : & mut Command ,
85+ fds : & mut CmdFds ,
86+ storage_root : & Dir ,
87+ run_root : & Dir ,
88+ ) -> Result < ( ) > {
8489 // podman requires an absolute path, for two reasons right now:
8590 // - It writes the file paths into `db.sql`, a sqlite database for unknown reasons
8691 // - It forks helper binaries, so just giving it /proc/self/fd won't work as
@@ -121,19 +126,16 @@ fn bind_storage_roots(cmd: &mut Command, storage_root: &Dir, run_root: &Dir) ->
121126 Ok ( ( ) )
122127 } )
123128 } ;
124- cmd . take_fd_n ( run_root, STORAGE_RUN_FD ) ;
129+ fds . take_fd_n ( run_root, STORAGE_RUN_FD ) ;
125130 Ok ( ( ) )
126131}
127132
128- // Initialize a `podman` subprocess with:
129- // - storage overridden to point to to storage_root
130- // - Authentication (auth.json) using the bootc/ostree owned auth
131- fn new_podman_cmd_in ( sysroot : & Dir , storage_root : & Dir , run_root : & Dir ) -> Result < Command > {
132- let mut cmd = Command :: new ( "podman" ) ;
133- bind_storage_roots ( & mut cmd, storage_root, run_root) ?;
134- let run_root = format ! ( "/proc/self/fd/{STORAGE_RUN_FD}" ) ;
135- cmd. args ( [ "--root" , STORAGE_ALIAS_DIR , "--runroot" , run_root. as_str ( ) ] ) ;
136-
133+ /// Set up `REGISTRY_AUTH_FILE` on a command, passing the bootc/ostree
134+ /// auth file via an anonymous tmpfile fd.
135+ ///
136+ /// If no bootc-owned auth is configured, an empty `{}` is passed to
137+ /// prevent podman from falling back to user-owned auth paths.
138+ pub ( crate ) fn setup_auth ( cmd : & mut Command , fds : & mut CmdFds , sysroot : & Dir ) -> Result < ( ) > {
137139 let tmpd = & cap_std:: fs:: Dir :: open_ambient_dir ( "/tmp" , cap_std:: ambient_authority ( ) ) ?;
138140 let mut tempfile = cap_tempfile:: TempFile :: new_anonymous ( tmpd) . map ( std:: io:: BufWriter :: new) ?;
139141
@@ -154,9 +156,23 @@ fn new_podman_cmd_in(sysroot: &Dir, storage_root: &Dir, run_root: &Dir) -> Resul
154156 . into_std ( ) ;
155157 let fd: Arc < OwnedFd > = std:: sync:: Arc :: new ( tempfile. into ( ) ) ;
156158 let target_fd = fd. as_fd ( ) . as_raw_fd ( ) ;
157- cmd . take_fd_n ( fd, target_fd) ;
159+ fds . take_fd_n ( fd, target_fd) ;
158160 cmd. env ( "REGISTRY_AUTH_FILE" , format ! ( "/proc/self/fd/{target_fd}" ) ) ;
159161
162+ Ok ( ( ) )
163+ }
164+
165+ // Initialize a `podman` subprocess with:
166+ // - storage overridden to point to to storage_root
167+ // - Authentication (auth.json) using the bootc/ostree owned auth
168+ fn new_podman_cmd_in ( sysroot : & Dir , storage_root : & Dir , run_root : & Dir ) -> Result < Command > {
169+ let mut cmd = Command :: new ( "podman" ) ;
170+ let mut fds = CmdFds :: new ( ) ;
171+ bind_storage_roots ( & mut cmd, & mut fds, storage_root, run_root) ?;
172+ let run_root = format ! ( "/proc/self/fd/{STORAGE_RUN_FD}" ) ;
173+ cmd. args ( [ "--root" , STORAGE_ALIAS_DIR , "--runroot" , run_root. as_str ( ) ] ) ;
174+ setup_auth ( & mut cmd, & mut fds, sysroot) ?;
175+ cmd. take_fds ( fds) ;
160176 Ok ( cmd)
161177}
162178
@@ -435,7 +451,9 @@ impl CStorage {
435451 cmd. stdout ( Stdio :: null ( ) ) ;
436452 // An ephemeral place for the transient state;
437453 let temp_runroot = TempDir :: new ( cap_std:: ambient_authority ( ) ) ?;
438- bind_storage_roots ( & mut cmd, & self . storage_root , & temp_runroot) ?;
454+ let mut fds = CmdFds :: new ( ) ;
455+ bind_storage_roots ( & mut cmd, & mut fds, & self . storage_root , & temp_runroot) ?;
456+ cmd. take_fds ( fds) ;
439457
440458 // The destination (target stateroot) + container storage dest
441459 let storage_dest = & format ! (
0 commit comments