Skip to content

Commit 1fd4117

Browse files
jmarrerocgwalters
authored andcommitted
cli: Handle PermissionDenied when reading /proc/1/ns/ipc
In restricted build environments such as Tekton/Buildah containers, /proc/1/ns/ipc can be masked even when the process has CAP_SYS_ADMIN. The read_link() call fails with EACCES, which causes bootc to exit with a fatal error. Handle PermissionDenied by silently skipping the IPC namespace join, consistent with the existing CAP_SYS_ADMIN gate. Also drop tracing::debug! from join_host_ipc_namespace() since tracing is not yet initialized when global_init() runs. Fixes: bootc-dev@d250000 Assisted-by: OpenCode (Claude Opus 4.6) Signed-off-by: Joseph Marrero Corchado <jmarrero@redhat.com>
1 parent 298bb47 commit 1fd4117

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

crates/lib/src/cli.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,9 @@ async fn usroverlay(access_mode: FilesystemOverlayAccessMode) -> Result<()> {
16201620
///
16211621
/// Requires `CAP_SYS_ADMIN` (needed for `setns()`); silently skipped when
16221622
/// running unprivileged (e.g. during RPM build for manpage generation).
1623+
/// Also skipped when `/proc/1/ns/ipc` is not accessible, which can happen
1624+
/// in restricted build environments (e.g. Tekton/Buildah containers) where
1625+
/// `/proc` is masked even for processes with `CAP_SYS_ADMIN`.
16231626
fn join_host_ipc_namespace() -> Result<()> {
16241627
let caps = rustix::thread::capabilities(None).context("capget")?;
16251628
if !caps
@@ -1628,7 +1631,13 @@ fn join_host_ipc_namespace() -> Result<()> {
16281631
{
16291632
return Ok(());
16301633
}
1631-
let ns_pid1 = std::fs::read_link("/proc/1/ns/ipc").context("reading /proc/1/ns/ipc")?;
1634+
let ns_pid1 = match std::fs::read_link("/proc/1/ns/ipc") {
1635+
Ok(v) => v,
1636+
Err(e) if e.kind() == std::io::ErrorKind::PermissionDenied => {
1637+
return Ok(());
1638+
}
1639+
Err(e) => return Err(e).context("reading /proc/1/ns/ipc"),
1640+
};
16321641
let ns_self = std::fs::read_link("/proc/self/ns/ipc").context("reading /proc/self/ns/ipc")?;
16331642
if ns_pid1 != ns_self {
16341643
let pid1ipcns = std::fs::File::open("/proc/1/ns/ipc").context("open pid1 ipcns")?;
@@ -1637,7 +1646,6 @@ fn join_host_ipc_namespace() -> Result<()> {
16371646
Some(rustix::thread::LinkNameSpaceType::InterProcessCommunication),
16381647
)
16391648
.context("setns(ipc)")?;
1640-
tracing::debug!("Joined pid1 IPC namespace");
16411649
}
16421650
Ok(())
16431651
}

0 commit comments

Comments
 (0)