Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip tests on systems with restricted usernamespaces (backport #12051) #12183

Open
wants to merge 1 commit into
base: 2.24-maintenance
Choose a base branch
from

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Jan 10, 2025

Depends on #12050

This makes ci pass: https://github.com/NixOS/nix/actions/runs/12329995455/job/34414955507?pr=12051
even on systems that have restricted usernamespaces: 6642863


This is an automatic backport of pull request #12051 done by Mergify.

…r namespaces

Update tests/functional/common/functions.sh

Co-authored-by: Robert Hensing <[email protected]>
(cherry picked from commit da7f7ba)

# Conflicts:
#	tests/functional/common/vars-and-functions.sh
#	tests/functional/supplementary-groups.sh
Copy link
Contributor Author

mergify bot commented Jan 10, 2025

Cherry-pick of da7f7ba has failed:

On branch mergify/bp/2.24-maintenance/pr-12051
Your branch is up to date with 'origin/2.24-maintenance'.

You are currently cherry-picking commit da7f7ba81.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   tests/functional/build-remote-trustless-should-fail-0.sh
	modified:   tests/functional/build-remote-trustless.sh
	modified:   tests/functional/build-remote.sh
	modified:   tests/functional/chroot-store.sh
	modified:   tests/functional/linux-sandbox.sh
	modified:   tests/functional/local-overlay-store/bad-uris.sh
	modified:   tests/functional/local-overlay-store/common.sh
	modified:   tests/functional/nested-sandboxing.sh
	modified:   tests/functional/nested-sandboxing/command.sh
	modified:   tests/functional/shell.sh

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   tests/functional/common/vars-and-functions.sh
	both modified:   tests/functional/supplementary-groups.sh

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@github-actions github-actions bot added the with-tests Issues related to testing. PRs with tests have some priority label Jan 10, 2025
Copy link
Member

@bryango bryango left a comment

Choose a reason for hiding this comment

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

@Mic92 I have verified such changes do work on my machine.

Comment on lines +408 to +423
<<<<<<< HEAD:tests/functional/common/vars-and-functions.sh
fi # COMMON_VARS_AND_FUNCTIONS_SH_SOURCED
=======
requiresUnprivilegedUserNamespaces() {
if [[ -f /proc/sys/kernel/apparmor_restrict_unprivileged_userns ]] && [[ $(< /proc/sys/kernel/apparmor_restrict_unprivileged_userns) -eq 1 ]]; then
skipTest "Unprivileged user namespaces are disabled. Run 'sudo sysctl -w /proc/sys/kernel/apparmor_restrict_unprivileged_userns=0' to allow, and run these tests."
fi
}

execUnshare () {
requiresUnprivilegedUserNamespaces
exec unshare --mount --map-root-user "$SHELL" "$@"
}

fi # COMMON_FUNCTIONS_SH_SOURCED
>>>>>>> da7f7ba81 (functional-tests: skip tests if the kernel restricts unprivileged user namespaces):tests/functional/common/functions.sh
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<<<<<<< HEAD:tests/functional/common/vars-and-functions.sh
fi # COMMON_VARS_AND_FUNCTIONS_SH_SOURCED
=======
requiresUnprivilegedUserNamespaces() {
if [[ -f /proc/sys/kernel/apparmor_restrict_unprivileged_userns ]] && [[ $(< /proc/sys/kernel/apparmor_restrict_unprivileged_userns) -eq 1 ]]; then
skipTest "Unprivileged user namespaces are disabled. Run 'sudo sysctl -w /proc/sys/kernel/apparmor_restrict_unprivileged_userns=0' to allow, and run these tests."
fi
}
execUnshare () {
requiresUnprivilegedUserNamespaces
exec unshare --mount --map-root-user "$SHELL" "$@"
}
fi # COMMON_FUNCTIONS_SH_SOURCED
>>>>>>> da7f7ba81 (functional-tests: skip tests if the kernel restricts unprivileged user namespaces):tests/functional/common/functions.sh
requiresUnprivilegedUserNamespaces() {
if [[ -f /proc/sys/kernel/apparmor_restrict_unprivileged_userns ]] && [[ $(< /proc/sys/kernel/apparmor_restrict_unprivileged_userns) -eq 1 ]]; then
skipTest "Unprivileged user namespaces are disabled. Run 'sudo sysctl -w /proc/sys/kernel/apparmor_restrict_unprivileged_userns=0' to allow, and run these tests."
fi
}
execUnshare () {
requiresUnprivilegedUserNamespaces
exec unshare --mount --map-root-user "$SHELL" "$@"
}
fi # COMMON_VARS_AND_FUNCTIONS_SH_SOURCED

Comment on lines +12 to +16
<<<<<<< HEAD
unshare --mount --map-root-user bash <<EOF
=======
execUnshare <<EOF
>>>>>>> da7f7ba81 (functional-tests: skip tests if the kernel restricts unprivileged user namespaces)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<<<<<<< HEAD
unshare --mount --map-root-user bash <<EOF
=======
execUnshare <<EOF
>>>>>>> da7f7ba81 (functional-tests: skip tests if the kernel restricts unprivileged user namespaces)
execUnshare <<EOF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conflicts merge-queue with-tests Issues related to testing. PRs with tests have some priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants