#!/bin/sh # krang -- root-only integration test. # # Copyright (c) 2026 Konrad Lother # License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree. # # This is the part the offline suite cannot prove: debootstrap, mount namespace, # chroot, uid drop, Landlock, seccomp and the event log ownership. It does not # start the autonomous daemon or a provider; it runs --sandbox-test, one # scripted turn that asks `id -u` and tries `mount(2)` inside the cage. # # sudo tests/root-integration.sh # # Environment: # KRANG_TEST_DIR work directory (default: mktemp -d /var/tmp/...) # KRANG_TEST_ROOTFS reuse an already prepared rootfs, skip debootstrap # KRANG_KEEP=1 keep the work directory for inspection set -eu if [ "$(id -u)" != "0" ]; then echo "root-integration: must run as root (sudo tests/root-integration.sh)" >&2 exit 1 fi [ -x ./krang ] || { echo "root-integration: build ./krang first (make)" >&2; exit 1; } if [ -n "${KRANG_TEST_ROOTFS:-}" ]; then ROOTFS=$KRANG_TEST_ROOTFS else if ! command -v debootstrap >/dev/null 2>&1 && [ ! -x /usr/sbin/debootstrap ]; then echo "root-integration: debootstrap is not installed" >&2 exit 1 fi fi WORK=${KRANG_TEST_DIR:-$(mktemp -d /var/tmp/krang-root.XXXXXX)} KRANG_ROOT=$(cd "$(dirname "$0")/.." && pwd) SPLINTER=${SPLINTER:-$KRANG_ROOT/../splinter} PLUGIN=$SPLINTER/plugins/clock/clock.so test -r "$PLUGIN" || { echo "root-integration: missing $PLUGIN (build ../splinter first)" >&2 exit 1 } STATE=$WORK/state WORKSPACE=$WORK/workspace CONF=$WORK/krang.conf if [ -z "${KRANG_TEST_ROOTFS:-}" ]; then ROOTFS=$WORK/rootfs fi mkdir -p "$STATE" "$WORKSPACE" cleanup() { if [ "${KRANG_KEEP:-0}" = "1" ]; then echo "root-integration: kept $WORK" return fi rm -rf "$WORK" } trap cleanup EXIT INT TERM cat >"$CONF" <&2 exit 1 } fi echo "== sandbox-test (unshare, chroot, uid drop, Landlock, seccomp)" ./krang --sandbox-test --config "$CONF" EVENTS=$STATE/events.jsonl SESSIONS=$STATE/sessions/krang.jsonl test -s "$EVENTS" test -s "$SESSIONS" echo "== event log ownership" EV_UID=$(stat -c %u "$EVENTS") EV_MODE=$(stat -c %a "$EVENTS") echo "events: uid=$EV_UID mode=$EV_MODE" [ "$EV_UID" = "0" ] || { echo "event log is not root-owned" >&2; exit 1; } [ "$EV_MODE" = "600" ] || { echo "event log mode is not 600" >&2; exit 1; } echo "== session ownership" S_UID=$(stat -c %u "$SESSIONS") echo "session: uid=$S_UID" [ "$S_UID" = "65534" ] || { echo "session is not owned by the sandbox uid" >&2; exit 1; } echo "== tool observations" grep -q '"name":"clock"' "$EVENTS" || { echo "the clock plugin was not loaded" >&2 exit 1 } grep -q '65534' "$EVENTS" || { echo "id -u did not report 65534" >&2; exit 1; } grep -q 'mount-denied\|Operation not permitted\|Permission denied' "$EVENTS" || { echo "mount was not denied" >&2 exit 1 } grep -q 'sandbox-test-ok' "$EVENTS" || { echo "answer missing" >&2; exit 1; } if command -v setpriv >/dev/null 2>&1; then if setpriv --reuid=65534 --regid=65534 --clear-groups \ test -r "$EVENTS" 2>/dev/null; then echo "event log is readable by the sandbox uid" >&2 exit 1 fi echo "== sandbox uid cannot read the event log: ok" fi echo "== root-integration: ok"