Skip to content

Commit 999007f

Browse files
committed
lib: Pass absolute authfile path when pulling LBIs
ostree-ext explicitly handles authfile paths as relative; this works fine for most callers of get_global_authfile, as they only read the returned open file descriptor, and ignore the path. However, pulling logically bound images requires passing the actual authfile path to Podman, so we must resolve the absolute path in this case - otherwise, we see errors like the following: ``` [root@fedora ~]# bootc upgrade layers already present: 69; layers needed: 1 (242.2 MB) Fetched layers: 230.95 MiB in 3 seconds (90.88 MiB/s) Deploying: done (3 seconds) Fetching bound image: quay.io/prometheus/node-exporter:v1.10.2: done (0 seconds) error: Upgrading: Staging: Pulling bound images: Pulling bound images: Failed to pull image: Subprocess failed: ExitStatus(unix_wait_status(32000)) Error: credential file is not accessible: faccessat etc/ostree/auth.json: no such file or directory ``` Since cap_std::fs::Dir intentionally does not expose its filesystem path, we must resort to reconstructing it from a file descriptor. We could do this by inspectingthe file descriptor for `sysroot` and combining that with the relative path returned by get_global_authfile, but since get_global_authfile returns the descriptor of the actual authfile, we can simply read that directly. Signed-off-by: James Forcier <csssuf@csssuf.net>
1 parent a578483 commit 999007f

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

crates/lib/src/podstorage.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use cap_std_ext::cmdext::CapStdExtCommandExt;
2424
use cap_std_ext::dirext::CapStdExtDirExt;
2525
use fn_error_context::context;
2626
use ostree_ext::ostree::{self};
27-
use std::os::fd::OwnedFd;
27+
use std::os::fd::{AsRawFd, OwnedFd};
2828
use tokio::process::Command as AsyncCommand;
2929

3030
// Pass only 100 args at a time just to avoid potentially overflowing argument
@@ -353,10 +353,15 @@ impl CStorage {
353353
cmd.stdin(Stdio::null());
354354
cmd.stdout(Stdio::null());
355355
cmd.args(["pull", image]);
356-
let authfile = ostree_ext::globals::get_global_authfile(&self.sysroot)?
357-
.map(|(authfile, _fd)| authfile);
358-
if let Some(authfile) = authfile {
359-
cmd.args(["--authfile", authfile.as_str()]);
356+
let authfile_fd =
357+
ostree_ext::globals::get_global_authfile(&self.sysroot)?.map(|(_authfile, fd)| fd);
358+
if let Some(fd) = authfile_fd {
359+
let authfile_path = std::fs::read_link(format!("/proc/self/fd/{}", fd.as_raw_fd()))
360+
.map_err(Into::into)
361+
.and_then(|p| {
362+
Utf8PathBuf::from_path_buf(p).map_err(|_| anyhow::anyhow!("Invalid UTF-8"))
363+
})?;
364+
cmd.args(["--authfile", authfile_path.as_str()]);
360365
}
361366
tracing::debug!("Pulling image: {image}");
362367
let mut cmd = AsyncCommand::from(cmd);

0 commit comments

Comments
 (0)