Skip to content

fix(install): key the lifecycle node shim directory on the user id - #17

Merged
steipete merged 1 commit into
mainfrom
claude/lifecycle-node-shim-per-user
Sep 27, 2026
Merged

steipete merged 1 commit into
mainfrom
claude/lifecycle-node-shim-per-user

Conversation

@steipete

Copy link
Copy Markdown

What does this PR do?

Makes the lifecycle-script node shim work for every user on a shared host.

When node is not on PATH, Bun gives lifecycle scripts (and --bun) a directory holding node/bun symlinks to the running Bun. On POSIX that directory was the compile-time constant /tmp/bun-node-<sha>, the same for every user of a given build. The first user creates it with mode 0700. For every other user, mkdir hits EEXIST, the ownership guard (st_uid == getuid()) rejects the directory, and create_fake_temporary_node_executable returns Ok(()) without adding anything to PATH. A dependency's postinstall: node ... then fails with node: command not found (exit 127) and no hint from Bun.

This was hit on Ubuntu 26.04 x86_64 with the checksum-pinned fork build 1.4.3-canary.1+ddfce5d01 that openclaw/openclaw's setup-test-bun action installs. After one account ran a lifecycle install, another account's bun add -g --trust failed in protobufjs's node scripts/postinstall. A private /tmp for the second account fixed it with the same binary, and stock 1.4.2 only worked because its revision gave it a different, not-yet-existing directory.

  • Name the directory /tmp/bun-node-<uid>-<sha> (debug builds: -debug; /private/tmp on macOS, /data/local/tmp on Android as before). This is the scheme upstream oven-sh/bun#35565 proposes (open and unmerged since July) and the one the bunx-<uid>-* cache already uses. Upstream issue: oven-sh/bun#42048.
  • RunCommand::BUN_NODE_DIR (a const) becomes RunCommand::bun_node_dir(), memoized, since the uid is a runtime value. bun_node_file_utf8() still returns the directory on POSIX, as before.
  • The 0700 create + ownership/mode tamper guard is unchanged; it now protects a per-user path instead of a shared one.
  • Drop the POSIX debug-only delete_tree_absolute of the shim directory. It raced concurrent debug processes that share the directory, and the existing EEXIST readlink re-point already replaces stale links.
  • Windows is untouched (%TEMP% is already per-user there; upstream run: scope the --bun node shim directory by uid oven-sh/bun#35565's Windows naming change is not adapted here).
  • Regression test in test/cli/install/bun-install-lifecycle-scripts.test.ts, next to the node-gyp shim test: a root postinstall: node probe.mjs with a PATH that contains no node must run under Bun, through a shim directory named for the current uid, owned by the current user, mode 0700.

Production delta: src/install/lib.rs + src/runtime/cli/run_command.rs, +31/-57, net -26 lines. Test +43/-1. One changelog entry.

How did you verify your code works?

Two-user reproduction, Linux x86_64 (Ubuntu 26.04, kernel 7.0.0-1009-aws, m7i.4xlarge; users usera uid 1001 and userb uid 1002; Node.js removed so node is not on either user's PATH). The probe project has a root postinstall: node probe.mjs and a trusted file: dependency probe-dep with the same postinstall; each probe prints typeof Bun, the uid, and the bun-node PATH entry. The install runs as sudo -u <user> -H env -i HOME=/home/<user> PATH=/usr/local/bin:/usr/bin:/bin <bun> install.

Before, with the pinned 1.4.3-canary.1+ddfce5d01 binary (both checksums from the openclaw/openclaw action verified):

=== /opt/bun-pinned/bun install as usera ===
root: typeof Bun=object uid=1001 shim=/tmp/bun-node-ddfce5d01
exit=0

drwx------ 2 usera usera 80 Sep 27 18:31 /tmp/bun-node-ddfce5d01
lrwxrwxrwx 1 usera usera 19 Sep 27 18:31 node -> /opt/bun-pinned/bun

=== /opt/bun-pinned/bun install as userb ===
/usr/bin/bash: line 1: node: command not found
error: postinstall script from "probe-dep" exited with 127
exit=127

$ rm -rf /tmp/bun-node-*   # control: userb alone
root: typeof Bun=object uid=1002 shim=/tmp/bun-node-ddfce5d01
exit=0

A from-source release build of openclaw/main at 76d5d1294f reproduced it identically (/tmp/bun-node-76d5d1294, usera=0 userb-collision=127 userb-alone=0).

After, a release build of 76d5d1294f + this patch (built from the exact diff committed here; its sha256 matches git diff openclaw/main HEAD):

=== a) two users ===
root: typeof Bun=object uid=1001 shim=/tmp/bun-node-1001-76d5d1294   exit=0
root: typeof Bun=object uid=1002 shim=/tmp/bun-node-1002-76d5d1294   exit=0
drwx------ 2 usera usera 80 Sep 27 18:56 /tmp/bun-node-1001-76d5d1294
drwx------ 2 userb userb 80 Sep 27 18:56 /tmp/bun-node-1002-76d5d1294

=== b) legacy dir from the pinned build owned by usera, then fixed build as userb ===
root: typeof Bun=object uid=1002 shim=/tmp/bun-node-1002-76d5d1294   exit=0
drwx------ 2 userb userb 80 Sep 27 18:56 /tmp/bun-node-1002-76d5d1294
drwx------ 2 usera usera 80 Sep 27 18:56 /tmp/bun-node-ddfce5d01

=== c) fixed build as usera twice: same directory reused (same inode, 0700) ===
scenario: a-usera=0 a-userb=0 b-userb=0 c-usera-2nd=0

Regression test:

  • Linux x86_64, as a non-root user (uid 1000): passes with the patched release build, fails with the pinned build at the intended assertion (Expected /^bun-node-1000(-|$)/, Received: "bun-node-ddfce5d01").
  • macOS arm64: passes with bun bd test, and USE_SYSTEM_BUN=1 (stock 1.4.2) fails with Received: "bun-node-744846f84".
  • With the macOS debug build, the neighboring node-gyp shim test and test/cli/run/as-node.test.ts (11/11) pass. test/cli/install/bun-run.test.ts is 286 pass / 10 fail. All 10 failures reproduce identically on a clean debug build of openclaw/main on the same Mac: two SIGILL expectations, and eight cases where the local shell can't find bun-debug. None are related to this change.

Also: rustfmt and Prettier are clean, and the Codex review of the diff found nothing actionable. rust:check-all completed only for x86_64-unknown-linux-gnu; linux-x64 is additionally covered by the full release build above, and macOS by the debug build.

Follow-ups, not in this PR

  • If another user deliberately pre-creates your /tmp/bun-node-<uid>-<sha>, the guard still refuses it and skips the shim silently. Warning, or falling back to a private mkdtemp directory, would make that visible. The collision between ordinary users is gone.
  • The shim still lives under the literal /tmp, not $TMPDIR. This keeps parity with upstream run: scope the --bun node shim directory by uid oven-sh/bun#35565.

When `node` is not on PATH, lifecycle scripts and `--bun` get a PATH
entry holding `node`/`bun` symlinks to the running Bun. On POSIX that
directory was the compile-time `/tmp/bun-node-<sha>`, shared by every
user on the host. The first user created it `0700`; every other user's
`mkdir` hit EEXIST, the ownership guard rejected the directory, and the
shim was silently left off PATH, so `postinstall: node ...` failed with
`node: command not found` (exit 127).

Name the directory `/tmp/bun-node-<uid>-<sha>` (debug: `-debug`), the
scheme upstream oven-sh#35565 proposes and the `bunx-<uid>-*` cache
already uses. The ownership/mode guard is unchanged. Also drop the
POSIX debug-only wipe of the directory, which raced concurrent debug
processes; the EEXIST readlink re-point already replaces stale links.
Windows paths are unchanged.

Upstream issue: oven-sh#42048
@steipete
steipete merged commit c148250 into main Sep 27, 2026
10 of 11 checks passed
@steipete
steipete deleted the claude/lifecycle-node-shim-per-user branch September 27, 2026 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant