Files
CatoandClaude 169f920055 fix(desktop): Linux AppImage keeps the Chromium sandbox on (#1521)
Every Linux launch passed --no-sandbox. afterPack.cjs wrapped the
Electron binary in a stub that added it unconditionally, the .desktop
Exec= line carried it (electron-builder's AppImage default), and the
systemd unit from install-fleet-runner.sh passed it again. The reason
was real but narrow: inside an AppImage the setuid chrome-sandbox can
never work (the FUSE mount is nosuid), so where unprivileged user
namespaces are also blocked Chromium aborts at FATAL. Everywhere else
the namespace sandbox works without any setuid helper, and the flag
switched off the renderer sandbox #1479 had turned on.

- desktop/scripts/linux-launcher.sh replaces the stub. It runs
  Chromium's own probe (create a userns, write its maps, nest another)
  and the setuid-helper check for .deb installs, and passes
  --no-sandbox only when neither is available (or as root). It then
  prints why and how to fix it, and sets FLEET_RUNNER_SANDBOX_OFF.
  It also reports a --no-sandbox that arrives on argv, including the
  one electron-builder's AppRun appends silently.
- The main process shows that reason as a notification.
- linux.executableArgs is [] so the .desktop entry stops passing it.
- The systemd unit no longer passes --no-sandbox.
- The stale-instance pgrep no longer requires --no-sandbox in argv.
- Packaged-build test: test-linux-sandbox.sh starts the real AppImage
  under Xvfb and checks the live process tree (main argv; renderer
  seccomp-bpf and its own user namespace). ci-linux-sandbox.sh runs it
  with Ubuntu's userns restriction off (must be sandboxed) and on (must
  still start, with the notice). New PR workflow
  desktop-linux-sandbox.yml, and a step on the Linux release build.
- Version 0.8.62 with its changelog entry.


Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-01 19:18:22 +01:00

56 lines
2.7 KiB
JavaScript

// electron-builder afterPack hook: puts desktop/scripts/linux-launcher.sh in
// front of the Linux Electron binary.
//
// Why a launcher at all: a Linux AppImage mounts a squashfs volume that strips
// the SUID bit from chrome-sandbox. Where unprivileged user namespaces are
// also unavailable, Chromium aborts before any of our own code runs:
//
// FATAL:setuid_sandbox_host.cc(163)] The SUID sandbox helper binary was
// found, but is not configured correctly. ... You need to make sure that
// ... chrome-sandbox is owned by root and has mode 4755.
//
// The flag that avoids that abort has to be on argv before Chromium starts:
// app.commandLine.appendSwitch('no-sandbox') in main runs too late, and
// electron-builder's `linux.executableArgs` only reaches the .desktop file's
// Exec= line, not a direct launch of the AppImage. (It defaults to
// --no-sandbox for AppImage, which is why package.json sets it to [].)
// electron-builder's generated AppRun also appends --no-sandbox, silently,
// when its own `unshare -Ur true` probe fails; the launcher reports that too.
//
// This hook used to bake --no-sandbox in unconditionally, so every Linux
// user ran with the renderer sandbox off, including the many whose machine
// could sandbox perfectly well through user namespaces. The launcher now
// probes for that and adds --no-sandbox only where Chromium would otherwise
// abort, saying why on stderr and in the app. See linux-launcher.sh.
//
// Scoped to Linux: mac .dmg and Windows .exe have no SUID helper.
// desktop/scripts/test-linux-sandbox.sh proves the packaged AppImage in CI.
const fs = require('fs');
const path = require('path');
/** @param {import('electron-builder').AfterPackContext} context */
exports.default = async function afterPack(context) {
if (context.electronPlatformName !== 'linux') return;
// electron-builder copies the Electron binary into appOutDir under the
// executable name: "Fleet Runner" becomes "fleet-runner".
const execName = context.packager.executableName;
const appOutDir = context.appOutDir;
const realBinaryPath = path.join(appOutDir, execName);
const movedBinaryPath = path.join(appOutDir, `${execName}-bin`);
if (!fs.existsSync(realBinaryPath)) {
throw new Error(`[afterPack] expected the Electron binary at ${realBinaryPath}; it is missing`);
}
// afterPack can run twice (multi-arch, retries): wrap once.
if (!fs.existsSync(movedBinaryPath)) {
fs.renameSync(realBinaryPath, movedBinaryPath);
}
const template = fs.readFileSync(path.join(__dirname, 'linux-launcher.sh'), 'utf8');
fs.writeFileSync(realBinaryPath, template.replaceAll('@EXEC@', execName), { mode: 0o755 });
console.log(`[afterPack] installed linux-launcher.sh as ${execName} (Electron moved to ${execName}-bin)`);
};