Skip to content

test(shim): skip privileged tests without required permissions#477

Open
immanuwell wants to merge 1 commit into
containerd:mainfrom
immanuwell:test/shim-skip-privileged-tests
Open

test(shim): skip privileged tests without required permissions#477
immanuwell wants to merge 1 commit into
containerd:mainfrom
immanuwell:test/shim-skip-privileged-tests

Conversation

@immanuwell

Copy link
Copy Markdown
Contributor

normal cargo test -p containerd-shim --lib can fail on a non-root linux box, even when nothing is wrong with the code.

this keeps the privileged tests strict, but bails out early when the host just does not allow cgroup writes, overlay mounts, or loop device setup. so local runs stop tripping over env stuff, neat and simple.

repro:

  1. use a regular non-root shell on linux
  2. run cargo +stable test -p containerd-shim --lib
  3. run cargo +stable test -p containerd-shim --lib --features async
  4. before this patch you can hit Permission denied from test_add_cgroup or test_setup_loop_dev, and overlay mount can fail too

checks:

  • cargo +stable check -p containerd-shim --all-targets
  • cargo +stable test -p containerd-shim --lib
  • cargo +stable test -p containerd-shim --lib --features async
  • cargo +stable test -p runc --lib

@github-actions github-actions Bot added the C-shim Containerd shim label Jun 21, 2026
@immanuwell immanuwell force-pushed the test/shim-skip-privileged-tests branch from e4b7e98 to fa104de Compare June 21, 2026 17:11
@mxpv mxpv requested a review from Copilot June 22, 2026 00:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to make containerd-shim’s Linux privileged unit tests stop failing on non-root hosts due to environmental permission constraints (cgroup writes, overlay mounts, loop device setup), by detecting permission-related failures and exiting tests early while keeping the tests strict when privileges are available.

Changes:

  • Added a test-only helper to classify “permission denied / not permitted” errors.
  • Updated overlay mount + recursive unmount and loop device setup tests to skip when the host lacks required permissions.
  • Updated the cgroup test to skip when cgroup creation/task addition fails due to missing permissions.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
crates/shim/src/mount_linux.rs Skip privileged mount/loop tests when permission errors occur, otherwise assert strictly.
crates/shim/src/error.rs Introduces a test-only helper for recognizing permission-related errors.
crates/shim/src/cgroup.rs Makes cgroup test skip early when cgroup operations fail due to permission constraints.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/shim/src/error.rs
Comment on lines +96 to +100
#[cfg(unix)]
Error::Nix(err) | Error::MountError { err, .. } => {
matches!(err, nix::errno::Errno::EACCES | nix::errno::Errno::EPERM)
}
Error::Other(msg) => {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-shim Containerd shim

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants