Skip to content

Commit 37d3389

Browse files
committed
Update cap-std-ext to 5.1.2, use new CmdFds API
This is a safer API, but this is specifically prep for using varlink. Assisted-by: OpenCode (Claude Opus 4) Signed-off-by: Colin Walters <walters@verbum.org>
1 parent ca9f93c commit 37d3389

5 files changed

Lines changed: 55 additions & 33 deletions

File tree

Cargo.lock

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ anstream = "1.0"
3535
anyhow = "1.0.82"
3636
camino = "1.1.6"
3737
canon-json = "0.2.1"
38-
cap-std-ext = "5.1.1"
38+
cap-std-ext = "5.1.2"
3939
cfg-if = "1.0"
4040
chrono = { version = "0.4.38", default-features = false }
4141
clap = "4.5.4"

crates/lib/src/podstorage.rs

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use bootc_utils::{AsyncCommandRunExt, CommandRunExt, ExitStatusExt};
1919
use camino::{Utf8Path, Utf8PathBuf};
2020
use cap_std_ext::cap_std::fs::Dir;
2121
use cap_std_ext::cap_tempfile::TempDir;
22-
use cap_std_ext::cmdext::CapStdExtCommandExt;
22+
use cap_std_ext::cmdext::{CapStdExtCommandExt, CmdFds};
2323
use cap_std_ext::dirext::CapStdExtDirExt;
2424
use cap_std_ext::{cap_std, cap_tempfile};
2525
use 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!(

crates/ostree-ext/src/container/skopeo.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use super::ImageReference;
44
use anyhow::{Context, Result};
5-
use cap_std_ext::cmdext::CapStdExtCommandExt;
5+
use cap_std_ext::cmdext::{CapStdExtCommandExt, CmdFds};
66
use containers_image_proxy::oci_spec::image as oci_image;
77
use fn_error_context::context;
88
use io_lifetimes::OwnedFd;
@@ -80,7 +80,9 @@ pub async fn copy(
8080
cmd.arg("--digestfile");
8181
cmd.arg(digestfile.path());
8282
if let Some((add_fd, n)) = add_fd {
83-
cmd.take_fd_n(add_fd, n);
83+
let mut fds = CmdFds::new();
84+
fds.take_fd_n(add_fd, n);
85+
cmd.take_fds(fds);
8486
}
8587
if let Some(authfile) = authfile {
8688
cmd.arg("--authfile");

crates/ostree-ext/src/tar/write.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use camino::{Utf8Component, Utf8Path, Utf8PathBuf};
1414

1515
use cap_std::io_lifetimes;
1616
use cap_std_ext::cap_std::fs::Dir;
17-
use cap_std_ext::cmdext::CapStdExtCommandExt;
17+
use cap_std_ext::cmdext::{CapStdExtCommandExt, CmdFds};
1818
use cap_std_ext::{cap_std, cap_tempfile};
1919
use containers_image_proxy::oci_spec::image as oci_image;
2020
use fn_error_context::context;
@@ -423,7 +423,9 @@ pub async fn write_tar(
423423
.stdout(Stdio::piped())
424424
.stderr(Stdio::piped())
425425
.args(["commit"]);
426-
c.take_fd_n(repofd.clone(), 3);
426+
let mut fds = CmdFds::new();
427+
fds.take_fd_n(repofd.clone(), 3);
428+
c.take_fds(fds);
427429
c.arg("--repo=/proc/self/fd/3");
428430
if let Some(sepolicy) = sepolicy.as_ref() {
429431
c.arg("--selinux-policy");

0 commit comments

Comments
 (0)