Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(linux): let the DEB install in a container on a restricted Ubuntu host
milind-sonic6bb490ba3c7
diff --git a/build/linux-after-install.sh b/build/linux-after-install.shindex 97612b2265..8d379dc76e 100755--- a/build/linux-after-install.sh+++ b/build/linux-after-install.sh@@ -105,6 +105,19 @@ secure_browser_tree() {repair_executable "$BROWSER_ROOT/chrome/chrome-headless-shell-linux64/chrome-headless-shell"}+in_container() {+ if [ "$TEST_MODE" -eq 1 ]; then+ [ -e "$APP_ROOT/test-system/container" ]+ return+ fi+ if [ -x /usr/bin/systemd-detect-virt ] && /usr/bin/systemd-detect-virt --quiet --container; then+ return 0+ fi+ # Only root can create these markers on the host, and the runtimes create+ # them inside every container: Docker /.dockerenv, Podman /run/.containerenv.+ [ -f /.dockerenv ] || [ -f /run/.containerenv ] || [ -s /run/systemd/container ]+}+install_browser_apparmor_profile() {profile=$APP_ROOT/resources/openmausbot-browser.apparmorif [ -L "$profile" ] || [ ! -f "$profile" ] || [ "$(stat -c '%h' -- "$profile")" != 1 ]; then@@ -166,6 +179,14 @@ install_browser_apparmor_profile() {# policy for a future boot, but do not fail installation on an unrestricted# host booted with AppArmor disabled. A restricted host still fails closed.if [ ! -x "$APPARMOR_STATUS" ] || ! "$APPARMOR_STATUS" --enabled >/dev/null 2>&1; then+ # A Docker or Podman container reads the host kernel's restriction but+ # cannot reach the host's AppArmor, so no install inside it could load+ # this policy. The host owns that setting: keep the staged policy, say+ # so, and install. A container that can load policy (LXD) loads it below.+ if [ "$restricted" = 1 ] && in_container; then+ echo "OpenMausBot staged its browser AppArmor policy at $target but did not load it: AppArmor belongs to this container's host. The bot's browser needs the host to allow its user namespaces." >&2+ return+ fiif [ "$restricted" = 1 ]; thenecho "OpenMausBot cannot load its browser sandbox policy while AppArmor restrictions are active but AppArmor is unavailable." >&2exit 1diff --git a/scripts/linux-after-install.test.mjs b/scripts/linux-after-install.test.mjsindex d0f6e943b2..692573b3eb 100644--- a/scripts/linux-after-install.test.mjs+++ b/scripts/linux-after-install.test.mjs@@ -254,6 +254,36 @@ describe.skipIf(process.platform !== "linux")("Linux DEB upgrade hook", () => {expect(result.stdout).not.toContain("profile operation");});+ it("installs in a Docker container on a restricted host, staging the policy for the host", () => {+ // Docker shows the host's restriction sysctl but not the host's AppArmor:+ // a clean ubuntu:24.04 container on a stock Ubuntu 24.04 host.+ const { appRoot, systemRoot, apparmorStatus, apparmorDir } = fixture();+ fs.writeFileSync(apparmorStatus, "#!/bin/sh\nexit 1\n");+ fs.writeFileSync(path.join(systemRoot, "container"), "docker\n");+ const result = runHook(appRoot);+ expect(result.status, result.stderr).toBe(0);+ expect(result.stderr).toContain("AppArmor belongs to this container's host");+ expect(result.stdout).not.toContain("profile operation");+ expect(fs.readFileSync(path.join(apparmorDir, "openmausbot-browser"), "utf8")).toBe(fs.readFileSync(browserPolicy, "utf8"));+ });++ it("still loads the policy in a container that has its own AppArmor", () => {+ const { appRoot, systemRoot, apparmorDir } = fixture();+ fs.writeFileSync(path.join(systemRoot, "container"), "lxc\n");+ const result = runHook(appRoot);+ expect(result.status, result.stderr).toBe(0);+ expect(result.stdout).toContain(`profile operation: -r ${apparmorDir}/openmausbot-browser`);+ });++ it("still fails closed in a container whose host restricts namespaces but that lacks AppArmor tools", () => {+ const { appRoot, systemRoot, parser } = fixture();+ fs.unlinkSync(parser);+ fs.writeFileSync(path.join(systemRoot, "container"), "docker\n");+ const result = runHook(appRoot);+ expect(result.status).not.toBe(0);+ expect(result.stderr).toContain("needs apparmor and apparmor_parser");+ });+it("refuses an AppArmor destination symlink without overwriting its target", () => {const { appRoot, apparmorDir } = fixture();const external = path.join(appRoot, "external-policy");