Files
connector-popos/smoketest/lib/runner.sh
T
davidandClaude Opus 5.5 fef73e8b5b Test the agent sandbox from inside; keep srt's settings out of /tmp
Ports CoreDesktop's security checks (05b13b2, d5925fa, 53c6c8b) as
smoketest/scenarios/80-security.sh:

- The sandbox: a fake opencode, Hermes and Cline Desktop, run through
  sandbox/bin's wrappers, can't read secrets or an SMB password through
  sudo, write outside their project (home, ~/.bashrc, ~/.local/bin,
  systemd units, autostart, the connector, its sandbox config or yours,
  the settings srt starts with, their project's git hooks and config),
  reach domains, LAN addresses or loopback servers that aren't allowed,
  or see other processes or the session's D-Bus. Each check also runs
  outside, so a pass means the sandbox blocked it.
- Root: what configure installs for root to run or read is root's alone
  and names no home folder, and with a security key and fingerprint set
  up, a password user's sudo still takes the password and only it.
- The install path: every hop from federated.sh/pop is HTTPS, and plain
  HTTP doesn't serve the script.

CoreDesktop's network exposure checks (ufw, Docker, sshd) don't apply.

Writing it found that sandbox/agent put the settings srt starts with in
/tmp/federated-sandbox when XDG_RUNTIME_DIR wasn't set, and every sandbox
can write /tmp, so an agent could put its own settings, or a link, where
the next one's go. They're now always in /run/user/<uid>, which no
sandbox can write, and it won't start without it.

The smoketest's runner gives each scenario what a login does: USER,
/run/user/<uid>, and the session bus in it, as on Pop!_OS.

PLAN.md: CoreDesktop compared at 4e9b962, everything that applies ported.
Neither lint nor the Docker smoketest has run on these ports yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 19:14:55 -07:00

95 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
#
# Purpose : Run one smoketest scenario inside the container (smoketest/run
# starts this). Prints ok, FAIL or skip for each check, and exits 1
# if any failed.
#
# Usage: runner.sh <scenario file>
#
# A scenario sets DESCRIPTION and TIER and defines `scenario`, which calls the
# checks below. It runs with what configure gives items (CONNECTOR, CONF_DIR,
# confirm...), answering yes to every question, so it can source items and
# call their functions. A desktop session's D-Bus and an unlocked keyring are
# started first, as COSMIC starts them at login.
CONNECTOR="$HOME/connector"
CONF_DIR="$HOME/.config/federated-connector"
export CONNECTOR CONF_DIR
RED=$'\033[31m' GREEN=$'\033[32m' YELLOW=$'\033[33m' RESET=$'\033[0m'
FAILURES=0
# configure's questions, answered yes
confirm() { echo "$1 [y/N] y"; return 0; }
confirm_yes() { echo "$1 [Y/n] y"; return 0; }
# check <description> <command...>: ok if the command succeeds
check() {
local description="$1" output
shift
if output="$("$@" 2>&1)"; then
echo "${GREEN}ok$RESET $description"
else
echo "${RED}FAIL$RESET $description"
[ -n "$output" ] && printf '%s\n' "$output" | tail -n 15 | sed 's/^/ /'
FAILURES=$((FAILURES + 1))
fi
}
# check_not <description> <command...>: ok if the command fails
check_not() {
local description="$1"
shift
if "$@" > /dev/null 2>&1; then
echo "${RED}FAIL$RESET $description (it succeeded)"
FAILURES=$((FAILURES + 1))
else
echo "${GREEN}ok$RESET $description"
fi
}
# check_eq <description> <expected> <actual>
check_eq() {
if [ "$2" = "$3" ]; then
echo "${GREEN}ok$RESET $1"
else
echo "${RED}FAIL$RESET $1"
echo " expected: $2"
echo " got: $3"
FAILURES=$((FAILURES + 1))
fi
}
skip() {
echo "${YELLOW}skip$RESET $1"
}
step() {
echo "-- $*"
}
# What a login gives: USER (Docker doesn't set it), the runtime folder systemd
# makes, the session D-Bus in it, as on Pop!_OS, and the keyring
export USER="${USER:-$(id -un)}"
export XDG_RUNTIME_DIR="/run/user/$UID"
sudo install -d -m 700 -o "$UID" -g "$(id -g)" "$XDG_RUNTIME_DIR"
export DBUS_SESSION_BUS_ADDRESS="unix:path=$XDG_RUNTIME_DIR/bus"
dbus-daemon --session --address="$DBUS_SESSION_BUS_ADDRESS" --fork --nopidfile > /dev/null
echo -n smoketest | gnome-keyring-daemon --unlock --components=secrets > /dev/null
export PATH="$HOME/.local/bin:$PATH"
cd "$HOME" || exit 1
source "$CONNECTOR/configure.d/lib/packages.sh"
source "$CONNECTOR/configure.d/lib/agents.sh"
# shellcheck disable=SC1090
source "$1" || { echo "Couldn't read $1"; exit 1; }
echo "$DESCRIPTION"
echo "($(. /etc/os-release && echo "$PRETTY_NAME"), $(uname -m))"
scenario
echo
if [ $FAILURES -eq 0 ]; then
echo "${GREEN}All checks passed.$RESET"
else
echo "${RED}$FAILURES check(s) failed.$RESET"
exit 1
fi