Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Installer: stop on the sandbox checks that matter, warn on five; fetch helpers from the installed version's tag

milind-soni7d1494e5c05c
diff --git a/apps/docs/content/docs/self-hosting/deploy-vps.mdx b/apps/docs/content/docs/self-hosting/deploy-vps.mdx
index 5b6ba003ea..1ddc7c84fc 100644
--- a/apps/docs/content/docs/self-hosting/deploy-vps.mdx
+++ b/apps/docs/content/docs/self-hosting/deploy-vps.mdx
@@ -54,11 +54,13 @@ If Docker is missing, the installer asks before installing it with Docker's offi
| `data/` | everything MausBot stores: chats, bots, engine sign-ins, paired devices. Never touched once it exists |
| `caddy/` | the HTTPS certificates |
| `update.sh` | the update command, once this repository has it (see below) |
-| `compose.box.yaml`, `box/` | the sandbox's settings and the files that prepare the server for it, as this repository has them |
+| `compose.box.yaml`, `box/` | the sandbox's settings and the files that prepare the server for it |
+
+`update.sh` and the sandbox's files are this repository's own, taken from the tag of the version being installed so they match it, and from `main` only when that tag does not have them. The installer says which it used.
It runs the newest release, pinned by its version; once a `stable` channel is published it follows that instead. It never runs `latest`, which follows every commit. It then waits until the server reports healthy and `https://maus.example.com` answers with a valid certificate, and prints the address.
-**The bots' sandbox.** A MausBot version with the hardened profile runs every bot in a sandbox, away from the server's settings, keys and other bots' files, and Docker's defaults do not let a container build one. For such a version the installer prepares the server (a seccomp profile in `/etc/mausbot` and an AppArmor profile in `/etc/apparmor.d`, the two the MausBot connector installs), starts the server with the four security settings in `compose.box.yaml` (no `--privileged`, no added capability), and then runs the server's own self-check, which among other things confirms that a bot cannot read `config.json`. If the check fails the installer says so and does not report success. For a version without the hardened profile it says the sandbox is not there yet; run the install command again after updating to one that has it. `--no-sandbox` skips all of this, for a server only you sign in to on a host without AppArmor.
+**The bots' sandbox.** A MausBot version with the hardened profile runs every bot in a sandbox, away from the server's settings, keys and other bots' files, and Docker's defaults do not let a container build one. For such a version the installer prepares the server (a seccomp profile in `/etc/mausbot` and an AppArmor profile in `/etc/apparmor.d`, the two the MausBot connector installs), starts the server with the four security settings in `compose.box.yaml` (no `--privileged`, no added capability), and then runs the server's own self-check, which among other things confirms that a bot cannot read `config.json`. If a check fails that means a bot could reach something it must not, or that bots would not work, the installer names it and does not report success; so does a self-check that gives no answer, or a check the installer has never heard of. Five checks that are about neither (the kernel keyring, the sandbox's host name, the CPU list, a hosting provider's address, and reaching the public internet) only print a note. For a version without the hardened profile it says the sandbox is not there yet; run the install command again after updating to one that has it. `--no-sandbox` skips all of this, for a server only you sign in to on a host without AppArmor.
**Sign in as the first admin** with a one-time link made on the server:
diff --git a/deploy/e2e/run.sh b/deploy/e2e/run.sh
index 3c6512ba5d..80f529ec84 100755
--- a/deploy/e2e/run.sh
+++ b/deploy/e2e/run.sh
@@ -92,9 +92,10 @@ if sudo grep -qx "COMPOSE_FILE=compose.yaml:compose.box.yaml" "$DIR/.env"; then
[ "$(sudo docker inspect -f '{{.AppArmorProfile}}' "$container")" = omb-home-narrow ] || fail "the server does not run under the sandbox's AppArmor profile"
[ "$(sudo docker inspect -f '{{.HostConfig.Privileged}} {{json .HostConfig.CapAdd}}' "$container")" = "false null" ] || fail "the server was given privileges"
(cd "$DIR" && sudo docker compose logs omb 2>&1) | grep -F "bot box: on (bubblewrap" || fail "the server did not start its bot box"
- checks=$(box_check) || fail "the sandbox self-check failed: $checks"
+ # The installer has already judged every result (it stops on all but a few named ones); here, the ones this is about.
+ checks=$(box_check || true)
printf '%s\n' "$checks" >"$OUT/box-check.json"
- jq -e '.box == "bwrap" and .failed == [] and .passed == .total and ([.results[] | select(.ok) | .id] | index("config-hidden") != null and index("messages-db-hidden") != null)' <<<"$checks" >/dev/null || fail "the sandbox does not hide config.json: $checks"
+ jq -e '.box == "bwrap" and ([.results[] | select(.ok) | .id] | index("config-hidden") != null and index("messages-db-hidden") != null)' <<<"$checks" >/dev/null || fail "the sandbox does not hide config.json: $checks"
# The check has teeth: with the data folder's cover taken away, config.json is readable and the check says so.
bound=$(box_check --mutate=bind-data || true)
jq -e '.failed | index("config-hidden") != null' <<<"$bound" >/dev/null || fail "the self-check did not notice an uncovered data folder: $bound"
diff --git a/deploy/install.sh b/deploy/install.sh
index ea8d614f13..2558b3b188 100755
--- a/deploy/install.sh
+++ b/deploy/install.sh
@@ -19,8 +19,16 @@ settings() {
RELEASES_URL=https://api.github.com/repos/milind-soni/OpenMausBot/releases/latest
ADMIN_URL="${MAUSBOT_ADMIN_URL:-https://cloud.openmausbot.com}"
SCRIPT_URL=https://raw.githubusercontent.com/milind-soni/OpenMausBot/main/deploy/install.sh
- # Where the files this installer places come from: this repository, or a copy of it (https://… or file:///…).
- SOURCE="${OMB_INSTALL_SOURCE:-https://raw.githubusercontent.com/milind-soni/OpenMausBot/main}"
+ # Where the files this installer places come from: this repository at the tag of the version it installs, and at
+ # main when that tag does not have them. OMB_INSTALL_SOURCE names one copy to use instead (https://… or file:///…).
+ REPOSITORY_FILES=https://raw.githubusercontent.com/milind-soni/OpenMausBot
+ SOURCE_ASKED="${OMB_INSTALL_SOURCE:-}"
+ SOURCE=""
+ SOURCE_NAME=""
+ # WARN-ONLY SANDBOX CHECKS. The self-check's results that do not stop an install when they fail: none of them lets a
+ # bot reach what it must not, or stops bots working. Every other check, and any check this list has never heard
+ # of, stops it. A result that carries its own "severity" says so itself and this list is not asked.
+ SANDBOX_WARN_ONLY="keyring-denied hostname-private cpu-list-readable fly-api-hidden egress-public-allowed"
SECCOMP=seccomp-omb-home.json
APPARMOR_PROFILE=omb-home-narrow
PROJECT=openmausbot
@@ -361,7 +369,7 @@ check_outbound() {
targets="https://ghcr.io/v2/ https://pkg-containers.githubusercontent.com/ https://registry-1.docker.io/v2/ https://auth.docker.io/ https://production.cloudflare.docker.com/ https://acme-v02.api.letsencrypt.org/directory"
if [ "$DOCKER_STATE" = missing ]; then targets="$targets https://get.docker.com/ https://download.docker.com/"; fi
if [ -n "$CODE" ]; then targets="$targets $ADMIN_URL/"; fi
- case "$SOURCE" in https://*) targets="$targets https://$(host_of "$SOURCE")/" ;; esac
+ case "${SOURCE_ASKED:-$REPOSITORY_FILES}" in https://*) targets="$targets https://$(host_of "${SOURCE_ASKED:-$REPOSITORY_FILES}")/" ;; esac
blocked=""
for url in $targets; do
reachable "$url" || blocked="$blocked $(host_of "$url")"
@@ -681,7 +689,7 @@ ENV
fi
}
-fetch() { # path-in-the-repository destination [mode]: 1 when it is not there
+fetch() { # path-in-the-repository destination [mode]: 1 when SOURCE does not have it
tmp_fetch=$(mktemp "$2.XXXXXX")
if curl -fsSL --max-time 60 "$SOURCE/$1" -o "$tmp_fetch" 2>/dev/null && [ -s "$tmp_fetch" ]; then
chmod "${3:-644}" "$tmp_fetch"
@@ -692,13 +700,43 @@ fetch() { # path-in-the-repository destination [mode]: 1 when it is not there
return 1
}
+# The version the downloaded image says it is, as the repository tags it (v1.2.3), or nothing.
+image_version() {
+ docker image inspect -f '{{index .Config.Labels "org.opencontainers.image.version"}}' "$IMAGE" 2>/dev/null |
+ sed -n 's/^v\{0,1\}\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\)$/v\1/p' | head -n 1
+}
+
+# Tries each place the repository's files may come from, in order: the copy that was asked
+# for and nothing else; or the tag of the installed version, then main. Leaves SOURCE_NAME saying which one had them.
+from_repository() { # what-to-fetch
+ if [ -n "$SOURCE_ASKED" ]; then
+ SOURCE=$SOURCE_ASKED
+ SOURCE_NAME=$SOURCE_ASKED
+ "$1"
+ return
+ fi
+ version=$(image_version || true)
+ if [ -n "$version" ]; then
+ SOURCE="$REPOSITORY_FILES/$version"
+ SOURCE_NAME="MausBot $version's own"
+ if "$1"; then return 0; fi
+ fi
+ SOURCE="$REPOSITORY_FILES/main"
+ SOURCE_NAME="the newest in the repository${version:+ ($version has none)}"
+ "$1"
+}
+
+fetch_update() {
+ fetch deploy/update.sh "$INSTALL_DIR/update.sh" 755
+}
+
# update.sh (deploy/update.sh) updates with a backup and a way back; it is this repository's file, placed as it is.
place_update() {
- fetch deploy/update.sh "$INSTALL_DIR/update.sh" 755 || true
+ if from_repository fetch_update; then note "update.sh is $SOURCE_NAME."; fi
}
# The sandbox's host preparation and Compose settings are this repository's own (deploy/box, connector/profiles),
-# fetched and used as they are. 1 when they are not published where SOURCE points.
+# fetched and used as they are, all four from the same place.
fetch_sandbox() {
mkdir -p "$INSTALL_DIR/box/profiles"
fetch deploy/box/prepare-host.sh "$INSTALL_DIR/box/prepare-host.sh" 755 &&
@@ -727,33 +765,67 @@ prepare_sandbox() {
note "This MausBot version has no bots' sandbox yet. Run this command again after updating to a version that has it."
return
fi
- if ! fetch_sandbox; then
- fail "The files that prepare this server for the bots' sandbox could not be downloaded from $SOURCE. Check this server's outbound HTTPS and run this again; or add --no-sandbox to install without the sandbox, on a server you alone sign in to."
+ if ! from_repository fetch_sandbox; then
+ fail "The files that prepare this server for the bots' sandbox could not be downloaded from ${SOURCE_ASKED:-$REPOSITORY_FILES}. Check this server's outbound HTTPS and run this again; or add --no-sandbox to install without the sandbox, on a server you alone sign in to."
fi
say "Preparing this server for the bots' sandbox..."
+ note "The sandbox's files are $SOURCE_NAME."
MAUSBOT_PROFILES_DIR="$INSTALL_DIR/box/profiles" sh "$INSTALL_DIR/box/prepare-host.sh" >/dev/null ||
fail "This server could not be prepared for the bots' sandbox (the reason is above). Fix that and run this again; or add --no-sandbox to install without the sandbox, on a server you alone sign in to."
set_env COMPOSE_FILE compose.yaml:compose.box.yaml
SANDBOX=on
}
-# The server's own self-check of the sandbox, as a bot meets it: among its checks, that config.json cannot be read.
+sandbox_field() { # result name: that field of one result of the self-check
+ printf '%s' "$1" | sed -n "s/.*\"$2\":\"\([^\"]*\)\".*/\1/p"
+}
+
+# The server's own self-check of the sandbox, as a bot meets it. A failed check stops the install unless it is one of
+# SANDBOX_WARN_ONLY (or says "severity":"warn" itself); a self-check that gives no answer stops it too.
check_sandbox_runs() {
[ "$SANDBOX" = on ] || return 0
say "Checking that the bots' sandbox holds..."
- report=$(compose exec -T omb node dist-server/bot-box/box-check.js --public=none 2>/dev/null | tr -d ' \n' || true)
+ see="See it with: cd $INSTALL_DIR && sudo docker compose exec omb node dist-server/bot-box/box-check.js --public=none and send us what it prints."
+ report=$(compose exec -T omb node dist-server/bot-box/box-check.js --public=none 2>/dev/null | tr -d '\n' || true)
case "$report" in
- *'"box":"bwrap"'*'"failed":[]'* | *'"failed":[]'*'"box":"bwrap"'*)
- case "$report" in
- *'"config-hidden"'*) say "The bots' sandbox is on: a bot cannot read the server's settings, keys or other bots' files." ;;
- *) fail "MausBot is running, but its sandbox self-check did not test that a bot cannot read the server's settings. Send us this line." ;;
- esac
- ;;
- *)
- failed=$(printf '%s' "$report" | sed -n 's/.*"failed":\[\([^]]*\)\].*/\1/p' | tr -d '"' | tr ',' ' ')
- fail "MausBot is running, but its bots' sandbox failed its self-check${failed:+ ($failed)}, so bots are not safely separated from the server. See it with: cd $INSTALL_DIR && sudo docker compose exec omb node dist-server/bot-box/box-check.js --public=none and send us what it prints."
- ;;
+ *'"box":"bwrap"'*'"results":[{'*) ;;
+ *) fail "MausBot is running, but its bots' sandbox gave no answer to its self-check, so bots may not be separated from the server. $see" ;;
esac
+ case "$report" in
+ *'"id":"config-hidden","ok":true'*) ;;
+ *) fail "MausBot is running, but its sandbox self-check did not show that a bot cannot read the server's settings (config-hidden), so bots are not safely separated from the server. $see" ;;
+ esac
+ stopping=""
+ set -f
+ old_ifs=$IFS
+ IFS='
+'
+ for result in $(printf '%s' "$report" | sed 's/},{/}\
+{/g' | grep '"ok":false' || true); do
+ IFS=$old_ifs
+ id=$(sandbox_field "$result" id)
+ detail=$(sandbox_field "$result" detail)
+ severity=$(sandbox_field "$result" severity)
+ if [ -z "$severity" ]; then
+ severity=must
+ case " $SANDBOX_WARN_ONLY " in *" $id "*) [ -z "$id" ] || severity=warn ;; esac
+ fi
+ if [ "$severity" = warn ]; then
+ note "The sandbox's self-check did not pass $id${detail:+ ($detail)}. Bots are still kept from the server's settings and from each other; tell us about it."
+ else
+ stopping="$stopping ${id:-an unnamed check}${detail:+ ($detail)},"
+ fi
+ done
+ IFS=$old_ifs
+ set +f
+ if [ -z "$stopping" ]; then
+ case "$report" in
+ *'"failed":[]'*) ;;
+ *) case "$report" in *'"ok":false'*) ;; *) stopping=" checks it did not name," ;; esac ;;
+ esac
+ fi
+ [ -z "$stopping" ] || fail "MausBot is running, but its bots' sandbox failed its self-check:${stopping%,}. Bots are not safely separated from the server. $see"
+ say "The bots' sandbox is on: a bot cannot read the server's settings, keys or other bots' files."
}
# A new data folder is handed to the user the image runs as. A folder that already exists is never touched.
diff --git a/docs/deploy-vps.md b/docs/deploy-vps.md
index 84cddc378f..f136205e49 100644
--- a/docs/deploy-vps.md
+++ b/docs/deploy-vps.md
@@ -46,11 +46,13 @@ If Docker is missing, the installer asks before installing it with Docker's offi
| `data/` | everything MausBot stores: chats, bots, engine sign-ins, paired devices. Never touched once it exists |
| `caddy/` | the HTTPS certificates |
| `update.sh` | the update command, once this repository has it (see below) |
-| `compose.box.yaml`, `box/` | the sandbox's settings and the files that prepare the server for it, as this repository has them |
+| `compose.box.yaml`, `box/` | the sandbox's settings and the files that prepare the server for it |
+
+`update.sh` and the sandbox's files are this repository's own, taken from the tag of the version being installed so they match it, and from `main` only when that tag does not have them. The installer says which it used.
It runs the newest release, pinned by its version; once a `stable` channel is published it follows that instead. It never runs `latest`, which follows every commit. It then waits until the server reports healthy and `https://maus.example.com` answers with a valid certificate, and prints the address.
-**The bots' sandbox.** A MausBot version with the hardened profile runs every bot in a sandbox, away from the server's settings, keys and other bots' files, and Docker's defaults do not let a container build one. For such a version the installer prepares the server (a seccomp profile in `/etc/mausbot` and an AppArmor profile in `/etc/apparmor.d`, the two the MausBot connector installs), starts the server with the four security settings in `compose.box.yaml` (no `--privileged`, no added capability), and then runs the server's own self-check, which among other things confirms that a bot cannot read `config.json`. If the check fails the installer says so and does not report success. For a version without the hardened profile it says the sandbox is not there yet; run the install command again after updating to one that has it. `--no-sandbox` skips all of this, for a server only you sign in to on a host without AppArmor.
+**The bots' sandbox.** A MausBot version with the hardened profile runs every bot in a sandbox, away from the server's settings, keys and other bots' files, and Docker's defaults do not let a container build one. For such a version the installer prepares the server (a seccomp profile in `/etc/mausbot` and an AppArmor profile in `/etc/apparmor.d`, the two the MausBot connector installs), starts the server with the four security settings in `compose.box.yaml` (no `--privileged`, no added capability), and then runs the server's own self-check, which among other things confirms that a bot cannot read `config.json`. If a check fails that means a bot could reach something it must not, or that bots would not work, the installer names it and does not report success; so does a self-check that gives no answer, or a check the installer has never heard of. Five checks that are about neither (the kernel keyring, the sandbox's host name, the CPU list, a hosting provider's address, and reaching the public internet) only print a note. For a version without the hardened profile it says the sandbox is not there yet; run the install command again after updating to one that has it. `--no-sandbox` skips all of this, for a server only you sign in to on a host without AppArmor.
**Sign in as the first admin** with a one-time link made on the server:
diff --git a/scripts/server-installer.test.ts b/scripts/server-installer.test.ts
index 66af1f3b8c..b2d0d29572 100644
--- a/scripts/server-installer.test.ts
+++ b/scripts/server-installer.test.ts
@@ -17,7 +17,8 @@ const TOKEN = "t0ken-of-the-registry";
const CODE = "ABCD-1234-EFGH";
const BOX_PASSED = '{"box":"bwrap","total":31,"passed":31,"failed":[],"results":[{"id":"config-hidden","ok":true},{"id":"messages-db-hidden","ok":true}]}';
const BOX_FAILED = '{"box":"bwrap","total":31,"passed":30,"failed":["config-hidden"],"results":[{"id":"config-hidden","ok":false}]}';
-const SOURCE = "https://raw.githubusercontent.com/milind-soni/OpenMausBot/main";
+const FILES = "https://raw.githubusercontent.com/milind-soni/OpenMausBot";
+const SOURCE = `${FILES}/v0.1.151`;
const REAL_TOOLS = ["sed", "awk", "grep", "cat", "head", "tail", "tr", "sort", "cut", "mkdir", "mktemp", "chmod", "chown", "mv", "rm", "dirname", "sh"];
/** A server that passes every check: Ubuntu 24.04, x86-64, 4 cores, 8 GB, 80 GB free, Docker 27, free ports, a domain that points here. */
@@ -68,7 +69,10 @@ case "$*" in
*releases/latest*) printf '{\\n "tag_name": "%s",\\n "name": "x"\\n}\\n' "$FAKE_RELEASE" ;;
*--resolve*) printf '%s' "\${FAKE_HTTPS:-}" ;;
*"/install.sh -o "*) exit 22 ;;
- *"${SOURCE}/"*" -o "*) [ "$FAKE_SOURCE" = published ] || exit 22
+ *"${FILES}/"*" -o "*) case "$*" in
+ *"${FILES}/main/"*) [ "$FAKE_SOURCE" = published ] || [ "$FAKE_SOURCE" = main-only ] || exit 22 ;;
+ *) [ "$FAKE_SOURCE" = published ] || exit 22 ;;
+ esac
for last; do :; done
case "$*" in
*deploy/box/prepare-host.sh*) printf '#!/bin/sh\\necho "prepare-host profiles=$MAUSBOT_PROFILES_DIR" >> "$FAKE_LOG"\\nexit "\${FAKE_PREPARE:-0}"\\n' > "$last" ;;
@@ -91,6 +95,7 @@ case "$*" in
"run --rm --network none --entrypoint id "*" -g") /usr/bin/id -g ;;
compose*" ps -q omb") echo c1 ;;
"image inspect -f {{json .Config.Env}} "*) echo "$FAKE_IMAGE_ENV" ;;
+ "image inspect -f {{index .Config.Labels "*) echo "\${FAKE_IMAGE_VERSION-v0.1.151}" ;;
"compose exec -T omb node dist-server/bot-box/box-check.js --public=none") echo "$FAKE_BOX_CHECK"; case "$FAKE_BOX_CHECK" in *'"failed":[]'*) ;; *) exit 1 ;; esac ;;
"inspect --format {{.State.Health.Status}} c1") echo "$FAKE_HEALTH" ;;
esac`,
@@ -300,7 +305,9 @@ describe.skipIf(!posix)("deploy/install.sh", () => {
const changes = result.docker.filter((call) => !READS.test(call) && !call.includes(" ps -q omb") && !call.startsWith("docker inspect"));
expect(changes).toEqual([
"docker compose pull -q",
+ 'docker image inspect -f {{index .Config.Labels "org.opencontainers.image.version"}} ghcr.io/milind-soni/openmausbot:v0.1.151',
"docker image inspect -f {{json .Config.Env}} ghcr.io/milind-soni/openmausbot:v0.1.151",
+ 'docker image inspect -f {{index .Config.Labels "org.opencontainers.image.version"}} ghcr.io/milind-soni/openmausbot:v0.1.151',
"docker run --rm --network none --entrypoint id ghcr.io/milind-soni/openmausbot:v0.1.151 -u",
"docker run --rm --network none --entrypoint id ghcr.io/milind-soni/openmausbot:v0.1.151 -g",
"docker compose up -d --remove-orphans",
@@ -417,20 +424,84 @@ describe.skipIf(!posix)("deploy/install.sh", () => {
it("says so, and does not finish, when the sandbox does not hold or the server cannot be prepared", () => {
const failed = run(["--domain", "maus.example.com"], { env: { FAKE_BOX_CHECK: BOX_FAILED } });
expect(failed.status).toBe(1);
- expect(failed.stderr).toContain("MausBot is running, but its bots' sandbox failed its self-check (config-hidden), so bots are not safely separated from the server.");
+ expect(failed.stderr).toContain("MausBot is running, but its sandbox self-check did not show that a bot cannot read the server's settings (config-hidden)");
expect(failed.all).not.toContain("MausBot is running at");
- const untested = run(["--domain", "maus.example.com"], { env: { FAKE_BOX_CHECK: '{"box":"bwrap","failed":[],"results":[]}' } });
- expect(untested.stderr).toContain("its sandbox self-check did not test that a bot cannot read the server's settings");
+ const silent = run(["--domain", "maus.example.com"], { env: { FAKE_BOX_CHECK: '{"box":"bwrap","failed":[],"results":[]}' } });
+ expect(silent.status).toBe(1);
+ expect(silent.stderr).toContain("MausBot is running, but its bots' sandbox gave no answer to its self-check");
+ const off = run(["--domain", "maus.example.com"], { env: { FAKE_BOX_CHECK: '{"box":"off","reason":"userns-refused"}' } });
+ expect(off.stderr).toContain("gave no answer to its self-check");
const refused = run(["--domain", "maus.example.com"], { env: { FAKE_PREPARE: "1" } });
expect(refused.status).toBe(1);
expect(refused.stderr).toContain("This server could not be prepared for the bots' sandbox (the reason is above).");
expect(refused.docker).not.toContain("docker compose up -d --remove-orphans");
const unpublished = run(["--domain", "maus.example.com"], { env: { FAKE_SOURCE: "missing" } });
expect(unpublished.status).toBe(1);
- expect(unpublished.stderr).toContain(`The files that prepare this server for the bots' sandbox could not be downloaded from ${SOURCE}.`);
+ expect(unpublished.stderr).toContain(`The files that prepare this server for the bots' sandbox could not be downloaded from ${FILES}.`);
expect(unpublished.docker).not.toContain("docker compose up -d --remove-orphans");
});
+ const box = (results: { id: string; ok: boolean; detail: string; severity?: string }[]) => JSON.stringify({
+ box: "bwrap", bridge: "socat", mutate: [], passed: results.filter((result) => result.ok).length, total: results.length,
+ failed: results.filter((result) => !result.ok).map((result) => result.id), results, skipped: [], durationMs: 109,
+ });
+ const hidden = { id: "config-hidden", ok: true, detail: "ENOENT" };
+
+ it.each(["keyring-denied", "hostname-private", "cpu-list-readable", "fly-api-hidden", "egress-public-allowed"])("goes on with a warning when only %s fails, showing what the check said", (id) => {
+ const result = run(["--domain", "maus.example.com"], { env: { FAKE_BOX_CHECK: box([hidden, { id, ok: false, detail: "exit null" }]) } });
+ expect(result.status).toBe(0);
+ expect(result.stdout).toContain(` note The sandbox's self-check did not pass ${id} (exit null).`);
+ expect(result.stdout).toContain("The bots' sandbox is on:");
+ expect(result.all).toContain("MausBot is running at https://maus.example.com");
+ });
+
+ it.each([
+ "messages-db-hidden", "data-dir-empty", "other-bot-folder-hidden", "other-task-folder-hidden", "secret-not-on-disk", "tmp-private", "engine-read-only",
+ "secret-not-in-env", "other-env-unreadable", "other-pid-hidden", "server-pid-hidden", "host-loopback-unreachable", "no-direct-internet", "harness-other-refused",
+ "egress-loopback-refused", "egress-metadata-refused", "egress-private-refused", "no-provider-key-in-env", "broker-key-not-on-disk", "broker-wrong-token-refused",
+ "broker-other-grant-refused", "own-cwd-rw", "bot-folder-rw", "engine-runs", "harness-internal-allowed", "broker-call-works", "base-url-is-broker",
+ "a-check-added-next-year",
+ ])("stops when %s fails", (id) => {
+ const result = run(["--domain", "maus.example.com"], { env: { FAKE_BOX_CHECK: box([{ id, ok: false, detail: "sees 4 entries" }, hidden, { id: "keyring-denied", ok: false, detail: "exit null" }]) } });
+ expect(result.status).toBe(1);
+ expect(result.stderr).toContain(`MausBot is running, but its bots' sandbox failed its self-check: ${id} (sees 4 entries). Bots are not safely separated from the server.`);
+ expect(result.stdout).toContain(" note The sandbox's self-check did not pass keyring-denied (exit null).");
+ expect(result.all).not.toContain("MausBot is running at");
+ });
+
+ it("stops when config.json is readable, and takes a check's own severity over its list", () => {
+ const readable = run(["--domain", "maus.example.com"], { env: { FAKE_BOX_CHECK: box([{ id: "config-hidden", ok: false, detail: "read 212 bytes" }]) } });
+ expect(readable.status).toBe(1);
+ expect(readable.stderr).toContain("did not show that a bot cannot read the server's settings (config-hidden)");
+ const marked = run(["--domain", "maus.example.com"], { env: { FAKE_BOX_CHECK: box([hidden, { id: "keyring-denied", ok: false, detail: "EACCES", severity: "must" }, { id: "new-soft-check", ok: false, detail: "slow", severity: "warn" }]) } });
+ expect(marked.status).toBe(1);
+ expect(marked.stderr).toContain("failed its self-check: keyring-denied (EACCES). Bots are not safely separated");
+ expect(marked.stdout).toContain(" note The sandbox's self-check did not pass new-soft-check (slow).");
+ expect(script.match(/keyring-denied/g)).toHaveLength(1);
+ });
+
+ it("takes the sandbox's files and update.sh from the installed version's tag, from main only when the tag has none, and says which", () => {
+ const tagged = run(["--domain", "maus.example.com"]);
+ expect(tagged.stdout).toContain(" note The sandbox's files are MausBot v0.1.151's own.");
+ expect(tagged.stdout).toContain(" note update.sh is MausBot v0.1.151's own.");
+ expect(tagged.calls.some((call) => call.includes(`${FILES}/main/`))).toBe(false);
+ const fallback = run(["--domain", "maus.example.com"], { env: { FAKE_SOURCE: "main-only" } });
+ expect(fallback.status).toBe(0);
+ expect(fallback.stdout).toContain(" note The sandbox's files are the newest in the repository (v0.1.151 has none).");
+ expect(fallback.stdout).toContain(" note update.sh is the newest in the repository (v0.1.151 has none).");
+ const order = fallback.calls.filter((call) => call.includes("deploy/box/prepare-host.sh")).map((call) => (call.includes("/v0.1.151/") ? "tag" : "main"));
+ expect(order).toEqual(["tag", "main"]);
+ expect(fallback.calls.filter((call) => call.includes("/v0.1.151/") && call.includes("compose.box.yaml"))).toEqual([]);
+ const stable = run(["--domain", "maus.example.com"], { env: { FAKE_STABLE: "200", FAKE_IMAGE_VERSION: "0.1.160" } });
+ expect(stable.stdout).toContain(" note The sandbox's files are MausBot v0.1.160's own.");
+ const unlabelled = run(["--domain", "maus.example.com"], { env: { FAKE_IMAGE_VERSION: "" } });
+ expect(unlabelled.stdout).toContain(" note The sandbox's files are the newest in the repository.");
+ const copy = run(["--domain", "maus.example.com"], { env: { OMB_INSTALL_SOURCE: "https://mirror.example.test/omb" } });
+ expect(copy.status).toBe(1);
+ expect(copy.calls.some((call) => call.includes("https://mirror.example.test/omb/deploy/box/prepare-host.sh -o "))).toBe(true);
+ expect(copy.calls.some((call) => call.includes(FILES) && call.includes(" -o "))).toBe(false);
+ });
+
it("leaves the sandbox out for a version that has none and when asked, and takes its settings back out", () => {
const first = run(["--domain", "maus.example.com"]);
expect(readFileSync(join(first.install, ".env"), "utf8")).toContain("COMPOSE_FILE=");