Skip to content

feat(cli)!: verify sandbox SSH host keys - #5703

Merged
alangou merged 9 commits into
mainfrom
feat/verify-sandbox-ssh-host-keys/alangou
Nov 26, 2026
Merged

alangou merged 9 commits into
mainfrom
feat/verify-sandbox-ssh-host-keys/alangou

Conversation

@alangou

@alangou alangou commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

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. A connection they cannot verify is refused.

This catches a relay that routes the connection to the wrong supervisor, a supervisor left over from a deleted sandbox, and another process answering on the sandbox's SSH socket. It does not cover a compromised gateway: the gateway is both the source of the fingerprint and the transport, so it can publish the fingerprint of a key it holds.

Related Issue

Follow-on to #3835 (item 4 of its design, "CLI and TUI verify against the fingerprint").

Changes

  • ssh runs with StrictHostKeyChecking=yes against one known-hosts file per sandbox, under <config>/openshell/known_hosts/<gateway>/. Other trust sources are disabled.
  • ssh-proxy reads 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 before NEWKEYS.
  • New module openshell_core::ssh_host_key owns the fingerprint format, the pin file, the ssh options, and the relay check. sandbox_ssh_args cannot be called without it.
  • The client decides the check when it prepares the proxy, from the fingerprint of the sandbox it looked up. The private handoff of fix(ssh): keep session tokens out of OpenSSH process arguments #5944 carries the expected fingerprint and the pin file to ssh-proxy. A saved SSH config entry names its pin with --known-hosts.
  • No protobuf change. No dependency on the OpenSSH version.
  • An unverified connection is refused: a sandbox with no published fingerprint, an SSH config entry from an earlier release, and a client started before the upgrade. OPENSHELL_SSH_REQUIRE_HOST_KEY=0 lets it go ahead with a warning.
  • --editor on sandbox create or sandbox connect also replaces the entries an earlier release wrote in the managed SSH include file, when the user did not edit them.
  • Generated entries turn connection sharing off, as the ssh the CLI starts already does. The alias does not name the gateway, so a shared connection would also serve the sandbox of the same name on another gateway, unchecked.
  • With the opt-out set, the TUI status line says the host key was not verified after the session.

Breaking change: SSH connections that worked without verification are now refused until the user upgrades the gateway, stops and starts the sandbox, regenerates the SSH config entry, restarts the older client, or sets OPENSHELL_SSH_REQUIRE_HOST_KEY=0.

Accepted risk: a config directory whose path contains ", ${, a newline, or a backslash on Unix cannot hold the known-hosts file, because ssh has no way to take such a path in UserKnownHostsFile. SSH commands fail there with SSH known-hosts path ... cannot be used. The fix is to set XDG_CONFIG_HOME to a path without them. An indirection through a second path would add code for a case no report describes.

Out of scope: 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, and refuse a connection they cannot verify.

  • A sandbox with no published fingerprint is refused. Upgrade the gateway, or stop and start the sandbox, to get a fingerprint.
  • SSH config entries generated by earlier releases are refused. Use --editor on sandbox connect to replace them, or paste new openshell sandbox ssh-config output.
  • An openshell or openshell term process started before the upgrade is refused until you restart it.
  • Set OPENSHELL_SSH_REQUIRE_HOST_KEY=0 to connect without verification, with a warning.
  • SSH commands fail when the OpenShell config directory path contains ", ${, a newline, or a backslash on Unix. Set XDG_CONFIG_HOME to a path without them.

Testing

  • Checks appropriate to the affected code and behavior pass
  • Unit tests added/updated (if applicable)
  • E2E tests added/updated (if applicable)

Ran on Linux with OpenSSH 10.0p2: cargo test for openshell-core, openshell-cli, and openshell-tui, cargo clippy --all-targets -D warnings on the same crates, cargo fmt --check, and the lockfile check.

ssh_proxy_host_key_integration runs the real ssh binary through the built openshell ssh-proxy against a russh server, over a handoff the test prepares as the CLI does: the published key connects, another key is refused before any command runs, a stale pin is replaced, and ssh refuses a key missing from its own known-hosts file. The first two run over the session relay and the direct relay. Two of these run with a % in the config directory. The same file checks that a saved SSH config entry without --known-hosts, a handoff from a client that predates verification, and a gateway that publishes nothing are refused, and that the first and last are relayed with a warning when OPENSHELL_SSH_REQUIRE_HOST_KEY=0.

