Let Hermes' gateway reach only a Matrix server you've allowed
Ports CoreDesktop's e991264, 05b13b2 and d974b91. configure agents allowed Hermes' gateway the host in MATRIX_HOMESERVER from ~/.hermes/.env, which Hermes can write from inside its sandbox, so it could open the way out to any host it chose. The allowed server is now in ~/.config/federated-connector/sandbox/hermes.json, which no sandbox can write. configure hermes is to do while Hermes names a server you haven't allowed, and asks about only that; configure agents says so. Only a plain host name counts, so it can't be a wildcard or carry escape codes into the question. sandbox/agent no longer reads FEDERATED_SANDBOX_DOMAINS. The server an old drop-in allows is carried over, read from the drop-in itself, when the gateway starts and when configure agents rewrites it, so a working gateway keeps working. Agents could read ~/.config/federated-connector, which has the Core's domain and user name; base.json now hides it. edit_json treats an empty settings file like a missing one: jq reads no JSON from an empty file and writes nothing back, so configure ai-servers said a server was added while the sandbox still blocked it. agent_path joined the last folder on PATH to ~/.local/bin, so an agent there wasn't found when ~/.local/bin wasn't on PATH (e.g. in a service). Smoketest: 55-hermes-homeserver, and 50-sandbox checks that an agent can't read the connector's settings. PLAN.md drops what's done. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+2
-1
@@ -32,7 +32,8 @@ Each run writes its logs to `smoketest/results/<time>/`, one per scenario, and p
|
||||
| `20-goa` | `goa-account` with Online Accounts 3.50. It adds Nextcloud and email (quoting a name), adding again changes nothing, and it pauses email and ends the pause. Test a Core takes an unreachable mail server as a sign-in failure, not a wrong password. Removing leaves nothing in the keyring. |
|
||||
| `30-core-local` | Superpanel's entry, Element's config (in ~/.config, or the Flatpak's folder), and the COSMIC Files sidebar. The sidebar check reads and writes ron's pretty format with network places and escaped names, keeps COSMIC Files' defaults, and leaves a file it can't read alone. Then davfs2's secret, read back. |
|
||||
| `40-backup` | restic and rclone from apt, with `rclone serve webdav` standing in for Nextcloud and the secrets in the keyring. `system/backup` makes a snapshot that leaves out caches and the install, a file restores from it, and without the passphrase it fails. |
|
||||
| `50-sandbox` *(all)* | Node.js and srt download and install. A stand-in agent can't read `~/.ssh` or write outside its project, reaches allowed sites only, and won't start in your home folder. A new bash finds the sandboxed command first. |
|
||||
| `50-sandbox` *(all)* | Node.js and srt download and install. A stand-in agent can't read `~/.ssh` or Federated Connector's settings, or write outside its project, reaches allowed sites only, and won't start in your home folder. A new bash finds the sandboxed command first. |
|
||||
| `55-hermes-homeserver` | Hermes' gateway reaches only a Matrix server you've allowed: a server in Hermes' settings is to do until `configure hermes` allows it, a wildcard or escape codes never count, and `configure agents` carries over the server an old drop-in allowed. `edit_json` fills an empty file from its default. |
|
||||
| `60-packages` *(all)* | davfs2 installs with `mount.davfs` setuid, and `davfs2_ready` fixes one installed without. sshfs' `fusermount3` and smbclient are where `configure storage` expects them, and so is GTK's CUPS print backend. mise installs from its apt repository and a new bash has it. |
|
||||
|
||||
## What still needs Pop!_OS
|
||||
|
||||
@@ -24,6 +24,7 @@ scenario() {
|
||||
#!/bin/bash
|
||||
case "$1" in
|
||||
read-ssh) cat ~/.ssh/id_test ;;
|
||||
read-settings) cat ~/.config/federated-connector/core.conf ;;
|
||||
write-home) echo x > ~/outside ;;
|
||||
write-here) echo x > ./inside ;;
|
||||
fetch) curl -sf -o /dev/null --max-time 20 "$2" ;;
|
||||
@@ -31,7 +32,11 @@ esac
|
||||
AGENT
|
||||
chmod +x "$HOME/.local/bin/opencode"
|
||||
cd "$project" || return
|
||||
mkdir -p "$HOME/.config/federated-connector"
|
||||
echo 'CORE_DOMAIN=smoke.invalid' > "$HOME/.config/federated-connector/core.conf"
|
||||
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
|
||||
check_not "it can't write outside its project" "$SANDBOX_BIN/opencode" write-home
|
||||
check "it can write in its project" "$SANDBOX_BIN/opencode" write-here
|
||||
check "it reaches an allowed site" "$SANDBOX_BIN/opencode" fetch https://registry.npmjs.org/
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
# shellcheck shell=bash
|
||||
# Scenarios set what the runner and items read
|
||||
# shellcheck disable=SC2034
|
||||
DESCRIPTION="Hermes' gateway reaches only a Matrix server you've allowed; edit_json and empty files"
|
||||
TIER=quick
|
||||
|
||||
scenario() {
|
||||
local out
|
||||
source "$CONNECTOR/configure.d/30-agents.sh"
|
||||
source "$CONNECTOR/configure.d/lib/json.sh"
|
||||
mkdir -p "$HOME/.hermes" "$(dirname "$HERMES_GATEWAY_UNIT")"
|
||||
|
||||
step "edit_json"
|
||||
mkdir -p "$CONF_DIR/sandbox"
|
||||
: > "$CONF_DIR/sandbox/test.json"
|
||||
check "it edits an empty file" edit_json "$CONF_DIR/sandbox/test.json" '{}' '.a = 1'
|
||||
check_eq "from its default" 1 "$(jq .a "$CONF_DIR/sandbox/test.json")"
|
||||
rm -f "$CONF_DIR/sandbox/test.json"
|
||||
|
||||
step "What Hermes' settings name"
|
||||
echo 'MATRIX_HOMESERVER=https://matrix.smoke.invalid:8448/' > "$HERMES_ENV"
|
||||
check_eq "the host in MATRIX_HOMESERVER" matrix.smoke.invalid "$(hermes_homeserver)"
|
||||
echo 'MATRIX_HOMESERVER=https://*.smoke.invalid' > "$HERMES_ENV"
|
||||
check_eq "not a wildcard" "" "$(hermes_homeserver)"
|
||||
printf 'MATRIX_HOMESERVER=https://evil\033[2Jhost\n' > "$HERMES_ENV"
|
||||
check_eq "not escape codes" "" "$(hermes_homeserver)"
|
||||
|
||||
step "configure hermes asks before it's reached"
|
||||
source "$CONNECTOR/configure.d/33-hermes.sh"
|
||||
echo 'MATRIX_HOMESERVER=https://matrix.smoke.invalid' > "$HERMES_ENV"
|
||||
echo 'OPENROUTER_API_KEY=x' >> "$HERMES_ENV"
|
||||
check_not "a server not allowed yet isn't" hermes_homeserver_allowed matrix.smoke.invalid
|
||||
check_eq "it's to do for that server" matrix.smoke.invalid "$(pending_homeserver)"
|
||||
check_not "Hermes is to do" is_configured
|
||||
check "run_configure asks only about the server" run_configure
|
||||
check "the server is allowed" hermes_homeserver_allowed matrix.smoke.invalid
|
||||
check "Hermes is done" is_configured
|
||||
echo 'MATRIX_HOMESERVER=https://other.smoke.invalid' > "$HERMES_ENV"
|
||||
check_not "a server Hermes names later isn't allowed" hermes_homeserver_allowed other.smoke.invalid
|
||||
|
||||
step "The gateway's drop-in"
|
||||
# No systemd user manager in a container
|
||||
systemctl() { :; }
|
||||
rm -f "$HERMES_SANDBOX_CONF"
|
||||
touch "$HERMES_GATEWAY_UNIT"
|
||||
mkdir -p "$(dirname "$HERMES_GATEWAY_DROPIN")"
|
||||
printf '[Service]\nEnvironment="FEDERATED_SANDBOX_DOMAINS=matrix.smoke.invalid"\nExecStart=\nExecStart=x\n' > "$HERMES_GATEWAY_DROPIN"
|
||||
check_not "an old drop-in isn't ok" gateway_ok
|
||||
out="$(sandbox_gateway 2>&1)"
|
||||
check "the server an old drop-in allowed is carried over" hermes_homeserver_allowed matrix.smoke.invalid
|
||||
check "the new drop-in is ok" gateway_ok
|
||||
check_not "it allows no domains itself" grep -q FEDERATED_SANDBOX_DOMAINS "$HERMES_GATEWAY_DROPIN"
|
||||
check "it says the server Hermes names now needs allowing" grep -q "other.smoke.invalid.*configure hermes" <<< "$out"
|
||||
printf '[Service]\nEnvironment="FEDERATED_SANDBOX_DOMAINS=*"\n' > "$HERMES_GATEWAY_DROPIN"
|
||||
rm -f "$HERMES_SANDBOX_CONF"
|
||||
hermes_carry_over_homeserver
|
||||
check_not "a wildcard isn't carried over" test -s "$HERMES_SANDBOX_CONF"
|
||||
rm -rf "$HERMES_GATEWAY_UNIT" "$HERMES_GATEWAY_UNIT.d" "$HOME/.hermes"
|
||||
}
|
||||
Reference in New Issue
Block a user