diff --git a/PLAN.md b/PLAN.md index e1b6c9e..f5dac87 100644 --- a/PLAN.md +++ b/PLAN.md @@ -61,9 +61,18 @@ Not ported, and why: ## Pop!_OS-specific -- [ ] `make lint` and `smoketest/run --tier all` haven't run since the ports - from CoreDesktop at `4e9b962`: they were written on a machine without - shellcheck or Docker. The new scenarios' quick checks were run by hand; - `50-sandbox` and `80-security` (srt, PAM) never have been. -- [ ] The manual checks in [TEST.md](TEST.md) on a real Pop!_OS 24.04 machine, +- [ ] Pin srt. `configure.d/lib/tools.sh` installs the latest + `@anthropic-ai/sandbox-runtime`, so a new release reaches every computer + untested. One already broke opencode's sandbox: srt's Unix socket filter + needs a user namespace inside bubblewrap, which Pop!_OS' AppArmor + (`bwrap-userns-restrict`) denies. opencode now allows all Unix sockets + and hides their paths instead, as Hermes and Cline Desktop do. Pin a + version the smoketest passed with, and move the pin only after + `smoketest/run 50 80` passes on the new one. +- [ ] Start the real opencode in its sandbox on Pop!_OS, to check it needs no + socket the new `denyRead` list hides. Only a stand-in has run so far. +- [ ] The development machine runs Pop!_OS 26.04, but the smoketest still builds on Ubuntu + 24.04 and smoketest/README.md says 24.04. Decide which release the + connector supports, and test on it. +- [ ] The manual checks in [TEST.md](TEST.md) on a real Pop!_OS machine, against a real Core. None have been done yet. diff --git a/TEST.md b/TEST.md index 8223916..77b79f8 100644 --- a/TEST.md +++ b/TEST.md @@ -10,6 +10,12 @@ that cover what changed, and all of them before a release is announced. ## Automated tests +They need shellcheck and Docker, which the connector doesn't install. Once: + +``` +sudo apt install shellcheck docker.io && sudo usermod -aG docker $USER # then log in again +``` + ``` make lint # shellcheck, and the Python compiles smoketest/run # the quick scenarios diff --git a/configure.d/30-agents.sh b/configure.d/30-agents.sh index beeccb8..5ef96a1 100644 --- a/configure.d/30-agents.sh +++ b/configure.d/30-agents.sh @@ -115,9 +115,9 @@ OLD_NOTIFY_DONE="notify-send 'Claude Code' 'Task completed'" # Settings written before claude-notify ran notify-send itself, so clicking # did nothing: true while either of those two hooks is still there old_claude_notifications() { - jq -e --arg input "$OLD_NOTIFY_INPUT" --arg done "$OLD_NOTIFY_DONE" \ + jq -e --arg input "$OLD_NOTIFY_INPUT" --arg completed "$OLD_NOTIFY_DONE" \ '[.hooks.Notification[]?.hooks[]?, .hooks.Stop[]?.hooks[]? | objects | .command] - | any(. == $input or . == $done)' "$CLAUDE_SETTINGS" &> /dev/null + | any(. == $input or . == $completed)' "$CLAUDE_SETTINGS" &> /dev/null } # Your own settings are left alone: the hooks are added only if you have no diff --git a/sandbox/config/opencode.json b/sandbox/config/opencode.json index d976b2a..6f1575e 100644 --- a/sandbox/config/opencode.json +++ b/sandbox/config/opencode.json @@ -4,9 +4,22 @@ "opencode.ai", "*.opencode.ai", "models.dev" - ] + ], + "allowAllUnixSockets": true }, "filesystem": { + "denyRead": [ + "/run/user", + "/run/dbus", + "/run/docker.sock", + "/run/podman", + "/run/tailscale", + "/run/ssh-unix-local", + "/tmp/.X11-unix", + "/tmp/tmux-*", + "/tmp/ssh-*", + "/tmp/*/SingletonSocket" + ], "allowRead": [ "~/.config/opencode", "~/.local/share/opencode" diff --git a/smoketest/scenarios/50-sandbox.sh b/smoketest/scenarios/50-sandbox.sh index 2edf082..f7bb902 100644 --- a/smoketest/scenarios/50-sandbox.sh +++ b/smoketest/scenarios/50-sandbox.sh @@ -23,6 +23,7 @@ scenario() { cat > "$HOME/.local/bin/opencode" << 'AGENT' #!/bin/bash case "$1" in + started) true ;; read-ssh) cat ~/.ssh/id_test ;; read-settings) cat ~/.config/federated-connector/core.conf ;; write-home) echo x > ~/outside ;; @@ -34,6 +35,9 @@ AGENT cd "$project" || return mkdir -p "$HOME/.config/federated-connector" echo 'CORE_DOMAIN=smoke.invalid' > "$HOME/.config/federated-connector/core.conf" + # Without this, the checks that something fails would pass if the sandbox + # itself didn't start + check "its sandbox starts" "$SANDBOX_BIN/opencode" started check_not "it can't read ~/.ssh" "$SANDBOX_BIN/opencode" read-ssh check "unsandboxed, Federated Connector's settings are readable" "$SANDBOX_BIN/unsandboxed" opencode read-settings check_not "it can't read Federated Connector's settings" "$SANDBOX_BIN/opencode" read-settings diff --git a/smoketest/scenarios/80-security.sh b/smoketest/scenarios/80-security.sh index e242bea..ed53625 100644 --- a/smoketest/scenarios/80-security.sh +++ b/smoketest/scenarios/80-security.sh @@ -18,7 +18,7 @@ PRIVILEGED=1 # runs it exactly as it would run opencode, Hermes or Cline Desktop: same # config, same srt, same proxy. -AGENTS=(opencode hermes cline-desktop) +FAKE_AGENTS=(opencode hermes cline-desktop) FAKE_BIN="$HOME/smoketest-agents" # Where opencode and Hermes are started; Cline Desktop always starts in ~/Projects PROJECT="$HOME/Projects/smoketest-project" @@ -84,7 +84,7 @@ outside() { blocked() { local agent check "outside the sandbox: $1" outside "$2" - for agent in "${AGENTS[@]}"; do + for agent in "${FAKE_AGENTS[@]}"; do check "$agent: $1" fails_in "$agent" "$2" done } @@ -105,7 +105,7 @@ write_stays_in() { write_blocked() { local agent check "outside the sandbox: $1" outside "[ -w \"\$(dirname $2)\" ] && { [ ! -e $2 ] || [ -w $2 ]; }" - for agent in "${AGENTS[@]}"; do + for agent in "${FAKE_AGENTS[@]}"; do check "$agent: $1" write_stays_in "$agent" "$2" "smoketest-escape-$agent" done } @@ -118,7 +118,7 @@ setup_sandbox() { mkdir -p "$FAKE_BIN" "$PROJECT" "$HOME/smoketest-other" "$HOME/.local/bin" \ "$HOME/.config/systemd/user" "$HOME/.config/autostart" "$(dirname "$USER_SANDBOX_CONF")" - for agent in "${AGENTS[@]}"; do + for agent in "${FAKE_AGENTS[@]}"; do printf '#!/bin/bash\nexec bash "$@"\n' > "$FAKE_BIN/$agent" chmod +x "$FAKE_BIN/$agent" done @@ -155,7 +155,7 @@ sandbox_checks() { step "The sandbox: what agents must be able to do, or the rest proves nothing" setup_sandbox lan="http://$LAN_IP" - for agent in "${AGENTS[@]}"; do + for agent in "${FAKE_AGENTS[@]}"; do check "$agent: writes in the folder it started in" works_in "$agent" 'echo x > ./smoketest-probe && rm ./smoketest-probe' check "$agent: writes in /tmp" works_in "$agent" 'echo x > /tmp/smoketest-probe-$$ && rm /tmp/smoketest-probe-$$' check "$agent: reaches an allowed domain through its proxy" works_in "$agent" 'curl -sf -o /dev/null -m 20 https://github.com/' @@ -197,7 +197,7 @@ sandbox_checks() { source "$CONNECTOR/configure.d/lib/json.sh" check "allow one LAN server, as configure ai-servers does" \ edit_json "$USER_SANDBOX_CONF" '{}' --arg s "$LAN_IP:$LAN_PORT" '.network.allowedDomains += [$s]' - for agent in "${AGENTS[@]}"; do + for agent in "${FAKE_AGENTS[@]}"; do check "$agent: reaches the allowed LAN server" works_in "$agent" "curl -sf -m 10 $lan:$LAN_PORT/" done blocked "reaches another port on the allowed LAN server" "curl -sf -m 10 $lan:$LAN_PORT_OTHER/"