gstack icon indicating copy to clipboard operation
gstack copied to clipboard

setup's umask 077 also applies to bun install, so bun's shared package cache gets owner-only files that later installs of other projects hardlink

Open exGeni opened this issue 3 weeks ago • 4 comments

What happened

setup sets umask 077 on line 5 for the whole script (umask 077 # Restrict new files to owner-only (0o600 files, 0o700 dirs), added for M9 of #783 to protect gstack's state and log files). The same umask is still in effect when install_runtime_deps runs bun_cmd install (lines 1913, 1917 and 1920 at f0cd9f8c4b453c1eadd714e4149174ee01179eae), and when setup runs bun_cmd x playwright install chromium (lines 2480 and 2482).

Bun extracts each package it downloads into its global install cache (~/.bun/install/cache by default). As observed with bun 1.4.4 (reproduction below), the extracted files take the umask of the extracting process, so under setup's umask a package downloaded by gstack's bun install lands in the cache with its group and other permission bits removed (in the reproduction: 0600 files in 0700 directories). On Linux, bun installs by hardlinking from that cache by default (bun's docs/pm/global-cache.mdx), so when the same user later runs bun install in an unrelated project with a normal umask, that project's node_modules gets the same 0600 inodes.

We hit this as a failure for a second Unix user. The owning user's separate Bun project (a gbrain checkout) had node_modules/qs/* -rw------- root root, while the published qs-6.16.1.tgz has 0644 entries. A second Unix user on the machine that runs that project then failed with:

error: Cannot find module '<checkout>/node_modules/qs' from '/tmp/[eval]'
note: Cannot read file "<checkout>/node_modules/qs/": EACCES

On this machine, 388 of the 572 top-level entries in ~/.bun/install/cache are 0700, and 17,582 cache files are 0600. We did not trace which process created the qs cache entry; the timing is consistent with gstack's setup: [email protected]@@@1 was created at 2026-10-26 11:03Z, about 20 minutes after gstack commit a1487458 (2026-10-26 10:44Z) added [email protected] to gstack's bun.lock. The reproduction below shows the mechanism independently of that history.

Expected: the owner-only umask protects the files setup writes for gstack itself (state and logs) and does not leak into bun's package cache, which is shared by every Bun project of that user. One possible shape: run the bun calls (install_runtime_deps, bun x playwright) in a subshell with umask 022, and check that the state and log files M9 protects keep their owner-only modes. Restrictive cache permissions otherwise propagate into later installations of unrelated projects and can prevent access by another Unix user. We considered reporting this to bun instead, but the restrictive umask is set by setup.

Steps to reproduce

Bun 1.4.4 on Linux, with a throwaway cache so the real one is untouched:

  1. export BUN_INSTALL_CACHE_DIR=$PWD/cache
    mkdir a b
    for p in a b; do echo '{"name":"'$p'","version":"0.0.0","dependencies":{"qs":"6.16.1"}}' > $p/package.json; done
    (cd a && umask 077 && bun install)   # what setup does
    (cd b && umask 022 && bun install)   # an unrelated project, normal umask
    stat -c '%a %h %i %n' cache/[email protected]@@@1/lib/index.js a/node_modules/qs/lib/index.js b/node_modules/qs/lib/index.js
    
  2. Output: all three paths show mode 600, link count 3 and the same inode number (one filesystem), so project b gets the owner-only file through the shared hardlinked inode, although it was installed with umask 022.

Local repair: chmod -R a+rX <checkout>/node_modules/qs. Because the files are hardlinks, this also changes the cache copy. The other 0600 cache entries remain until the next install that pulls them into a project another user reads.

Readiness report

gstack doctor 1.99.0.0
ok              install root    ~/.claude/skills/gstack: claude global current (1.99.0.0), agy global current (1.99.0.0), codex global current (1.99.0.0)
ok              state root      ~/.gstack durable=yes (selected by default)
ok              bun             1.4.4 at /usr/local/bin/bun (floor 1.3.3, tested 1.4.2)
...
15 ok, 0 warn, 0 not configured, 0 fail

Environment

  • Host (Claude Code, Codex, Cursor, ...) and its version: Claude Code 2.1.309
  • OS: Debian GNU/Linux 12 (bookworm), Linux 7.0.0
  • gstack: 1.99.0.0 installed (9ab50347); claims checked against main at f0cd9f8c4b453c1eadd714e4149174ee01179eae
  • bun: 1.4.4
  • Related: #783 (security audit, M9 asked for umask 077 at the top of setup; this issue keeps that intent and only asks that it not reach bun's package cache). The gstack docs at f0cd9f8 do not cover the umask's effect on bun's cache.

exGeni avatar Nov 11 '26 01:11 exGeni

Thank you, @exGeni, for the clear report and the repro. We reproduced it on main (554390d) with bun 1.4.4 on Linux: a package installed under setup's umask 077 lands in bun's cache as 0600, and an unrelated project installed later with umask 022 gets the same 0600 hardlinked file.

We've labelled this S3. A second Unix user is the case that breaks, and chmod -R a+rX on the affected node_modules works around it. gstack is in a tooling freeze through 2026-11-21, so the fix (running setup's bun calls under a normal umask while keeping gstack's own state and log files owner-only) is queued for after the freeze.

capy-ai[bot] avatar Nov 11 '26 16:11 capy-ai[bot]

Following up: we're taking this. Running bun install and the Playwright install with a normal umask, while gstack's own state files keep 077, is a small, plainly correct fix. It will be rebuilt on current main and linked here after November 21.

capy-ai[bot] avatar Nov 16 '26 03:11 capy-ai[bot]

Picking this up. A maintainer agent working through a batch of fixes (our tracking thread GSTA-801) will first reproduce this on current main. If it reproduces, the agent fixes it on main and we'll close this issue with a link when the change lands. If it no longer reproduces, we'll close it and say what changed.

capy-ai[bot] avatar Nov 22 '26 05:11 capy-ai[bot]

Fixed on main in #4682: setup's bun install and Playwright install now run under umask 022, so new entries in Bun's shared cache are readable by other users, while gstack's own state and log files stay owner-only. Entries that are already 0600 need the chmod -R a+rX you described. Thanks for the clean repro.

capy-ai[bot] avatar Nov 22 '26 10:11 capy-ai[bot]