Not run locally: the E2E suites, macOS, Windows, and OpenSSH 8.x. The existing conformance test ssh_host_identity_stable_across_stop_start_and_new_on_recreate exercises the relay check against a real supervisor in CI.

Checklist

  • Follows Conventional Commits
  • Commits are signed off (DCO)
  • Architecture docs updated (if applicable)

@copy-pr-bot

copy-pr-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the state:accepted A maintainer decided OpenShell should pursue this issue label Nov 18, 2026
@github-actions

Copy link
Copy Markdown

@alangou alangou added the test:e2e Requires end-to-end coverage label Nov 18, 2026
@github-actions

Copy link
Copy Markdown

Label test:e2e applied, but pull-request/5703 does not exist yet. A maintainer needs to comment /ok to test 3cdb3a9710e393e622c35c2bb339dc206a30dbdf to mirror this PR. Once the mirror exists, re-apply the label or re-run Branch E2E Checks from the Actions tab.

@alangou

alangou commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 3cdb3a9

@github-actions

Copy link
Copy Markdown

Compatibility review (advisory)

New or updated breaking changes; see the full report for all findings.

1. cli — No explicit risk acceptance found

openshell ssh-proxy --gateway-name G --name S now requires --known-hosts FILE, while openshell ssh-proxy --gateway URL --sandbox S --token T now requires both --host-key FINGERPRINT and --known-hosts FILE.

  • Impact: Previously generated SSH/editor entries and older running CLI/TUI launchers now exit 1 with a host-key-verification refusal instead of opening their SSH connections.
  • Action: Provide a backward-compatible transition for saved SSH entries and older launchers; documented regeneration through sandbox ssh-config or sandbox connect --editor and client restarts do not satisfy the no-break policy.
  • PR: feat(cli)!: verify sandbox SSH host keys #5703

2. cli — No explicit risk acceptance found

openshell sandbox connect, SSH-based exec/transfers, forwarding, and TUI connections now reject an empty CreateSshSessionResponse.host_key_fingerprint instead of connecting by default.

  • Impact: Consumers using older gateways or existing sandboxes without assigned SSH identities lose previously working SSH operations unless they change their environment or upgrade/restart infrastructure.
  • Action: Preserve the existing empty-fingerprint default under this no-break policy; the documented gateway upgrade, sandbox stop/start, and OPENSHELL_SSH_ALLOW_UNVERIFIED_HOST_KEY=1 alternatives remain mandatory consumer migrations.
  • PR: feat(cli)!: verify sandbox SSH host keys #5703

3. configuration — No explicit risk acceptance found

An existing setting such as XDG_CONFIG_HOME=/tmp/100% previously worked for SSH operations but now produces a rejected known-hosts path.

  • Impact: openshell sandbox connect and openshell sandbox ssh-config fail for valid existing configuration directories containing %, even with a current gateway and matching host key.
  • Action: Keep previously valid XDG paths usable through SSH-compatible escaping or pin-path indirection rather than requiring an undocumented configuration-directory relocation.
  • PR: feat(cli)!: verify sandbox SSH host keys #5703
Review details
  • Execution: complete
  • Candidate: PR #5703 (732ff5f6e4b24494f986ab867c59268b890da539)
  • Baseline: 8424e1dddd36d8884017b0648508063428672a16 (8424e1dddd36d8884017b0648508063428672a16)
  • Reviewed: rust-sdk, python-sdk, typescript-sdk, api-behavior, cli, configuration, policy, helm, state

Advisory review; publication gates are unchanged.

Branch check run

@alangou

alangou commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test ee95035

@github-actions

Copy link
Copy Markdown

Compatibility review (advisory)

New or updated breaking changes; see the full report for all findings.

1. configuration — No explicit risk acceptance found

SSH operations previously accepted XDG_CONFIG_HOME/HOME paths containing double quotes, Unix backslashes, or literal '${', but now reject them as unusable known-hosts paths.

  • Impact: Existing users of these configuration directories lose openshell sandbox connect, forwarding, and sandbox ssh-config with an SSH known-hosts path ... cannot be used error.
  • Action: Preserve existing XDG_CONFIG_HOME/HOME paths through an SSH-safe pin-path indirection rather than requiring configuration relocation under this no-break policy.
  • PR: feat(cli)!: verify sandbox SSH host keys #5703
