Repository navigation
Conversation
The CLI, the TUI, and generated SSH config entries accepted any SSH host key. They now run ssh with StrictHostKeyChecking=yes against a per-sandbox known-hosts file. The ssh-proxy relay reads the host key from the server's key exchange reply, pins it only when its SHA-256 fingerprint equals the one the gateway published, and withholds the reply otherwise. A sandbox with no published fingerprint is refused unless OPENSHELL_SSH_ALLOW_UNVERIFIED_HOST_KEY=1 is set. SSH config entries generated by earlier releases are refused with the command that regenerates them. Signed-off-by: Adrien Langou <alangou@nvidia.com>
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
|
🌿 Preview your docs: https://nvidia-preview-pr-5703.docs.buildwithfern.com/openshell |
Restore the base shape of the SSH option and proxy-command helpers where the feature does not need a new one, fold duplicate tests into tables, and drop tests that repeat a proof at a more expensive level. No change to what is verified or refused. Signed-off-by: Adrien Langou <alangou@nvidia.com>
|
Label |
|
/ok to test 3cdb3a9 |
Compatibility review (advisory)New or updated breaking changes; see the full report for all findings. 1. cli — No explicit risk acceptance found
2. cli — No explicit risk acceptance found
3. configuration — No explicit risk acceptance foundAn existing setting such as
Review details
Advisory review; publication gates are unchanged. |
Address the compatibility review of the host key verification change. A sandbox with no published fingerprint connects with a warning instead of being refused, so gateways that predate sandbox SSH identities keep working. The OPENSHELL_SSH_ALLOW_UNVERIFIED_HOST_KEY opt-out is no longer needed. SSH config entries and running clients from an earlier release keep working: ssh-proxy relays without a check and warns, since their ssh accepts any host key anyway. A '%' in the config directory is escaped for ssh instead of rejected. Harden the relay gate: an identification line is at most 255 bytes, so the gate and every ssh release hand over to packets at the same byte, and a group exchange reply is accepted only after its group. Signed-off-by: Adrien Langou <alangou@nvidia.com>
|
/ok to test ee95035 |
Compatibility review (advisory)New or updated breaking changes; see the full report for all findings. 1. configuration — No explicit risk acceptance foundSSH operations previously accepted XDG_CONFIG_HOME/HOME paths containing double quotes, Unix backslashes, or literal '${', but now reject them as unusable known-hosts paths.
Review details
Advisory review; publication gates are unchanged. |
Signed-off-by: Adrien Langou <alangou@nvidia.com>
|
/ok to test 261ba4c |
OPENSHELL_SSH_REQUIRE_HOST_KEY turns the two unverified cases, a sandbox with no published fingerprint and a caller that predates host-key verification, from a warning into a refusal. It is off by default. Signed-off-by: Adrien Langou <alangou@nvidia.com>
|
/ok to test ffc6aee |
|
Accepted risk |
FrostGod
left a comment
There was a problem hiding this comment.
Nice work, the gate is really careful. A few general thoughts:
- Threat model: the gateway is both the fingerprint source and the transport. Could the PR say what this actually catches? Relay routed to the wrong supervisor, stale supervisor, spoofed sshd socket? A compromised gateway isn't covered.
- Default: should we turn
OPENSHELL_SSH_REQUIRE_HOST_KEYon by default in the next major release, with an opt-out and a release note? Curious what you think. - macOS: could you check this on macOS too?
- #557: not sure that one is worth doing. The gateway reaches sshd through the relay on the supervisor's own authenticated session, then a Unix socket, so there's no network hop to MITM, and the gateway issued the key in the first place. Also #557 is closed, so maybe drop it from the out-of-scope list?
| /// The server-to-client side of the `ssh-proxy` relay. Holds back the server's | ||
| /// key exchange reply until the host key in it is checked and pinned. | ||
| #[derive(Debug)] | ||
| pub struct HostKeyGate { | ||
| check: HostKeyCheck, | ||
| phase: GatePhase, | ||
| /// Bytes not yet released. Its head is the line or packet being decided. | ||
| buffer: Vec<u8>, | ||
| } | ||
|
|
||
| /// What the gate waits for: the identification line, then the cleartext | ||
| /// packets of a key exchange in the only order the server may send them. `ssh` | ||
| /// can discard a packet outside this order, so a gate that let one through | ||
| /// could be shown one host key while `ssh` acts on another. | ||
| #[derive(Clone, Copy, Debug)] | ||
| enum GatePhase { | ||
| Banner, | ||
| KexInit, | ||
| /// The reply, or before it the group of a group exchange. | ||
| GroupOrReply, | ||
| Reply, | ||
| NewKeys, | ||
| Done, | ||
| } | ||
|
|
||
| impl HostKeyGate { | ||
| /// Feed bytes read from the gateway; returns the bytes that may be written | ||
| /// to `ssh` now. Lines are released whole up to the `SSH-` identification | ||
| /// line. Then exactly these packets are released whole, in this order: | ||
| /// KEXINIT, the group of a group exchange if there is one, the key | ||
| /// exchange reply once its Ed25519 host key is pinned, and NEWKEYS. | ||
| /// Everything after NEWKEYS passes through. | ||
| /// | ||
| /// On an error nothing from this call is released, and every later call | ||
| /// fails on the same line or packet. | ||
| pub fn push(&mut self, chunk: &[u8]) -> Result<Vec<u8>, HostKeyError> { | ||
| self.buffer.extend_from_slice(chunk); | ||
| let mut released = Vec::new(); | ||
| while let Some(len) = self.releasable()? { | ||
| released.extend(self.buffer.drain(..len)); | ||
| } | ||
| Ok(released) | ||
| } | ||
|
|
||
| /// The length of the buffer's head that may be released, or `None` when | ||
| /// deciding needs more bytes. An error leaves the head in place. | ||
| fn releasable(&mut self) -> Result<Option<usize>, HostKeyError> { | ||
| match self.phase { | ||
| GatePhase::Banner => { | ||
| let head = &self.buffer[..self.buffer.len().min(MAX_BANNER_LINE_LEN)]; | ||
| let Some(newline) = head.iter().position(|&byte| byte == b'\n') else { | ||
| return if head.len() == MAX_BANNER_LINE_LEN { | ||
| Err(HostKeyError::Malformed("identification line is too long")) | ||
| } else { | ||
| Ok(None) | ||
| }; | ||
| }; | ||
| if head.starts_with(b"SSH-") { | ||
| self.phase = GatePhase::KexInit; | ||
| } | ||
| Ok(Some(newline + 1)) | ||
| } | ||
| GatePhase::Done => Ok((!self.buffer.is_empty()).then_some(self.buffer.len())), | ||
| awaited => { | ||
| let Some((length, rest)) = self.buffer.split_first_chunk::<4>() else { | ||
| return Ok(None); | ||
| }; | ||
| let length = usize::try_from(u32::from_be_bytes(*length)) | ||
| .ok() | ||
| .filter(|length| PACKET_LENGTHS.contains(length)) | ||
| .ok_or(HostKeyError::Malformed("packet length is out of range"))?; | ||
| let Some(packet) = rest.get(..length) else { | ||
| return Ok(None); | ||
| }; | ||
| let padding = usize::from(packet[0]); | ||
| let (message, fields) = packet | ||
| .get(1..length.saturating_sub(padding)) | ||
| .and_then(<[u8]>::split_first) | ||
| .ok_or(HostKeyError::Malformed("packet padding leaves no payload"))?; | ||
| self.phase = self.check.phase_after(awaited, *message, fields)?; | ||
| Ok(Some(4 + length)) | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
The gate is careful, but it's a hand-written SSH packet parser in the CLI. If CreateSshSessionResponse returned the public key and not just the fingerprint, we could write known_hosts directly and let ssh do the whole check. Was that ruled out only to avoid a proto change?
| fn under(config_dir: &Path, target: &SandboxSshTarget<'_>) -> Result<Self, HostKeyError> { | ||
| let alias = host_key_alias(target.sandbox, target.workspace); | ||
| // A gateway reached by its endpoint alone is named by its URL. | ||
| let gateway = target.gateway.replace( | ||
| |ch: char| !ch.is_ascii_alphanumeric() && !matches!(ch, '.' | '-' | '_'), | ||
| "_", | ||
| ); | ||
| let path = config_dir.join("known_hosts").join(&gateway).join(&alias); |
There was a problem hiding this comment.
The pin is keyed by sandbox name, but the docs (overview.mdx:890) say "pin it to the sandbox ID". Fine, since the gateway rewrites it anyway, but let's make the wording match.
| // user as is, and a returned error would be reformatted as | ||
| // a report. | ||
| eprintln!("openshell: {refusal}"); | ||
| std::process::exit(1) |
There was a problem hiding this comment.
process::exit(1) from inside the async relay skips cleanup. Probably fine for a ProxyCommand, but returning a dedicated error and exiting from main would be tidier.
| .collect::<Vec<_>>() | ||
| .join("\n"); | ||
| Ok(format!( | ||
| "Host {host_alias}\n User sandbox\n{options}\n ControlMaster no\n ControlPath none\n ControlPersist no\n LogLevel ERROR\n ServerAliveInterval 15\n ServerAliveCountMax 3\n ProxyCommand {proxy_cmd}\n" |
There was a problem hiding this comment.
Why add ControlMaster no to the generated config? Each alias is already per sandbox, so sharing was safe. VS Code Remote users may lose multiplexing. Looks unrelated to host-key checks; split it out?
|
|
||
| fn host_alias(name: &str, workspace: &str) -> String { | ||
| format!("openshell-{name}.{workspace}") | ||
| fn stale_ssh_config_warning(gateway: Option<&str>, workspace: &str, sandbox: &str) -> String { |
There was a problem hiding this comment.
We own the managed include file (install_ssh_config), so we could silently rewrite stale blocks there on the next sandbox connect. That would leave the warning only for hand-pasted entries.
| disable_raw_mode().into_diagnostic()?; | ||
|
|
||
| // Step 8: Spawn SSH as child process and wait. | ||
| if let Some(warning) = unverified_warning { |
There was a problem hiding this comment.
This prints just before ssh takes the terminal, so it's easy to miss. Show it in the status bar too? Same at L1181.
A generated entry has one host alias per sandbox, so a shared connection never reaches another sandbox. Stop disabling ControlMaster there. Also name the missing flags in the ssh-proxy warning, note that the gateway issues only Ed25519 host keys, and document that the fingerprint is read per connection and that unverified connections are allowed by default. Signed-off-by: Adrien Langou <alangou@nvidia.com>
Compatibility review (advisory)New or updated breaking changes; see the full report for all findings. 1. configuration — Risk explicitly acceptedSSH operations previously accepted XDG_CONFIG_HOME/HOME paths containing double quotes, literal '${', newlines, or Unix backslashes, but now reject them as unusable known-hosts paths.
Review details
Advisory review; publication gates are unchanged. |
The host alias of an entry names the sandbox and the workspace, not the gateway. With a user's persistent ControlMaster, ssh reused a connection opened to one gateway's sandbox for the entry of the same sandbox name on another gateway, and ran no host key check. Restore the three options that turn sharing off for the entry. Signed-off-by: Adrien Langou <alangou@nvidia.com>
Summary
The CLI, the TUI, and generated SSH config entries accepted any SSH host key from a sandbox. They now check it against the fingerprint the gateway publishes, so a connection that reaches the wrong SSH server fails before authentication.
Related Issue
Follow-on to #3835 (item 4 of its design, "CLI and TUI verify against the fingerprint"). #3835 is closed, so this PR needs its own tracking issue before it leaves draft.
Changes
sshruns withStrictHostKeyChecking=yesagainst one known-hosts file per sandbox, under<config>/openshell/known_hosts/<gateway>/. Other trust sources are disabled.ssh-proxyreads the host key from the server's key exchange reply. It pins the key only when its SHA-256 fingerprint equals the published one, and withholds the reply otherwise. It accepts only the exact cleartext sequence a server sends beforeNEWKEYS.openshell_core::ssh_host_keyowns the fingerprint format, the pin file, thesshoptions, and the relay check.sandbox_ssh_argscannot be called without it.OPENSHELL_SSH_REQUIRE_HOST_KEY=1refuses those unverified connections instead. It is off by default.Accepted risk: a config directory whose path contains
",${, a newline, or a backslash on Unix cannot hold the known-hosts file, becausesshhas no way to take such a path inUserKnownHostsFile. SSH commands fail there withSSH known-hosts path ... cannot be used. The fix is to setXDG_CONFIG_HOMEto a path without them. An indirection through a second path would add code for a case no report describes.Out of scope: the gateway's own SSH client for
ExecSandbox(#557), and a readable multi-line refusal in the TUI, which stays a one-line status.Release Notes
OpenShell clients now verify the sandbox SSH host key on every SSH connection they open.
OPENSHELL_SSH_REQUIRE_HOST_KEY=1to refuse unverified connections instead of connecting with a warning.",${, a newline, or a backslash on Unix. SetXDG_CONFIG_HOMEto a path without them.Testing
Ran on Linux with OpenSSH 10.0p2:
cargo testforopenshell-core,openshell-cli, andopenshell-tui,cargo clippy --all-targets -D warningson the same crates,cargo fmt --check, and the lockfile check.ssh_proxy_host_key_integrationruns the realsshbinary through the builtopenshell ssh-proxyagainst a russh server: the published key connects, another key is refused before any command runs, a stale pin is replaced, andsshrefuses a key missing from its own known-hosts file. Two of these run with a%in the config directory. The same file checks that a caller without the new flags, and a gateway that publishes nothing, are relayed with a warning, and are refused whenOPENSHELL_SSH_REQUIRE_HOST_KEYis set.Not run locally: the E2E suites, macOS, and OpenSSH 8.x. The existing conformance test
ssh_host_identity_stable_across_stop_start_and_new_on_recreateexercises the relay check against a real supervisor in CI.Checklist