Skip to content

Commit ffc102a

Browse files
authored
fix(cli): verify forward listener before success (ai-openshell#1880)
* fix(cli): verify forward listener before success Wait for a connectable local forward listener before reporting foreground forwarding success. Fail background forwarding when the forked SSH process cannot be tracked, probe the listener before writing the PID file, and terminate the tracked SSH process if the listener never opens. Document that forwarded URLs are printed only after listener health is proven. Signed-off-by: Shiju <shiju@nvidia.com> * fix(cli): harden background forward cleanup Signed-off-by: Shiju <shiju@nvidia.com> * fix(cli): validate background forward cleanup pid Signed-off-by: Shiju <shiju@nvidia.com> * fix(cli): harden forward PID matching and teardown Require background forward cleanup to prove a candidate PID is the OpenShell-generated SSH forwarding process before reporting it active or signaling it. Match the exact -L forward argument and sandbox ID instead of by substring, so a request for port 80 cannot collide with an existing 8080 forward and terminate the wrong process. Reject legacy PID records as non-authoritative and route port-only lookup through validated live forward state. Recover the exact process argv from /proc/<pid>/cmdline on Linux so a ProxyCommand whose executable path contains whitespace is parsed correctly; other platforms keep the best-effort ps command-line parse. After listener readiness succeeds, terminate the revalidated background ssh process if the PID-file write fails, instead of returning early and leaving a reachable but untracked forward that forward stop/list cannot manage. Cover adversarial matcher cases (port and sandbox-id collisions, command spoofing, remote-command token confusion, whitespace executable paths) and the PID-file write-failure teardown path with focused tests. Signed-off-by: Shiju <shiju@nvidia.com> --------- Signed-off-by: Shiju <shiju@nvidia.com>
1 parent f084eb3 commit ffc102a

5 files changed

Lines changed: 1333 additions & 109 deletions

File tree

‎crates/openshell-cli/src/main.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,7 +2089,7 @@ async fn main() -> Result<()> {
20892089
} else {
20902090
let name_width = forwards
20912091
.iter()
2092-
.map(|f| f.sandbox.len())
2092+
.map(|f| f.sandbox_name.len())
20932093
.max()
20942094
.unwrap_or(7)
20952095
.max(7);
@@ -2109,14 +2109,14 @@ async fn main() -> Result<()> {
21092109
bw = bind_width,
21102110
);
21112111
for f in &forwards {
2112-
let status = if f.alive {
2112+
let status = if f.validated_alive {
21132113
"running".green().to_string()
21142114
} else {
21152115
"dead".red().to_string()
21162116
};
21172117
println!(
21182118
"{:<nw$} {:<bw$} {:<8} {:<10} {}",
2119-
f.sandbox,
2119+
f.sandbox_name,
21202120
f.bind_addr,
21212121
f.port,
21222122
f.pid,

0 commit comments

Comments
 (0)