Skip to content

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

fix(vm): accept the WSL-translated workspace mount on Windows for any runtime (#6741)

ARAYN7011c6597cb151ba
diff --git a/server/container-computer.test.ts b/server/container-computer.test.ts
index 20a751fc10..46d682d749 100644
--- a/server/container-computer.test.ts
+++ b/server/container-computer.test.ts
@@ -37,6 +37,7 @@ import {
type CommandRunner,
type LocalVmTarget,
autoLocalVmAttachable,
+ dockerWorkspaceMountIsSafe,
} from "./container-computer.ts";
import { DESKTOP_FLAGS_LABEL, DESKTOP_FLAGS_VERSION, dockerSecurityIsHardened, podmanSecurityIsHardened } from "./container-isolation.ts";
import { PIDS_LIMIT } from "./container-limits.ts";
@@ -369,6 +370,31 @@ describe("containerRuntimeStatus probe of a hung runtime", () => {
});
});
+describe("dockerWorkspaceMountIsSafe", () => {
+ const workspace = "C:\\Users\\light\\.openmausbot\\vm-home";
+ const mount = (Source: string) => [{ Type: "bind", Source, Destination: VM_WORKSPACE_GUEST, RW: true }];
+
+ it.each([
+ "/mnt/c/Users/light/.openmausbot/vm-home",
+ "/mnt/c/Users/light/.openmausbot/vm-home/",
+ "/mnt//c/Users/light//.openmausbot/vm-home",
+ "\\mnt\\C\\Users\\light\\.openmausbot\\vm-home",
+ ])("accepts the WSL translation of a Windows workspace for any runtime: %s", (source) => {
+ expect(dockerWorkspaceMountIsSafe(mount(source), "win32", workspace)).toBe(true);
+ });
+
+ it("still rejects a different folder, other platforms and a non-bind mount", () => {
+ expect(dockerWorkspaceMountIsSafe(mount("/mnt/c/Users/light/other"), "win32", workspace)).toBe(false);
+ expect(dockerWorkspaceMountIsSafe(mount("/mnt/d/Users/light/.openmausbot/vm-home"), "win32", workspace)).toBe(false);
+ expect(dockerWorkspaceMountIsSafe(mount("/mnt/c/Users/light/.openmausbot/vm-home"), "linux", workspace)).toBe(false);
+ expect(dockerWorkspaceMountIsSafe(
+ [{ Type: "volume", Source: "/mnt/c/Users/light/.openmausbot/vm-home", Destination: VM_WORKSPACE_GUEST, RW: true }],
+ "win32",
+ workspace,
+ )).toBe(false);
+ });
+});
+
describe("containerComputerStatus", () => {
it("prefers the supported Podman image store when Docker is also healthy on Windows", async () => {
const fake = runner({
diff --git a/server/container-computer.ts b/server/container-computer.ts
index 214543fe68..9861158cff 100644
--- a/server/container-computer.ts
+++ b/server/container-computer.ts
@@ -572,7 +572,6 @@ export async function containerComputerStatus(
detail?.Mounts,
platform,
target.workspaceDir,
- status.runtime,
) ? "durable" : "unsafe";
status.security = (
status.runtime === "podman"
@@ -709,28 +708,27 @@ function sameWorkspaceSource(
return platform === "win32" ? actual.toLowerCase() === expected.toLowerCase() : actual === expected;
}
-/** Podman Machine exposes a Windows bind source through its WSL mount path; accept only the exact translation. */
-function samePodmanWindowsWorkspaceSource(source: string | undefined, expectedWorkspace: string): boolean {
+/**
+ * Podman Machine and Rancher Desktop (dockerd) expose a Windows bind source through its WSL mount path;
+ * accept only the exact translation, ignoring slash style, doubled slashes and a trailing slash.
+ */
+function sameWslWindowsWorkspaceSource(source: string | undefined, expectedWorkspace: string): boolean {
if (!source) return false;
const match = expectedWorkspace.match(/^([A-Za-z]):[\\/](.+)$/);
if (!match) return false;
- const expected = `/mnt/${match[1].toLowerCase()}/${match[2].replaceAll("\\", "/")}`;
- const actual = source.replaceAll("\\", "/");
- return actual.toLowerCase() === expected.toLowerCase();
+ const tidy = (path: string) => path.replaceAll("\\", "/").replace(/\/{2,}/g, "/").replace(/\/+$/, "").toLowerCase();
+ return tidy(source) === tidy(`/mnt/${match[1]}/${match[2]}`);
}
-function dockerWorkspaceMountIsSafe(
+export function dockerWorkspaceMountIsSafe(
mounts:
| Array<{ Type?: string; Source?: string; Destination?: string; RW?: boolean }>
| undefined,
platform: NodeJS.Platform,
expectedWorkspace: string,
- runtime: Runtime = "docker",
): boolean {
const sourceMatches = sameWorkspaceSource(mounts?.[0]?.Source, platform, expectedWorkspace) ||
- (runtime === "podman" &&
- platform === "win32" &&
- samePodmanWindowsWorkspaceSource(mounts?.[0]?.Source, expectedWorkspace));
+ (platform === "win32" && sameWslWindowsWorkspaceSource(mounts?.[0]?.Source, expectedWorkspace));
return Boolean(
mounts?.length === 1 &&
mounts[0]?.Type === "bind" &&