Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pym/bob/invoker.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ def ensureSandboxUsable():
ret = subprocess.run([getSandboxHelperPath(), "-C"], stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL).returncode
if ret != 0:
msg = None
knobs = [("/proc/sys/kernel/unprivileged_userns_clone", "1"),
("/proc/sys/kernel/apparmor_restrict_unprivileged_userns", "0")]
for knob, expected_val in knobs:
Expand All @@ -473,8 +474,13 @@ def ensureSandboxUsable():
except OSError:
msg = f"Make sure {knob} is {expected_val}."
break
else:

if not msg and any(k.startswith("NONO_") for k, v in os.environ.items()):
msg = f"The nono sandbox does not support nested unprivileged containers. See https://github.com/nolabs-ai/nono/issues/1980."

if not msg:
msg = f"Not sure why that is exactly. Please consider opening a bug report at https://github.com/BobBuildTool/bob."

raise BuildError("Your system does not support unprivileged containers! You need to build without sandbox (--no-sandbox).",
help=f"{msg} In case you use Docker, consider using the 'unconfined' seccomp profile."
" See https://bob-build-tool.readthedocs.io/en/latest/installation.html#sandbox-capabilities for more details.",
Expand Down
4 changes: 4 additions & 0 deletions test/black-box/commands/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ test_command()

for CMD in "${COMMANDS[@]}"; do
for SBX in "${SANDBOX_MODES[@]}" ; do
# Nested containers are not available in the nono sandbox
if is_nono && [[ ( $CMD == build || $CMD == dev || $CMD == project ) && -n "$SBX" && $SBX != --no-sandbox ]] ; then
continue
fi
test_command "$CMD" $SBX
done
done
3 changes: 3 additions & 0 deletions test/black-box/fingerprints/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ if [[ $(uname -o) == Msys ]] ; then
skip
fi

# Needs working sandbox
"${BOB_ROOT}/bin/bob-namespace-sandbox" -C || skip

# Test the various direct properties of fingerprint scripts
# =========================================================
#
Expand Down
14 changes: 7 additions & 7 deletions test/integration/gitea/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ def testUploadDownload(archiveUrl, env):
d = "testUploadDownload"
prepare(d, archiveUrl)

res = runBob(["build", "--download=no", "--upload", "root"], d, env)
res = runBob(["build", "--no-sandbox", "--download=no", "--upload", "root"], d, env)
assertEqual(res.returncode, 0)
assertEqual(readResult(d, "root"), "ok")

shutil.rmtree(os.path.join(d, "work"))

res = runBob(["build", "--download=forced", "root"], d, env)
res = runBob(["build", "--no-sandbox", "--download=forced", "root"], d, env)
assertEqual(res.returncode, 0)
assertEqual(readResult(d, "root"), "ok")

Expand All @@ -125,7 +125,7 @@ def testManage(archiveUrl, env):
d = "testManage"
prepare(d, archiveUrl)

res = runBob(["build", "--download=no", "--upload", "root-alpha", "root-bravo"], d, env)
res = runBob(["build", "--no-sandbox", "--download=no", "--upload", "root-alpha", "root-bravo"], d, env)
assertEqual(res.returncode, 0)

shutil.rmtree(os.path.join(d, "work"))
Expand All @@ -143,12 +143,12 @@ def testManage(archiveUrl, env):
assertEqual(res.returncode, 0)

# The retained artifact must still be downloadable...
res = runBob(["build", "--download=forced", "root-alpha"], d, env)
res = runBob(["build", "--no-sandbox", "--download=forced", "root-alpha"], d, env)
assertEqual(res.returncode, 0)
assertEqual(readResult(d, "root-alpha"), "alpha")

# ...but the pruned one must be gone from the archive.
res = runBob(["build", "--download=forced", "root-bravo"], d, env)
res = runBob(["build", "--no-sandbox", "--download=forced", "root-bravo"], d, env)
if res.returncode == 0:
print("[TEST]:", "Error: pruned artifact could still be downloaded!")
sys.exit(3)
Expand Down Expand Up @@ -224,6 +224,7 @@ def giteaCmd(args):
ROOT_URL = http://{GITEA_HOST}:{GITEA_PORT}/
DISABLE_SSH = true
OFFLINE_MODE = true
SSH_CREATE_AUTHORIZED_KEYS_FILE = false
[database]
DB_TYPE = sqlite3
Expand Down Expand Up @@ -276,8 +277,7 @@ def giteaCmd(args):

try:
giteaLog = open(os.path.join(workDir, "gitea.log"), "wb")
giteaProc = subprocess.Popen([gitea, "--config", appIni, "--work-path", workDir, "web"],
stdout=giteaLog, stderr=subprocess.STDOUT)
giteaProc = subprocess.Popen([gitea, "--config", appIni, "--work-path", workDir, "web"])
print("[TEST]:", "Gitea running as pid", giteaProc.pid, "in", workDir)

print("[TEST]:", "Waiting for Gitea to get ready...")
Expand Down
54 changes: 49 additions & 5 deletions test/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ run_test()
[[ ${VERBOSE+true} ]] && echo "$test_name: finished: ok ($((SECONDS-start))s)" || echo "ok ($((SECONDS-start))s)"
elif [[ $ret -eq 240 ]] ; then
[[ "${VERBOSE+true}" ]] && echo "$test_name: finished: skipped ($((SECONDS-start))s)" || echo "skipped ($((SECONDS-start))s)"
ret=0
elif [[ ${VERBOSE+true} ]] ; then
echo "$test_name: finished: FAIL (exit $ret, $((SECONDS-start))s)"
ret=1
Expand All @@ -94,7 +93,6 @@ run_test()
[[ ${VERBOSE+true} ]] && echo "$test_name: finished: ok ($((SECONDS-start))s)" || echo "ok ($((SECONDS-start))s)"
elif [[ $ret -eq 240 ]] ; then
[[ ${VERBOSE+true} ]] && echo "$test_name: finished: skipped ($((SECONDS-start))s)" || echo "skipped ($((SECONDS-start))s)"
ret=0
elif [[ ${VERBOSE+true} ]] ; then
echo "$test_name: finished: FAIL ($((SECONDS-start))s)"
ret=1
Expand All @@ -112,6 +110,43 @@ run_test()

cat "$LOGFILE" >> log.txt
rm "$LOGFILE"
return $ret # 240 if the test was skipped
}

