Skip to content

cli: Handle PermissionDenied when reading /proc/1/ns/ipc#2162

Open
jmarrero wants to merge 1 commit intobootc-dev:mainfrom
jmarrero:fix-ipc-ns-permission-denied
Open

cli: Handle PermissionDenied when reading /proc/1/ns/ipc#2162
jmarrero wants to merge 1 commit intobootc-dev:mainfrom
jmarrero:fix-ipc-ns-permission-denied

Conversation

@jmarrero
Copy link
Copy Markdown
Contributor

@jmarrero jmarrero commented Apr 23, 2026

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 skipping the IPC namespace join, consistent with the existing CAP_SYS_ADMIN gate.

Fixes: d250000
Assisted-by: OpenCode (Claude Opus 4.6)

@bootc-bot bootc-bot Bot requested a review from ckyrouac April 23, 2026 19:55
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the join_host_ipc_namespace function to gracefully handle PermissionDenied errors when reading /proc/1/ns/ipc, which is common in restricted container environments. The review feedback identifies a critical compilation error in the error handling logic where the returned Result type does not match the function signature. Additionally, it was noted that the new debug log message will be ineffective because tracing is not yet initialized when this function is executed.

Comment thread crates/lib/src/cli.rs
Comment thread crates/lib/src/cli.rs Outdated
let ns_pid1 = match std::fs::read_link("/proc/1/ns/ipc") {
Ok(v) => v,
Err(e) if e.kind() == std::io::ErrorKind::PermissionDenied => {
tracing::debug!("Skipping IPC namespace join: /proc/1/ns/ipc not accessible: {e}");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Note that tracing is not yet initialized when this function is called during global_init in the bootc CLI. As a result, this debug message will not be visible in the logs even if the log level is set to debug. To fix this, the tracing initialization in crates/cli/src/main.rs would need to be moved before the call to global_init.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a very insightful comment.

@cgwalters cgwalters enabled auto-merge (rebase) April 23, 2026 21:50
@jmarrero jmarrero force-pushed the fix-ipc-ns-permission-denied branch from 80384b4 to b225a6a Compare April 24, 2026 20:13
Comment thread crates/cli/src/main.rs Outdated
/// and do the rest of the work there.
fn run() -> Result<()> {
// Initialize tracing early so that global_init() can use tracing macros
bootc_utils::initialize_tracing();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to ensure that we call into as little code as possible before global_init().

So my preferred fix here is to drop the tracing usage from global_init instead.

Copy link
Copy Markdown
Collaborator

@cgwalters cgwalters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marking as requested changes per above

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>
@jmarrero jmarrero force-pushed the fix-ipc-ns-permission-denied branch from b225a6a to c921172 Compare April 24, 2026 23:26
@jmarrero jmarrero requested a review from cgwalters April 24, 2026 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants