From 7591826f6ae16074c3d96e964730cfb2a8bf2c56 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 17 Nov 2026 16:45:47 +0000 Subject: [PATCH 1/2] test(server): t3 browser setup must not report ready while Chrome's sandbox fails Reproduces #38222: inside an LXC/Incus guest the host's userns restriction still blocks Chrome's sandbox after the guest loads T3's AppArmor profile, yet setup prints that the host is ready. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/cli/browser.test.ts | 32 +++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/apps/server/src/cli/browser.test.ts b/apps/server/src/cli/browser.test.ts index f652cb58b2104..5c35238d84aa0 100644 --- a/apps/server/src/cli/browser.test.ts +++ b/apps/server/src/cli/browser.test.ts @@ -28,7 +28,11 @@ const notFound = (method: string, path: string) => }); /** An Ubuntu host with the userns restriction on, the browser installed, and a system font. */ -const runSetupAsRoot = (input: { readonly profile: string | undefined }) => { +const runSetupAsRoot = (input: { + readonly profile: string | undefined; + /** An LXC guest whose host still denies userns: the profile loads, Chrome's sandbox does not start. */ + readonly sandboxStillBlocked?: boolean; +}) => { const files = new Map([ [USERNS_RESTRICTION, "1\n"], [BROWSER, ""], @@ -64,11 +68,20 @@ const runSetupAsRoot = (input: { readonly profile: string | undefined }) => { readonly args: ReadonlyArray; }; commands.push([name, ...args].join(" ")); - const output = - name === "fc-match" ? "/usr/share/fonts/sans.ttf" : name === BROWSER ? "Chrome 154\n" : ""; + const blocked = + input.sandboxStillBlocked === true && + !["fc-match", "apparmor_parser", "apt-get", "apt-cache", "ldd"].includes(name) && + !(name === BROWSER && args.includes("--version")); + const output = blocked + ? "FATAL:zygote_host_impl_linux.cc(130)] No usable sandbox!\n" + : name === "fc-match" + ? "/usr/share/fonts/sans.ttf" + : name === BROWSER + ? "Chrome 154\n" + : ""; return ChildProcessSpawner.makeHandle({ pid: ChildProcessSpawner.ProcessId(1), - exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(0)), + exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(blocked ? 1 : 0)), isRunning: Effect.succeed(false), kill: () => Effect.void, unref: Effect.succeed(Effect.void), @@ -137,3 +150,14 @@ it.effect.each([ expect(result.output).toContain("This host is ready for T3's browser."); }), ); + +it.effect("t3 browser setup as root does not report ready while Chrome's sandbox still fails", () => + Effect.gen(function* () { + const result = yield* runSetupAsRoot({ + profile: PreviewBrowserHost.APPARMOR_PROFILE, + sandboxStillBlocked: true, + }); + expect(result.loads).toEqual([LOAD]); + expect(result.output).not.toContain("This host is ready for T3's browser."); + }), +); From 493222f76ef45097226b8069b10581cb92261d9a Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 17 Nov 2026 16:51:44 +0000 Subject: [PATCH 2/2] fix(server): t3 browser setup no longer reports ready while Chrome's sandbox fails Inside an LXC/Incus guest whose host restricts unprivileged user namespaces, the AppArmor profile loaded in the guest does nothing, yet setup reported the host ready. Setup now launches the installed browser once (as the sudo user when run as root) and, when Chrome reports no usable sandbox, says the profile has to be loaded on the container's host or the sandbox turned off. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/cli/browser.ts | 12 +++++++++++ apps/server/src/preview/PreviewBrowserHost.ts | 21 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/apps/server/src/cli/browser.ts b/apps/server/src/cli/browser.ts index a82b84ef82d4b..600b36247bfed 100644 --- a/apps/server/src/cli/browser.ts +++ b/apps/server/src/cli/browser.ts @@ -141,8 +141,19 @@ const browserSetupCommand = Command.make("setup", { baseDir: baseDirFlag }).pipe : []; const needsFonts = !(yield* fontAvailable); const hasApt = yield* fs.exists("/usr/bin/apt-get").pipe(Effect.orElseSucceed(() => false)); + const sandboxStillBlocked = + restricted && Option.isSome(browser) && rootWarning === undefined + ? PreviewBrowserHost.sandboxFailsToStart( + browser.value, + isRoot ? env.SUDO_USER : undefined, + ) + : Effect.succeed(false); + const stillBlockedMessage = `Chrome's sandbox still cannot start, although the AppArmor profile at ${PreviewBrowserHost.APPARMOR_PROFILE_PATH} is ${isRoot ? "loaded" : "on disk"}. In a container (LXC, Incus, LXD), the container's host restricts user namespaces too: copy that profile to the container's host and load it there with \`apparmor_parser -r ${PreviewBrowserHost.APPARMOR_PROFILE_PATH}\`. Otherwise set \`T3CODE_SERVER_BROWSER_SANDBOX=0\` in the T3 server's environment and restart the server; this disables Chrome's sandbox.`; if (!needsProfile && missing.length === 0 && !needsFonts) { + if (yield* sandboxStillBlocked) { + return yield* Console.log(stillBlockedMessage + reloadHint); + } return yield* Console.log( rootWarning ?? (Option.isSome(browser) @@ -248,6 +259,7 @@ const browserSetupCommand = Command.make("setup", { baseDir: baseDirFlag }).pipe ); } + if (yield* sandboxStillBlocked) return yield* Console.log(stillBlockedMessage); yield* Console.log(rootWarning ?? "This host is ready for T3's browser."); }), ), diff --git a/apps/server/src/preview/PreviewBrowserHost.ts b/apps/server/src/preview/PreviewBrowserHost.ts index 0952dbaf944cd..458a0a272fc30 100644 --- a/apps/server/src/preview/PreviewBrowserHost.ts +++ b/apps/server/src/preview/PreviewBrowserHost.ts @@ -126,6 +126,27 @@ export const missingLibraries = Effect.fn("PreviewBrowserHost.missingLibraries") return listed.length > 0 ? listed : [loaderError]; }); +/** + * A loaded profile does nothing in a container whose host also restricts userns; only a launch + * shows that. Chrome will not sandbox as root, so root launches it as `user`. + */ +export const sandboxFailsToStart = Effect.fn("PreviewBrowserHost.sandboxFailsToStart")(function* ( + executable: string, + user: string | undefined, +) { + const spawner = yield* ChildProcessSpawner.ChildProcessSpawner; + const launch = [executable, "--headless", "--dump-dom", "about:blank"]; + const command = + user === undefined + ? ChildProcess.make(launch[0]!, launch.slice(1), { stdin: "ignore" }) + : ChildProcess.make("runuser", ["-u", user, "--", ...launch], { stdin: "ignore" }); + const output = yield* spawner.string(command, { includeStderr: true }).pipe( + Effect.timeout("15 seconds"), + Effect.orElseSucceed(() => ""), + ); + return output.includes(NO_SANDBOX_SIGNATURE); +}); + export const usernsRestricted = Effect.gen(function* () { if ((yield* HostProcess.Platform) !== "linux") return false; const fs = yield* FileSystem.FileSystem;