# Run test and treat "skipped" as success
run_test_plain()
{
local ret
run_test "$1"
ret=$?
[[ $ret -ne 240 ]] || ret=0
return $ret
}

# On GitHub Actions, collect the output of each test and emit it atomically as
# a collapsible group. The lock keeps parallel tests from interleaving.
run_test_grouped()
{
local ret out=$(mktemp) start=$SECONDS
run_test "$1" > "$out" 2>&1
ret=$?
local duration=$((SECONDS-start))
# Portable lock (flock is unreliable on MSYS): mkdir is atomic.
until mkdir "$GROUP_LOCK/lock" 2>/dev/null ; do sleep 0.1 ; done
{
if [[ $ret -eq 240 ]] ; then
echo "::group::⏭️ $1 (${duration}s)"
elif [[ $ret -ne 0 ]] ; then
echo "::group::❌ $1 (${duration}s)"
else
echo "::group::✅ $1 (${duration}s)"
fi
cat "$out"
echo "::endgroup::"
}
rmdir "$GROUP_LOCK/lock"
rm -f "$out"
[[ $ret -ne 240 ]] || ret=0
return $ret
}

Expand Down Expand Up @@ -278,11 +313,20 @@ if [[ -n "$RUN_BLACKBOX_PAT" ]] ; then
popd > /dev/null
fi

# Group output per test on GitHub Actions (only useful in verbose mode)
RUN_TEST=run_test_plain
if [[ ${GITHUB_ACTIONS:-} == true && ${VERBOSE+true} ]] ; then
RUN_TEST=run_test_grouped
export GROUP_LOCK="$(mktemp -d)"
trap 'rm -rf "$GROUP_LOCK" 2>/dev/null' EXIT
fi

