Skip to content

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

doctor --host asks the MausBot connector on a server that runs one

milind-sonideb82f9f1f3d
diff --git a/docs/headless-cli.md b/docs/headless-cli.md
index 67ee5c654f..e942f04e61 100644
--- a/docs/headless-cli.md
+++ b/docs/headless-cli.md
@@ -122,6 +122,14 @@ and 100 GB for a Team server), disk encryption, CPUs and memory (a Team needs
(required with `--domain HOST`, else only a warning), and the clock against
network time (signed requests allow 300 seconds). It changes nothing.
+On a server that runs MausBot's own connector (a team on its own server), it
+also asks the connector for its checks (`mausbot-connector probe --json`,
+which starts the bots' box once under the home's own security settings) and
+lists any that fail. There the home runs under its own AppArmor profile, so
+AppArmor's server-wide switch can stay on: the user-namespace check passes
+when the connector's box check does, and otherwise says to run the install
+command again.
+
A problem fails the check (exit 7) and says its fix on the next line; a
warning does not. `--json` prints `{ ok, problems, warnings, checks: [{ id,
status, message, fix }] }`. On macOS and Windows it says it checks Linux
diff --git a/server/headless/host-doctor.test.ts b/server/headless/host-doctor.test.ts
index 17b0c5ea26..d0cd4c9a63 100644
--- a/server/headless/host-doctor.test.ts
+++ b/server/headless/host-doctor.test.ts
@@ -92,6 +92,29 @@ describe("doctor --host", () => {
expect(report.human.at(-1)).toBe("1 problem.");
});
+ it("asks the MausBot connector on a server that runs one: its home's own AppArmor profile stands in for the server-wide switch", async () => {
+ const connector = (box: boolean) => async (command: string, args: string[]): Promise<CommandResult> => {
+ if (command === "docker" && args[0] === "exec") {
+ const checks = [{ id: "profiles", ok: true }, box ? { id: "box", ok: true } : { id: "box", ok: false, fix: "Our bots' safety box can't start on this server yet. Run the install command again to repair it." }];
+ return { ok: box, stdout: `${JSON.stringify({ ok: box, checks })}\n`, stderr: "", missing: false };
+ }
+ return command === "docker" ? { ok: true, stdout: "29.1.3\n", stderr: "", missing: false } : { ok: true, stdout: "yes\n", stderr: "", missing: false };
+ };
+ const stock = { files: { "/proc/sys/kernel/apparmor_restrict_unprivileged_userns": "1\n" } };
+ const passing = await checkHost(probe({ ...stock, run: connector(true) }), OPTIONS);
+ expect(byId(passing, "userns")).toMatchObject({ status: "ok", message: expect.stringContaining("its own AppArmor profile") });
+ expect(byId(passing, "connector")).toEqual({ id: "connector", status: "ok", message: "MausBot connector: its 2 checks pass, the bots' box among them" });
+ expect(hostReport(passing).exitCode).toBe(0);
+ const failing = await checkHost(probe({ ...stock, run: connector(false) }), OPTIONS);
+ expect(byId(failing, "userns")).toMatchObject({ status: "FAIL", fix: expect.stringContaining("install command again") });
+ expect(byId(failing, "connector-box")).toMatchObject({ status: "FAIL", fix: expect.stringContaining("Run the install command again") });
+ expect(hostReport(failing).exitCode).toBe(7);
+ // No connector here (docker exec answers with something else): nothing about one, and the server-wide fix.
+ const plain = await checkHost(probe(stock), OPTIONS);
+ expect(plain.some((check) => check.id.startsWith("connector"))).toBe(false);
+ expect(byId(plain, "userns")?.fix).toContain("kernel.apparmor_restrict_unprivileged_userns=0");
+ });
+
it("warns, and still passes, on what a standalone server can live with", async () => {
const checks = await checkHost(probe({
arch: "arm64", cpus: 2, memoryBytes: 4 * 2 ** 30, freeBytes: () => 40 * GB, clockOffset: async () => 45_000,
diff --git a/server/headless/host-doctor.ts b/server/headless/host-doctor.ts
index d7cf582d0f..223ebbefdf 100644
--- a/server/headless/host-doctor.ts
+++ b/server/headless/host-doctor.ts
@@ -1,5 +1,6 @@
// `doctor --host`: can this Linux machine run the server and the bots' sandbox? It only looks: files under /proc and /sys,
-// version queries to docker, podman and timedatectl, the sockets already listening, and one HEAD request for the time.
+// version queries to docker, podman and timedatectl, the sockets already listening, and one HEAD request for the time. On
+// a server that runs the MausBot connector it also asks that for its own checks, which start one throwaway box probe.
import { execFile } from "node:child_process";
import { existsSync, readdirSync, readFileSync, statfsSync } from "node:fs";
import { arch, cpus, homedir, release, totalmem } from "node:os";
@@ -91,14 +92,50 @@ async function containerCheck(probe: HostProbe): Promise<HostCheck> {
return fail("containers", "Neither Docker nor Podman is installed", "sudo apt-get install -y docker.io (or podman)");
}
-function userNamespaceCheck(probe: HostProbe): HostCheck {
+/** What the MausBot connector on this server says of it, when one runs there: its own checks (connector/src/host.ts). */
+export interface ConnectorReport {
+ checks: { id: string; ok: boolean; warning?: boolean; fix?: string }[];
+}
+
+const CONNECTOR = "mausbot-connector";
+
+/** Asks the connector's container, as root may; null where none runs or it cannot be asked. */
+export async function connectorReport(probe: HostProbe): Promise<ConnectorReport | null> {
+ // `probe --json` exits 1 when a check fails, with the same one line.
+ const result = await probe.run("docker", ["exec", CONNECTOR, CONNECTOR, "probe", "--json"]);
+ let parsed: unknown;
+ try { parsed = JSON.parse(result.stdout.trim().split("\n").at(-1) ?? ""); } catch { return null; }
+ const checks = (parsed as { checks?: unknown } | null)?.checks;
+ if (!Array.isArray(checks)) return null;
+ return {
+ checks: checks.filter((check): check is ConnectorReport["checks"][number] =>
+ typeof check === "object" && check !== null && typeof check.id === "string" && typeof check.ok === "boolean"),
+ };
+}
+
+function connectorChecks(report: ConnectorReport | null): HostCheck[] {
+ if (!report) return [];
+ const problems = report.checks.filter((check) => !check.ok || check.warning);
+ if (!problems.length) return [ok("connector", `MausBot connector: its ${report.checks.length} checks pass, the bots' box among them`)];
+ return problems.map((check) => check.ok
+ ? warn(`connector-${check.id}`, `MausBot connector: ${check.id}`, check.fix)
+ : fail(`connector-${check.id}`, `MausBot connector: the ${check.id} check fails`, check.fix ?? "run MausBot's install command again"));
+}
+
+function userNamespaceCheck(probe: HostProbe, connector: ConnectorReport | null): HostCheck {
const sysctl = (name: string) => probe.read(`/proc/sys/${name.replaceAll(".", "/")}`)?.trim();
const keep = (setting: string) => `sudo sysctl -w ${setting} (and put it in /etc/sysctl.d/ to keep it after a reboot)`;
if (!probe.list("/proc/self/ns").includes("user")) {
return fail("userns", "Bot sandbox: this kernel has no user namespaces", "use a stock Ubuntu or Debian kernel (CONFIG_USER_NS)");
}
if (sysctl("kernel.apparmor_restrict_unprivileged_userns") === "1") {
- return fail("userns", "Bot sandbox: AppArmor blocks unprivileged user namespaces", keep("kernel.apparmor_restrict_unprivileged_userns=0"));
+ // A MausBot home runs under its own AppArmor profile (omb-home-narrow), which allows them for that container alone.
+ if (connector?.checks.some((check) => check.id === "box" && check.ok)) {
+ return ok("userns", "Unprivileged user namespaces: AppArmor restricts them here, and MausBot's home has them through its own AppArmor profile");
+ }
+ return fail("userns", "Bot sandbox: AppArmor blocks unprivileged user namespaces", connector
+ ? "run MausBot's install command again: it loads the home's own AppArmor profile, so this server-wide switch can stay on"
+ : keep("kernel.apparmor_restrict_unprivileged_userns=0"));
}
if (sysctl("kernel.unprivileged_userns_clone") === "0") {
return fail("userns", "Bot sandbox: unprivileged user namespaces are turned off", keep("kernel.unprivileged_userns_clone=1"));
@@ -207,9 +244,9 @@ export async function checkHost(probe: HostProbe, options: HostOptions): Promise
const name = probe.platform === "darwin" ? "macOS" : probe.platform === "win32" ? "Windows" : probe.platform;
return [fail("platform", `doctor --host checks a Linux server, and this is ${name}`, "run it on the Linux server that will host OpenMausBot")];
}
- const [containers, ports, clock] = await Promise.all([containerCheck(probe), portChecks(probe, options), clockCheck(probe)]);
- return [systemCheck(probe), archCheck(probe), containers, userNamespaceCheck(probe), seccompCheck(probe), cgroupCheck(probe),
- diskCheck(probe, options.dataDir), encryptedCheck(probe, options.dataDir), sizeCheck(probe), ...ports, clock];
+ const [containers, ports, clock, connector] = await Promise.all([containerCheck(probe), portChecks(probe, options), clockCheck(probe), connectorReport(probe)]);
+ return [systemCheck(probe), archCheck(probe), containers, userNamespaceCheck(probe, connector), seccompCheck(probe), cgroupCheck(probe),
+ diskCheck(probe, options.dataDir), encryptedCheck(probe, options.dataDir), sizeCheck(probe), ...ports, clock, ...connectorChecks(connector)];
}
export function hostReport(checks: readonly HostCheck[]): { result: Record<string, unknown>; exitCode: number; human: string[] } {