From 2b829651f441ae3bdb8764f0d6edba15eb765c99 Mon Sep 17 00:00:00 2001 From: Piotr Mlocek Date: Thu, 3 Dec 2026 15:42:59 -0700 Subject: [PATCH 1/2] feat(ssh): forward sandbox Unix sockets Signed-off-by: Piotr Mlocek --- crates/openshell-cli/src/main.rs | 26 ++- crates/openshell-cli/src/ssh.rs | 87 ++++++++- .../openshell-supervisor-process/src/ssh.rs | 41 ++++ .../src/ssh/streamlocal.py | 45 +++++ .../src/ssh/streamlocal.rs | 176 ++++++++++++++++++ docs/how-it-works/sandboxes/overview.mdx | 4 + skills/openshell-cli/SKILL.md | 2 +- 7 files changed, 373 insertions(+), 8 deletions(-) create mode 100644 crates/openshell-supervisor-process/src/ssh/streamlocal.py create mode 100644 crates/openshell-supervisor-process/src/ssh/streamlocal.rs diff --git a/crates/openshell-cli/src/main.rs b/crates/openshell-cli/src/main.rs index 5cca485033..4b26c7a103 100644 --- a/crates/openshell-cli/src/main.rs +++ b/crates/openshell-cli/src/main.rs @@ -1950,6 +1950,14 @@ enum SandboxCommands { /// enabling tools like `VSCode` Remote-SSH to connect to the sandbox. #[command(help_template = LEAF_HELP_TEMPLATE, next_help_heading = "FLAGS")] SshConfig { + /// Install the host entry in the OpenShell-managed SSH configuration and print its alias. + #[arg(long)] + install: bool, + + /// Host alias to install. The default alias includes the sandbox and workspace. + #[arg(long, requires = "install")] + alias: Option, + /// Sandbox name (defaults to last-used sandbox). #[arg(add = ArgValueCompleter::new(completers::complete_sandbox_names))] name: Option, @@ -3943,9 +3951,23 @@ async fn run_async() -> Result<()> { std::process::exit(exit_code); } } - SandboxCommands::SshConfig { name } => { + SandboxCommands::SshConfig { + install, + alias, + name, + } => { let name = resolve_sandbox_name(name, &ctx.name, &cli.workspace)?; - run::print_ssh_config(&ctx.name, &name, &cli.workspace)?; + if install { + let alias = openshell_cli::ssh::install_ssh_alias( + &ctx.name, + &name, + &cli.workspace, + alias.as_deref(), + )?; + println!("{alias}"); + } else { + run::print_ssh_config(&ctx.name, &name, &cli.workspace)?; + } } SandboxCommands::Provider(command) => match command { SandboxProviderCommands::List { diff --git a/crates/openshell-cli/src/ssh.rs b/crates/openshell-cli/src/ssh.rs index 0417316414..894c4f7cc9 100644 --- a/crates/openshell-cli/src/ssh.rs +++ b/crates/openshell-cli/src/ssh.rs @@ -2476,6 +2476,15 @@ fn stale_ssh_config_warning(gateway: &str, workspace: &str, sandbox: &str) -> St } fn render_ssh_config(gateway: &str, name: &str, workspace: &str) -> Result { + render_ssh_config_for_alias(gateway, name, workspace, &host_alias(name, workspace)) +} + +fn render_ssh_config_for_alias( + gateway: &str, + name: &str, + workspace: &str, + host_alias: &str, +) -> Result { let exe = std::env::current_exe().into_diagnostic()?; let (selector, target) = match gateway.split_once("://") { Some((scheme, rest)) @@ -2513,7 +2522,6 @@ fn render_ssh_config(gateway: &str, name: &str, workspace: &str) -> Result String { } pub fn install_ssh_config(gateway: &str, name: &str, workspace: &str) -> Result { - let block = render_ssh_config(gateway, name, workspace)?; + install_ssh_config_for_alias(gateway, name, workspace, &host_alias(name, workspace)) +} + +pub fn install_ssh_alias( + gateway: &str, + name: &str, + workspace: &str, + alias: Option<&str>, +) -> Result { + let alias = alias.map_or_else(|| host_alias(name, workspace), str::to_owned); + if alias.len() > 253 + || !alias + .as_bytes() + .first() + .is_some_and(u8::is_ascii_alphanumeric) + || !alias + .bytes() + .all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'.' | b'-')) + { + return Err(miette::miette!( + "SSH alias must start with a letter or digit and contain only letters, digits, periods or hyphens" + )); + } + install_ssh_config_for_alias(gateway, name, workspace, &alias)?; + Ok(alias) +} + +fn install_ssh_config_for_alias( + gateway: &str, + name: &str, + workspace: &str, + alias: &str, +) -> Result { + let block = render_ssh_config_for_alias(gateway, name, workspace, alias)?; let managed_config = openshell_ssh_config_path()?; let main_config = user_ssh_config_path()?; - ensure_openshell_include(&main_config, &managed_config)?; if let Some(parent) = managed_config.parent() { openshell_core::paths::create_dir_restricted(parent)?; } + if let Some(parent) = main_config.parent() { + fs::create_dir_all(parent) + .into_diagnostic() + .wrap_err("failed to create ~/.ssh directory")?; + } + let lock = fs::OpenOptions::new() + .write(true) + .create(true) + .truncate(false) + .open(main_config.with_file_name("config.openshell.lock")) + .into_diagnostic() + .wrap_err("failed to open the OpenShell SSH configuration lock")?; + lock.lock() + .into_diagnostic() + .wrap_err("failed to lock the OpenShell SSH configuration")?; + ensure_openshell_include(&main_config, &managed_config)?; - let alias = host_alias(name, workspace); let contents = fs::read_to_string(&managed_config).unwrap_or_default(); - let updated = replace_earlier_release_entries(&upsert_host_block(&contents, &alias, &block)); + let updated = replace_earlier_release_entries(&upsert_host_block(&contents, alias, &block)); fs::write(&managed_config, updated) .into_diagnostic() .wrap_err("failed to write OpenShell SSH config")?; @@ -3265,6 +3320,28 @@ mod tests { }); } + #[test] + fn install_ssh_alias_keeps_same_named_sandboxes_on_distinct_gateways() { + let home = tempfile::tempdir().unwrap(); + let xdg = tempfile::tempdir().unwrap(); + Environment::new() + .set("HOME", home.path()) + .set("XDG_CONFIG_HOME", xdg.path()) + .run(|| { + for (gateway, alias) in [("one", "rex-demo-one"), ("two", "rex-demo-two")] { + assert_eq!( + install_ssh_alias(gateway, "demo", "default", Some(alias)).unwrap(), + alias, + ); + } + assert!(install_ssh_alias("one", "demo", "default", Some("*")).is_err()); + let config = fs::read_to_string(openshell_ssh_config_path().unwrap()).unwrap(); + assert!(config.contains("Host rex-demo-one")); + assert!(config.contains("Host rex-demo-two")); + assert_eq!(config.matches("StrictHostKeyChecking yes").count(), 2); + }); + } + #[test] fn install_ssh_config_replaces_the_entries_an_earlier_release_wrote() { let home = tempfile::tempdir().unwrap(); diff --git a/crates/openshell-supervisor-process/src/ssh.rs b/crates/openshell-supervisor-process/src/ssh.rs index a11eddbd21..22719382b5 100644 --- a/crates/openshell-supervisor-process/src/ssh.rs +++ b/crates/openshell-supervisor-process/src/ssh.rs @@ -4,6 +4,7 @@ //! Embedded SSH server for sandbox access. mod input; +mod streamlocal; mod upload; #[cfg(test)] @@ -633,6 +634,28 @@ impl russh::server::Handler for SshHandler { Ok(()) } + async fn channel_open_direct_streamlocal( + &mut self, + channel: russh::Channel, + socket_path: &str, + reply: ChannelOpenHandle, + _session: &mut Session, + ) -> Result<(), Self::Error> { + if !streamlocal::is_workspace_socket(socket_path) { + reply + .reject(ChannelOpenFailure::AdministrativelyProhibited) + .await; + return Ok(()); + } + tokio::spawn(streamlocal::forward( + self.boundary_exec.clone(), + socket_path.to_owned(), + channel, + reply, + )); + Ok(()) + } + async fn pty_request( &mut self, channel: ChannelId, @@ -1950,6 +1973,24 @@ mod tests { } } + #[tokio::test] + async fn direct_streamlocal_rejects_outside_workspace_and_failed_exec() { + let client = authenticated_test_client().await; + for (path, failure) in [ + ( + "/run/openshell/control.sock", + ChannelOpenFailure::AdministrativelyProhibited, + ), + ("/sandbox/listener.sock", ChannelOpenFailure::ConnectFailed), + ] { + let error = client + .channel_open_direct_streamlocal(path) + .await + .expect_err("channel opening must fail"); + assert!(matches!(error, russh::Error::ChannelOpenFailure(code) if code == failure)); + } + } + #[tokio::test] async fn direct_tcpip_handler_relays_loopback_bytes() { use tokio::io::{AsyncReadExt as _, AsyncWriteExt as _}; diff --git a/crates/openshell-supervisor-process/src/ssh/streamlocal.py b/crates/openshell-supervisor-process/src/ssh/streamlocal.py new file mode 100644 index 0000000000..a9508ab67a --- /dev/null +++ b/crates/openshell-supervisor-process/src/ssh/streamlocal.py @@ -0,0 +1,45 @@ +# SPDX-License-Identifier: Apache-2.0 + +import os +import socket +import stat +import sys +import threading +from contextlib import ExitStack + + +def connect(path, sock): + parts = path.split("/")[2:] + with ExitStack() as fds: + directory = os.open("/sandbox", os.O_PATH | os.O_DIRECTORY | os.O_NOFOLLOW) + fds.callback(os.close, directory) + for part in parts[:-1]: + directory = os.open( + part, os.O_PATH | os.O_DIRECTORY | os.O_NOFOLLOW, dir_fd=directory + ) + fds.callback(os.close, directory) + endpoint = os.open(parts[-1], os.O_PATH | os.O_NOFOLLOW, dir_fd=directory) + fds.callback(os.close, endpoint) + info = os.fstat(endpoint) + if not stat.S_ISSOCK(info.st_mode) or info.st_uid != os.geteuid(): + raise PermissionError("expected a workload-owned Unix socket") + sock.connect(f"/proc/self/fd/{endpoint}") + + +def send_input(sock): + try: + while data := os.read(0, 64 * 1024): + sock.sendall(data) + sock.shutdown(socket.SHUT_WR) + except OSError: + sock.shutdown(socket.SHUT_RDWR) + + +with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as connection: + connect(sys.argv[1], connection) + sys.stdout.buffer.write(b"\x01") + sys.stdout.buffer.flush() + threading.Thread(target=send_input, args=(connection,), daemon=True).start() + while data := connection.recv(64 * 1024): + sys.stdout.buffer.write(data) + sys.stdout.buffer.flush() diff --git a/crates/openshell-supervisor-process/src/ssh/streamlocal.rs b/crates/openshell-supervisor-process/src/ssh/streamlocal.rs new file mode 100644 index 0000000000..78a177c061 --- /dev/null +++ b/crates/openshell-supervisor-process/src/ssh/streamlocal.rs @@ -0,0 +1,176 @@ +// SPDX-License-Identifier: Apache-2.0 + +use std::{sync::Arc, time::Duration}; + +use openshell_isolation_interface::contract::ExecSpec; +use openshell_sandbox_backend::BoundaryExec; +use russh::{ + Channel, ChannelOpenFailure, + server::{ChannelOpenHandle, Msg}, +}; +use tokio::io::AsyncReadExt; + +pub(super) fn is_workspace_socket(path: &str) -> bool { + path.len() <= 107 + && !path.chars().any(char::is_control) + && path.strip_prefix("/sandbox/").is_some_and(|relative| { + relative + .split('/') + .all(|part| !matches!(part, "" | "." | "..")) + }) +} + +pub(super) async fn forward( + boundary: Arc, + path: String, + channel: Channel, + reply: ChannelOpenHandle, +) { + // The ordinary exec path applies the sandbox identity, Landlock and seccomp + // before the relay opens a socket. The supervisor never resolves the path. + let spec = ExecSpec { + program: "python3".into(), + args: vec![ + "-I".into(), + "-S".into(), + "-c".into(), + include_str!("streamlocal.py").into(), + path, + ], + shell: None, + runtime_helper: None, + env: Vec::new(), + workdir: None, + pty: false, + }; + let Ok(mut exec) = boundary.exec(spec).await else { + reply.reject(ChannelOpenFailure::ConnectFailed).await; + return; + }; + let process = exec.process; + let diagnostics = exec.stderr.take().map(|mut stderr| { + tokio::spawn(async move { tokio::io::copy(&mut stderr, &mut tokio::io::sink()).await }) + }); + let mut marker = [0]; + let connected = + tokio::time::timeout(Duration::from_secs(5), exec.stdout.read_exact(&mut marker)) + .await + .is_ok_and(|result| result.is_ok()) + && marker == [1]; + match exec.stdin.take() { + Some(stdin) if connected => { + reply.accept().await; + let mut workload = tokio::io::join(exec.stdout, stdin); + let mut client = channel.into_stream(); + let _ = tokio::io::copy_bidirectional(&mut client, &mut workload).await; + drop(workload); + } + _ => reply.reject(ChannelOpenFailure::ConnectFailed).await, + } + if let Some(diagnostics) = diagnostics { + diagnostics.abort(); + } + let _ = process.terminate().await; +} + +#[cfg(test)] +mod tests { + use super::is_workspace_socket; + use crate::ssh::tests::test_client; + use openshell_isolation_interface::contract::{ + BackendError, BoundaryExitStatus, BoundarySignal, ExecSpec, + }; + use openshell_sandbox_backend::test_support as rpc_test; + use std::sync::Arc; + use tokio::io::{AsyncReadExt, AsyncWriteExt}; + + struct RelayProcess; + + #[async_trait::async_trait] + impl rpc_test::BoundaryProcess for RelayProcess { + async fn wait(&self) -> Result { + std::future::pending().await + } + + async fn signal(&self, _: BoundarySignal) -> Result<(), BackendError> { + Ok(()) + } + + async fn terminate(&self) -> Result<(), BackendError> { + Ok(()) + } + } + + struct EchoExec; + + #[async_trait::async_trait] + impl rpc_test::BoundaryExec for EchoExec { + async fn exec(&self, spec: ExecSpec) -> Result { + assert_eq!(spec.program, "python3"); + assert_eq!(spec.args.last().unwrap(), "/sandbox/echo.sock"); + assert!(spec.runtime_helper.is_none()); + let (workload, session) = tokio::io::duplex(64); + let (mut input, mut output) = tokio::io::split(workload); + tokio::spawn(async move { + output.write_all(&[1]).await.unwrap(); + tokio::io::copy(&mut input, &mut output).await.unwrap(); + }); + let (stdout, stdin) = tokio::io::split(session); + Ok(rpc_test::ExecSession { + process: Arc::new(RelayProcess), + stdin: Some(Box::new(stdin)), + stdout: Box::new(stdout), + stderr: None, + terminal: None, + output_status: None, + }) + } + } + + #[tokio::test] + async fn forwards_channel_bytes_after_the_workload_connects() { + let client = test_client( + None, + rpc_test::exec(Arc::new(EchoExec)), + russh::client::Config::default(), + ) + .await; + let mut channel = client + .channel_open_direct_streamlocal("/sandbox/echo.sock") + .await + .unwrap() + .into_stream(); + channel.write_all(b"ping").await.unwrap(); + let mut reply = [0; 4]; + tokio::time::timeout( + std::time::Duration::from_secs(5), + channel.read_exact(&mut reply), + ) + .await + .expect("echo timed out") + .unwrap(); + assert_eq!(&reply, b"ping"); + } + + #[test] + fn streamlocal_paths_must_name_a_socket_under_the_workspace() { + assert!(is_workspace_socket("/sandbox/.rex.example/server.sock")); + for path in [ + "", + "/sandbox", + "/sandbox/", + "/sandbox-other/server.sock", + "/sandbox/../run/docker.sock", + "/sandbox/./server.sock", + "/sandbox//server.sock", + "/sandbox/line\nbreak", + "@abstract", + ] { + assert!(!is_workspace_socket(path), "{path:?}"); + } + assert!(!is_workspace_socket(&format!( + "/sandbox/{}", + "s".repeat(100) + ))); + } +} diff --git a/docs/how-it-works/sandboxes/overview.mdx b/docs/how-it-works/sandboxes/overview.mdx index 123678e9fe..5b385c2922 100644 --- a/docs/how-it-works/sandboxes/overview.mdx +++ b/docs/how-it-works/sandboxes/overview.mdx @@ -928,6 +928,10 @@ openshell sandbox ssh-config my-sandbox Append the output to `~/.ssh/config` or use `--editor` on `sandbox create`/`sandbox connect` for automatic setup. If the gateway URL contains credentials, a path, a query, or a fragment, register it under a gateway name and use that name when generating the SSH config. +Use `openshell sandbox ssh-config --install my-sandbox` to install an entry and print its host alias. Add `--alias ` to choose a distinct alias for the same sandbox name on another gateway. + +On Linux images with Python 3, OpenSSH clients can forward Unix stream sockets owned by the workload user below `/sandbox`. The connection runs with the sandbox's workload permissions. The destination path must name the socket directly without symlinks. + SSH config entries that an earlier release generated accept any host key, so connections through them are refused. Using `--editor` on `sandbox create` or `sandbox connect` replaces that sandbox's entry, and every diff --git a/skills/openshell-cli/SKILL.md b/skills/openshell-cli/SKILL.md index c89ba151ea..4128f7f04e 100644 --- a/skills/openshell-cli/SKILL.md +++ b/skills/openshell-cli/SKILL.md @@ -464,7 +464,7 @@ attachment, `Ctrl-C` or `Ctrl-D` exits the viewer and leaves main and other attachments running. Configure VS Code Remote-SSH with: ```bash -openshell sandbox ssh-config my-sandbox >> ~/.ssh/config +openshell sandbox ssh-config --install my-sandbox ``` A writable attachment that finds another attachment holding stdin reports `attached read-only; retry input after the owner disconnects`. Automatic recovery can hit this when it reattaches before the supervisor closes the dead connection. The supervisor closes a connection 60 seconds after it last received bytes from it, which can be later than 60 seconds after the network failed if the relay buffered data. After the old owner disconnects or times out, send the input you meant to type next. If stdin is free, the attachment prints `input enabled` and forwards that input to the process, so do not probe with Enter or a prompt answer such as `y`. If nothing prints, the old connection still holds stdin. Input sent while the attachment was read-only never reaches the process, so send it again later. `Ctrl-C`, `Ctrl-D`, and `Ctrl-P` then `Ctrl-Q` still exit a read-only attachment instead of enabling input; enable input first if you need `Ctrl-C` to interrupt the process. Recovery never takes stdin from a healthy owner, and an explicitly read-only attachment stays read-only. From 6e5183c84d6e6cb82829014a15ffbddd25ddcbb9 Mon Sep 17 00:00:00 2001 From: Piotr Mlocek Date: Thu, 3 Dec 2026 15:56:45 -0700 Subject: [PATCH 2/2] refactor(ssh): keep sandbox SSH config generation read-only Signed-off-by: Piotr Mlocek --- crates/openshell-cli/src/main.rs | 26 +------ crates/openshell-cli/src/ssh.rs | 87 ++---------------------- docs/how-it-works/sandboxes/overview.mdx | 2 - skills/openshell-cli/SKILL.md | 2 +- 4 files changed, 8 insertions(+), 109 deletions(-) diff --git a/crates/openshell-cli/src/main.rs b/crates/openshell-cli/src/main.rs index 4b26c7a103..5cca485033 100644 --- a/crates/openshell-cli/src/main.rs +++ b/crates/openshell-cli/src/main.rs @@ -1950,14 +1950,6 @@ enum SandboxCommands { /// enabling tools like `VSCode` Remote-SSH to connect to the sandbox. #[command(help_template = LEAF_HELP_TEMPLATE, next_help_heading = "FLAGS")] SshConfig { - /// Install the host entry in the OpenShell-managed SSH configuration and print its alias. - #[arg(long)] - install: bool, - - /// Host alias to install. The default alias includes the sandbox and workspace. - #[arg(long, requires = "install")] - alias: Option, - /// Sandbox name (defaults to last-used sandbox). #[arg(add = ArgValueCompleter::new(completers::complete_sandbox_names))] name: Option, @@ -3951,23 +3943,9 @@ async fn run_async() -> Result<()> { std::process::exit(exit_code); } } - SandboxCommands::SshConfig { - install, - alias, - name, - } => { + SandboxCommands::SshConfig { name } => { let name = resolve_sandbox_name(name, &ctx.name, &cli.workspace)?; - if install { - let alias = openshell_cli::ssh::install_ssh_alias( - &ctx.name, - &name, - &cli.workspace, - alias.as_deref(), - )?; - println!("{alias}"); - } else { - run::print_ssh_config(&ctx.name, &name, &cli.workspace)?; - } + run::print_ssh_config(&ctx.name, &name, &cli.workspace)?; } SandboxCommands::Provider(command) => match command { SandboxProviderCommands::List { diff --git a/crates/openshell-cli/src/ssh.rs b/crates/openshell-cli/src/ssh.rs index 894c4f7cc9..0417316414 100644 --- a/crates/openshell-cli/src/ssh.rs +++ b/crates/openshell-cli/src/ssh.rs @@ -2476,15 +2476,6 @@ fn stale_ssh_config_warning(gateway: &str, workspace: &str, sandbox: &str) -> St } fn render_ssh_config(gateway: &str, name: &str, workspace: &str) -> Result { - render_ssh_config_for_alias(gateway, name, workspace, &host_alias(name, workspace)) -} - -fn render_ssh_config_for_alias( - gateway: &str, - name: &str, - workspace: &str, - host_alias: &str, -) -> Result { let exe = std::env::current_exe().into_diagnostic()?; let (selector, target) = match gateway.split_once("://") { Some((scheme, rest)) @@ -2522,6 +2513,7 @@ fn render_ssh_config_for_alias( shell_escape(workspace).replace('%', "%%"), shell_escape(&pin.ssh_path()), ); + let host_alias = host_alias(name, workspace); let options = pin .ssh_options() .into_iter() @@ -2691,65 +2683,18 @@ fn upsert_host_block(contents: &str, alias: &str, block: &str) -> String { } pub fn install_ssh_config(gateway: &str, name: &str, workspace: &str) -> Result { - install_ssh_config_for_alias(gateway, name, workspace, &host_alias(name, workspace)) -} - -pub fn install_ssh_alias( - gateway: &str, - name: &str, - workspace: &str, - alias: Option<&str>, -) -> Result { - let alias = alias.map_or_else(|| host_alias(name, workspace), str::to_owned); - if alias.len() > 253 - || !alias - .as_bytes() - .first() - .is_some_and(u8::is_ascii_alphanumeric) - || !alias - .bytes() - .all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'.' | b'-')) - { - return Err(miette::miette!( - "SSH alias must start with a letter or digit and contain only letters, digits, periods or hyphens" - )); - } - install_ssh_config_for_alias(gateway, name, workspace, &alias)?; - Ok(alias) -} - -fn install_ssh_config_for_alias( - gateway: &str, - name: &str, - workspace: &str, - alias: &str, -) -> Result { - let block = render_ssh_config_for_alias(gateway, name, workspace, alias)?; + let block = render_ssh_config(gateway, name, workspace)?; let managed_config = openshell_ssh_config_path()?; let main_config = user_ssh_config_path()?; + ensure_openshell_include(&main_config, &managed_config)?; if let Some(parent) = managed_config.parent() { openshell_core::paths::create_dir_restricted(parent)?; } - if let Some(parent) = main_config.parent() { - fs::create_dir_all(parent) - .into_diagnostic() - .wrap_err("failed to create ~/.ssh directory")?; - } - let lock = fs::OpenOptions::new() - .write(true) - .create(true) - .truncate(false) - .open(main_config.with_file_name("config.openshell.lock")) - .into_diagnostic() - .wrap_err("failed to open the OpenShell SSH configuration lock")?; - lock.lock() - .into_diagnostic() - .wrap_err("failed to lock the OpenShell SSH configuration")?; - ensure_openshell_include(&main_config, &managed_config)?; + let alias = host_alias(name, workspace); let contents = fs::read_to_string(&managed_config).unwrap_or_default(); - let updated = replace_earlier_release_entries(&upsert_host_block(&contents, alias, &block)); + let updated = replace_earlier_release_entries(&upsert_host_block(&contents, &alias, &block)); fs::write(&managed_config, updated) .into_diagnostic() .wrap_err("failed to write OpenShell SSH config")?; @@ -3320,28 +3265,6 @@ mod tests { }); } - #[test] - fn install_ssh_alias_keeps_same_named_sandboxes_on_distinct_gateways() { - let home = tempfile::tempdir().unwrap(); - let xdg = tempfile::tempdir().unwrap(); - Environment::new() - .set("HOME", home.path()) - .set("XDG_CONFIG_HOME", xdg.path()) - .run(|| { - for (gateway, alias) in [("one", "rex-demo-one"), ("two", "rex-demo-two")] { - assert_eq!( - install_ssh_alias(gateway, "demo", "default", Some(alias)).unwrap(), - alias, - ); - } - assert!(install_ssh_alias("one", "demo", "default", Some("*")).is_err()); - let config = fs::read_to_string(openshell_ssh_config_path().unwrap()).unwrap(); - assert!(config.contains("Host rex-demo-one")); - assert!(config.contains("Host rex-demo-two")); - assert_eq!(config.matches("StrictHostKeyChecking yes").count(), 2); - }); - } - #[test] fn install_ssh_config_replaces_the_entries_an_earlier_release_wrote() { let home = tempfile::tempdir().unwrap(); diff --git a/docs/how-it-works/sandboxes/overview.mdx b/docs/how-it-works/sandboxes/overview.mdx index 5b385c2922..e13c2c0dac 100644 --- a/docs/how-it-works/sandboxes/overview.mdx +++ b/docs/how-it-works/sandboxes/overview.mdx @@ -928,8 +928,6 @@ openshell sandbox ssh-config my-sandbox Append the output to `~/.ssh/config` or use `--editor` on `sandbox create`/`sandbox connect` for automatic setup. If the gateway URL contains credentials, a path, a query, or a fragment, register it under a gateway name and use that name when generating the SSH config. -Use `openshell sandbox ssh-config --install my-sandbox` to install an entry and print its host alias. Add `--alias ` to choose a distinct alias for the same sandbox name on another gateway. - On Linux images with Python 3, OpenSSH clients can forward Unix stream sockets owned by the workload user below `/sandbox`. The connection runs with the sandbox's workload permissions. The destination path must name the socket directly without symlinks. SSH config entries that an earlier release generated accept any host key, so diff --git a/skills/openshell-cli/SKILL.md b/skills/openshell-cli/SKILL.md index 4128f7f04e..c89ba151ea 100644 --- a/skills/openshell-cli/SKILL.md +++ b/skills/openshell-cli/SKILL.md @@ -464,7 +464,7 @@ attachment, `Ctrl-C` or `Ctrl-D` exits the viewer and leaves main and other attachments running. Configure VS Code Remote-SSH with: ```bash -openshell sandbox ssh-config --install my-sandbox +openshell sandbox ssh-config my-sandbox >> ~/.ssh/config ``` A writable attachment that finds another attachment holding stdin reports `attached read-only; retry input after the owner disconnects`. Automatic recovery can hit this when it reattaches before the supervisor closes the dead connection. The supervisor closes a connection 60 seconds after it last received bytes from it, which can be later than 60 seconds after the network failed if the relay buffered data. After the old owner disconnects or times out, send the input you meant to type next. If stdin is free, the attachment prints `input enabled` and forwards that input to the process, so do not probe with Enter or a prompt answer such as `y`. If nothing prints, the old connection still holds stdin. Input sent while the attachment was read-only never reaches the process, so send it again later. `Ctrl-C`, `Ctrl-D`, and `Ctrl-P` then `Ctrl-Q` still exit a read-only attachment instead of enabling input; enable input first if you need `Ctrl-C` to interrupt the process. Recovery never takes stdin from a healthy owner, and an explicitly read-only attachment stays read-only.