# execute all tests, possibly in parallel
if [[ ${#RUN_TEST_NAMES[@]} -eq 0 ]] ; then
: # No tests matched
elif [[ ${RUN_JOBS:-} != 1 ]] ; then
export -f run_test print_verbose
export -f run_test run_test_plain run_test_grouped print_verbose
export RUN_TEST
export RUN_PYTHON3
export RUN_PYTHON3_COV
export TEST_ENVIRONMENT
Expand All @@ -291,11 +335,11 @@ elif [[ ${RUN_JOBS:-} != 1 ]] ; then
# buffering. This prevents the output from being interleaced.
echo "${RUN_TEST_NAMES[@]}" \
| xargs -P ${RUN_JOBS:-$(nproc)} -n 1 \
bash -o pipefail -c 'run_test "$@" | stdbuf -oL sed -e ""' bash \
bash -o pipefail -c '$RUN_TEST "$@" | stdbuf -oL sed -e ""' bash \
|| : $((FAILED+=$?))
else
for i in "${RUN_TEST_NAMES[@]}" ; do
if ! run_test "$i" ; then
if ! $RUN_TEST "$i" ; then
: $((FAILED++))
fi
done
Expand Down
30 changes: 27 additions & 3 deletions test/test-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ file_url()
fi
}

# Running inside the nono sandbox?
is_nono()
{
[[ -n "${NONO_CAP_FILE:-}" ]]
}

cleanup()
{
rm -rf work dev .bob-* "$@"
Expand All @@ -104,16 +110,34 @@ cleanup()
# and "no global defaults" debug switches.
run_bob()
{
local args=("$@")

# The nono sandbox does not support nested unprivileged containers. The
# "build" command uses the sandbox by default. Disable it unless the test
# explicitly asks for a sandbox mode.
if is_nono ; then
local a has_mode=0 is_build=0
for a in "$@" ; do
[[ "$a" == *-sandbox ]] && has_mode=1
done
# Find the command. Skip global "-C DIR" option.
local pos=0
[[ "$1" == -C ]] && pos=2
[[ "${args[$pos]:-}" == build || "${args[$pos]:-}" == project ]] && is_build=1
# Options must precede generator arguments of "project"
[[ $is_build -eq 1 && $has_mode -eq 0 ]] && args=("${args[@]:0:pos+1}" --no-sandbox "${args[@]:pos+1}")
fi

if is_win32 ; then
python "$BOB_ROOT/bob" --debug=pkgck,ngd,audit "$@"
python "$BOB_ROOT/bob" --debug=pkgck,ngd,audit "${args[@]}"
else
"$BOB_ROOT/bob" --debug=pkgck,ngd,audit "$@"
"$BOB_ROOT/bob" --debug=pkgck,ngd,audit "${args[@]}"
fi
}

export_run_bob()
{
export -f run_bob is_win32
export -f run_bob is_win32 is_nono
export BOB_ROOT TEST_ENVIRONMENT PYTHONPATH
}

Expand Down
16 changes: 12 additions & 4 deletions test/unit/test_jenkins_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@
import subprocess
import sys

from bob.invoker import getSandboxHelperPath
from bob.utils import removePath

def _sandboxWorks():
# Nested containers are not available e.g. inside the nono sandbox.
if sys.platform != "linux":
return False
return subprocess.run([getSandboxHelperPath(), "-C"], stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL).returncode == 0

class JenkinsBuilds(JenkinsTests):
OPTIONS = ""

Expand Down Expand Up @@ -556,7 +564,7 @@ def testBuild(self):
class JenkinsSandboxBuildDisabled(JenkinsSandboxBuilds, TestCase):
pass

@skipUnless(sys.platform == "linux", "Sandbox requires Linux")
@skipUnless(_sandboxWorks(), "Sandbox requires working containers")
class JenkinsSandboxBuildPartial(JenkinsSandboxBuilds, TestCase):
OPTIONS = "--sandbox"
OUTSIDE_ISOLATED=0
Expand All @@ -565,7 +573,7 @@ class JenkinsSandboxBuildPartial(JenkinsSandboxBuilds, TestCase):
INSIDE_STABLE_PATH=1
INSIDE_IMAGE_USED=1

@skipUnless(sys.platform == "linux", "Sandbox requires Linux")
@skipUnless(_sandboxWorks(), "Sandbox requires working containers")
class JenkinsSandboxBuildSlim(JenkinsSandboxBuilds, TestCase):
OPTIONS = "--slim-sandbox"
OUTSIDE_ISOLATED=1
Expand All @@ -574,7 +582,7 @@ class JenkinsSandboxBuildSlim(JenkinsSandboxBuilds, TestCase):
INSIDE_STABLE_PATH=0
INSIDE_IMAGE_USED=0

@skipUnless(sys.platform == "linux", "Sandbox requires Linux")
@skipUnless(_sandboxWorks(), "Sandbox requires working containers")
class JenkinsSandboxBuildDev(JenkinsSandboxBuilds, TestCase):
OPTIONS = "--dev-sandbox"
OUTSIDE_ISOLATED=1
Expand All @@ -583,7 +591,7 @@ class JenkinsSandboxBuildDev(JenkinsSandboxBuilds, TestCase):
INSIDE_STABLE_PATH=0
INSIDE_IMAGE_USED=1

@skipUnless(sys.platform == "linux", "Sandbox requires Linux")
@skipUnless(_sandboxWorks(), "Sandbox requires working containers")
class JenkinsSandboxBuildStrict(JenkinsSandboxBuilds, TestCase):
OPTIONS = "--strict-sandbox"
OUTSIDE_ISOLATED=1
Expand Down