Review details
  • Execution: complete
  • Candidate: PR #5703 (1d7e15fccd96400166be6574c8def6a439a615c7)
  • Baseline: 8424e1dddd36d8884017b0648508063428672a16 (8424e1dddd36d8884017b0648508063428672a16)
  • Reviewed: rust-sdk, python-sdk, typescript-sdk, api-behavior, cli, configuration, policy, helm, state

Advisory review; publication gates are unchanged.

Branch check run

@alangou

alangou commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 261ba4c

@alangou

alangou commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test ffc6aee

@alangou
alangou marked this pull request as ready for review November 19, 2026 13:42
@alangou

alangou commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Accepted risk ssh interprets ", \, ${ and newlines in the known-hosts path and has no portable escape for them so config directory containing them is refused. Workaround: set XDG_CONFIG_HOME to a path without them

@FrostGod FrostGod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_KEY on 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?

Comment thread crates/openshell-cli/src/ssh.rs Resolved
Comment thread crates/openshell-cli/src/ssh.rs Resolved
Comment thread crates/openshell-cli/src/ssh.rs Resolved
Comment thread crates/openshell-cli/src/main.rs Resolved
Comment thread crates/openshell-tui/src/lib.rs Resolved
@github-actions

Copy link
Copy Markdown

Compatibility review (advisory)

New or updated breaking changes; see the full report for all findings.

1. configuration — Risk explicitly accepted

SSH 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.

  • Impact: Existing users of these directories lose sandbox connect, forwarding, transfers, and sandbox ssh-config with an 'SSH known-hosts path ... cannot be used' error.

  • Action: Retain existing paths through an SSH-safe pin location for v0.1.10; accepted XDG_CONFIG_HOME relocation does not satisfy the patch no-break policy.

  • PR: feat(cli)!: verify sandbox SSH host keys #5703

  • Acceptance: comment

Review details
  • Execution: complete
  • Candidate: PR #5703 (8be354e70798d17737f3eb25d24a22d69405b997)
  • Baseline: ed8a0d98acee9b7f9e4efe004bc6a748524406b7 (ed8a0d98acee9b7f9e4efe004bc6a748524406b7)
  • Reviewed: rust-sdk, python-sdk, typescript-sdk, api-behavior, cli, configuration, policy, helm, state

Advisory review; publication gates are unchanged.

Branch check run

@alangou
alangou force-pushed the feat/verify-sandbox-ssh-host-keys/alangou branch 2 times, most recently from 13bc102 to 44262c3 Compare November 23, 2026 17:29
@github-actions

Copy link
Copy Markdown

Compatibility review (advisory)

New or updated breaking changes; see the full report for all findings.

1. rust-sdk — No explicit risk acceptance found

Raw SandboxPolicy gains cedar_policy, provider_credential_rules, and endpoint_settings, while GetSandboxConfigRequest and SupervisorHello gain supported_capabilities.

  • Impact: Existing complete literals and exhaustive patterns through openshell_sdk::raw::proto stop compiling, although default-based construction and protobuf wire callers remain compatible.
  • Action: Preserve the baseline raw Rust layouts for v0.1.10 or defer these additions to a permitted minor train with guidance for default-based literals and non-exhaustive patterns.
  • PR: feat(cli)!: verify sandbox SSH host keys #5703
Review details
  • Execution: complete
  • Candidate: PR #5703 (84e034af3f9f7ad14d798b95bb2cfd1678f7e3f7)
  • Baseline: 96f407a85e4f70aa011b4bb150fbda4d5a2023a3 (96f407a85e4f70aa011b4bb150fbda4d5a2023a3)
  • Reviewed: rust-sdk, python-sdk, api-behavior, cli, configuration, policy, helm, state

Advisory review; publication gates are unchanged.

Branch check run

@alangou
alangou force-pushed the feat/verify-sandbox-ssh-host-keys/alangou branch from 05b2566 to 5407775 Compare November 24, 2026 14:49
@alangou alangou changed the title feat(cli): verify sandbox SSH host keys feat(cli)!: verify sandbox SSH host keys Nov 24, 2026
@alangou

alangou commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Accepted risk unverified SSH connections are now refused by default: older gateway, sandbox with no SSH identity, SSH config entry from an earlier release, older client still running. Workaround: set OPENSHELL_SSH_REQUIRE_HOST_KEY=0 or regenerate the entry with sandbox connect --editor

@github-actions

Copy link
Copy Markdown

Compatibility review (advisory)

New or updated breaking changes; see the full report for all findings.

1. cli — Risk explicitly accepted

