Repository navigation
fix(install): key the lifecycle node shim directory on the user id - #17
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Makes the lifecycle-script
nodeshim work for every user on a shared host.When
nodeis not onPATH, Bun gives lifecycle scripts (and--bun) a directory holdingnode/bunsymlinks 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 mode0700. For every other user,mkdirhitsEEXIST, the ownership guard (st_uid == getuid()) rejects the directory, andcreate_fake_temporary_node_executablereturnsOk(())without adding anything toPATH. A dependency'spostinstall: node ...then fails withnode: 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+ddfce5d01that openclaw/openclaw'ssetup-test-bunaction installs. After one account ran a lifecycle install, another account'sbun add -g --trustfailed in protobufjs'snode scripts/postinstall. A private/tmpfor 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./tmp/bun-node-<uid>-<sha>(debug builds:-debug;/private/tmpon macOS,/data/local/tmpon Android as before). This is the scheme upstream oven-sh/bun#35565 proposes (open and unmerged since July) and the one thebunx-<uid>-*cache already uses. Upstream issue: oven-sh/bun#42048.RunCommand::BUN_NODE_DIR(aconst) becomesRunCommand::bun_node_dir(), memoized, since the uid is a runtime value.bun_node_file_utf8()still returns the directory on POSIX, as before.0700create + ownership/mode tamper guard is unchanged; it now protects a per-user path instead of a shared one.delete_tree_absoluteof the shim directory. It raced concurrent debug processes that share the directory, and the existingEEXISTreadlink re-point already replaces stale links.%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).test/cli/install/bun-install-lifecycle-scripts.test.ts, next to the node-gyp shim test: a rootpostinstall: node probe.mjswith aPATHthat contains nonodemust run under Bun, through a shim directory named for the current uid, owned by the current user, mode0700.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
userauid 1001 anduserbuid 1002; Node.js removed sonodeis not on either user'sPATH). The probe project has a rootpostinstall: node probe.mjsand a trustedfile:dependencyprobe-depwith the samepostinstall; each probe printstypeof Bun, the uid, and thebun-nodePATHentry. The install runs assudo -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+ddfce5d01binary (both checksums from the openclaw/openclaw action verified):A from-source release build of
openclaw/mainat76d5d1294freproduced 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 matchesgit diff openclaw/main HEAD):Regression test:
Expected /^bun-node-1000(-|$)/, Received: "bun-node-ddfce5d01").bun bd test, andUSE_SYSTEM_BUN=1(stock 1.4.2) fails withReceived: "bun-node-744846f84".test/cli/run/as-node.test.ts(11/11) pass.test/cli/install/bun-run.test.tsis 286 pass / 10 fail. All 10 failures reproduce identically on a clean debug build ofopenclaw/mainon the same Mac: twoSIGILLexpectations, and eight cases where the local shell can't findbun-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-allcompleted only forx86_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
/tmp/bun-node-<uid>-<sha>, the guard still refuses it and skips the shim silently. Warning, or falling back to a privatemkdtempdirectory, would make that visible. The collision between ordinary users is gone./tmp, not$TMPDIR. This keeps parity with upstream run: scope the --bun node shim directory by uid oven-sh/bun#35565.