fix: add fallback from rbash to bash/zsh/sh for command execution#2629
fix: add fallback from rbash to bash/zsh/sh for command execution#2629majiayu000 wants to merge 2 commits intoantinomyhq:mainfrom
Conversation
When the default shell is set to rbash, shell commands fail because rbash restricts many operations needed for normal command execution. This adds a resolve_shell() function that detects rbash and falls back to /bin/bash, /bin/zsh, or /bin/sh (in that order), applied in both the environment shell resolution and the command executor. Closes antinomyhq#2559 Signed-off-by: majiayu000 <1835304752@qq.com>
|
|
crates/forge_infra/src/executor.rs
Outdated
| let is_windows = cfg!(target_os = "windows"); | ||
| let shell = if self.restricted && !is_windows { | ||
| "rbash" | ||
| crate::env::resolve_shell("rbash") |
There was a problem hiding this comment.
Inconsistent shell path usage will cause command execution to fail. This line passes "rbash" (bare command name) to resolve_shell(), but if all fallback shells are missing, it returns "rbash" which may not be in PATH. Line 51 in env.rs correctly uses "/bin/rbash" (full path). This inconsistency means:
env.rsrestricted mode: tries/bin/rbash→ falls back to/bin/bash|/bin/zsh|/bin/sh→ worst case returns/bin/rbashexecutor.rsrestricted mode: triesrbash→ falls back to/bin/bash|/bin/zsh|/bin/sh→ worst case returnsrbash
If fallbacks don't exist, Command::new("rbash") will fail with "command not found" since rbash without a path requires it to be in PATH.
Fix:
crate::env::resolve_shell("/bin/rbash")| crate::env::resolve_shell("rbash") | |
| crate::env::resolve_shell("/bin/rbash") |
Spotted by Graphite
Is this helpful? React 👍 or 👎 to let us know.
Replace resolve_shell() fallback logic with simply using bash instead of rbash, as suggested in PR antinomyhq#2629 review. Signed-off-by: majiayu000 <1835304752@qq.com>
Fixes #2559
Summary
When the user's default shell is
rbash(restricted bash), ForgeCode fails becauserbashrestricts path execution and directory operations.This PR adds fallback logic so that when
rbashis detected, the shell resolution falls back through/bin/bash→/bin/zsh→/bin/sh.Changes
crates/forge_infra/src/env.rs: Addedresolve_shell()helper that detects rbash and returns the first available fallback shell. Applied in both restricted and non-restricted paths ofget_shell_path().crates/forge_infra/src/executor.rs: Updatedprepare_command()to useresolve_shell()so the actual command execution also avoids rbash.Test Plan
cargo check --all-features --workspacepassescargo test --all-features --workspacepassesrbash,/bin/rbash,/usr/bin/rbash) and falls back to bash/zsh/sh