openshell ssh-proxy --gateway-name G --name S now needs --known-hosts FILE, and openshell ssh-proxy --gateway URL --sandbox S --token T now needs --host-key FP --known-hosts FILE, unless OPENSHELL_SSH_REQUIRE_HOST_KEY=0.

  • Impact: Saved SSH/editor entries and older running CLI/TUI launchers now receive a host-key-verification refusal instead of an SSH stream.

  • Action: Preserve legacy ssh-proxy invocations under the supplied no-break policy; documented entry regeneration, client restarts, and the environment opt-out require consumer migration despite explicit acceptance.

  • PR: feat(cli)!: verify sandbox SSH host keys #5703

  • Acceptance: comment

2. cli — Risk explicitly accepted

SSH-backed CLI/TUI operations previously accepted an empty CreateSshSessionResponse.host_key_fingerprint but now reject it by default.

  • Impact: Existing sandboxes without published SSH identities lose shells, forwarding, and SSH-based transfers or exec unless users upgrade/restart infrastructure or set OPENSHELL_SSH_REQUIRE_HOST_KEY=0.

  • Action: Preserve the empty-fingerprint connection default under the supplied no-break policy; documented upgrades, sandbox stop/start, and the environment opt-out do not make this accepted break policy-compliant.

  • PR: feat(cli)!: verify sandbox SSH host keys #5703

  • Acceptance: comment

Review details
  • Execution: complete
  • Candidate: PR #5703 (07f417a2751c5f6d618d20b103953736018c6b7b)
  • Baseline: 9551cbada4babd38aa03f8948474cdc5bd206acc (9551cbada4babd38aa03f8948474cdc5bd206acc)
  • Reviewed: rust-sdk, python-sdk, api-behavior, cli, configuration, policy, helm, state

Advisory review; publication gates are unchanged.

Branch check run

FrostGod
FrostGod previously approved these changes Nov 25, 2026

@FrostGod FrostGod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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>
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>
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>
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>
The ssh-proxy warning blamed an older client, which is wrong when
someone starts the proxy by hand. It now names the missing flags.

Also say why a generated config entry turns connection sharing off: its
host alias does not name the gateway, so a shared connection would serve
the sandbox of the same name on another gateway without a host key
check. 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>
Using --editor rewrote only the entry of the sandbox being connected, so
the entries an earlier release wrote for other sandboxes kept accepting
any host key. It now replaces each of them that is still, line for line,
what that release wrote. An entry the user edited is left alone and
keeps its warning.

The TUI also puts "SSH host key NOT verified" first in its status line
after an unverified session, because ssh takes the terminal right after
the printed warning.

Signed-off-by: Adrien Langou <alangou@nvidia.com>
The relay exited the process from inside its task. It now returns the
refusal, and the CLI prints it like any other error. The exit code stays 1
and no byte of the refused key exchange reply reaches ssh.

Signed-off-by: Adrien Langou <alangou@nvidia.com>
An SSH connection whose host key cannot be verified is now refused: a
sandbox with no published fingerprint, an SSH config entry an earlier
release wrote, or an older client that starts ssh-proxy without
--host-key. Set OPENSHELL_SSH_REQUIRE_HOST_KEY=0 to connect with a
warning instead.

A stale config entry is refused before the gateway is called, and
uploads and downloads no longer retry a host key refusal.

Signed-off-by: Adrien Langou <alangou@nvidia.com>
@alangou
alangou force-pushed the feat/verify-sandbox-ssh-host-keys/alangou branch from 5407775 to 34d2f20 Compare November 26, 2026 10:07
@alangou
alangou enabled auto-merge November 26, 2026 10:08
SDAChess
SDAChess previously approved these changes Nov 26, 2026
main now hands relay grants to ssh-proxy over private IPC and no longer
accepts a session token in its arguments. The client decides the host key
check when it prepares the proxy, from the fingerprint of the sandbox it
looked up, and the handoff carries the expectation and the pin file to
the proxy. A saved SSH profile still names its pin with --known-hosts.

Signed-off-by: Adrien Langou <alangou@nvidia.com>
@alangou
alangou added this pull request to the merge queue Nov 26, 2026
Merged via the queue into main with commit 9996a59 Nov 26, 2026
164 of 165 checks passed
@alangou
alangou deleted the feat/verify-sandbox-ssh-host-keys/alangou branch November 26, 2026 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state:accepted A maintainer decided OpenShell should pursue this issue test:e2e Requires end-to-end coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants