Skip to content

fix(ssh): keep session tokens out of OpenSSH process arguments - #5826

Draft
alangou wants to merge 11 commits into
ai-openshell:mainfrom
alangou:fix/ssh-session-handoff/alangou
Draft

alangou wants to merge 11 commits into
ai-openshell:mainfrom
alangou:fix/ssh-session-handoff/alangou

Conversation

@alangou

@alangou alangou commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Why

Keep SSH session credentials out of the process arguments used for sandbox connections, file transfers and port forwards.

What changed

A gateway can advertise direct SSH on an authenticated GetSandbox response. The proxy opens ForwardTcp with its gateway credential and the immutable sandbox ID from that lookup. The gateway checks workspace access, the ID and the SSH connection limit at admission, and records the sandbox and channel in the audit log. This path creates no SSH session record.

Clients use the original session-token flow when the gateway does not advertise direct SSH. This includes older gateways, local-development identities and deployments whose interceptors observe or control SSH session creation or revocation. Older clients can still use their existing token flow. A released v0.1.9 CLI was also tested against the new gateway. A command that has selected direct SSH keeps that mode across reconnects. A definitive refusal stops automatic retries, including when it arrives in the gRPC trailers.

For launches initiated by the CLI or TUI, OpenSSH receives a one-use local handle. The proxy obtains its connection context over a same-account Unix socket or Windows named pipe. On legacy connections this channel also carries the session grant. The issuer attempts revocation after relay admission, failure or cancellation. Saved SSH configurations resolve their named profiles on invocation. File transfers retain the selected identity across retries and across uploads in one create request.

Scope

For regular CLI commands, a direct gateway endpoint selects the destination. When the profile and endpoint come from different sources (command line and environment), the CLI uses credentials registered for the endpoint. For a tunnel, pass both --gateway and --gateway-endpoint explicitly to pair the profile with the tunnel address. A saved SSH profile continues to select its own gateway when the editor inherits another endpoint.

Generate saved SSH configuration from a named profile if the URL includes credentials, a path, a query, or a fragment. Regenerate custom proxy commands that passed the old hidden --token option. Direct Rust callers of the changed openshell-core and openshell-cli SSH helpers may also need to update their calls.

On Unix the proxy checks the account of the socket peer and the issuer PID. The Windows named pipe restricts access to the issuing account. Revocation is best effort if the issuer dies or the gateway is unavailable.

Verification

  • Exercised modern and mixed client/gateway versions with system OpenSSH, mTLS, an isolated gateway and a fixture supervisor on Linux. Checked the SQLite SSH-session writes, stale sandbox IDs, OIDC access, direct recovery and definitive refusals during transfers.
  • Checked protobuf compatibility and lint with Buf, generated TypeScript bindings, and ran the SDK type checks, tests and build.
  • Verified the ordinary CLI destination and credentials against two local gateways. Checked private HTTP(S) URLs with lowercase, uppercase, and mixed-case schemes. With two accounts registered on the same gateway, verified the selected identity for whoami, SSH session creation and relay admission. The test used distinct client certificates and real OpenSSH.
  • Ran CLI, core, TUI, forwarding and proxy tests. Verified all 13 Cargo workspaces resolve their checked-in dependencies with --locked.
  • Compared the base and patched binaries against the same local mTLS gateway with OpenSSH. Inspected the arguments of both OpenSSH and its proxy against the actual session values. The base exposed the values and the patched processes did not.
  • Exercised interactive attach, saved SSH configuration, binary upload/download and simultaneous foreground/background forwards. Stopping one forward left the other usable.
  • On Linux, a different account knowing the handle received zero bytes. The Unix backend also compiled for Apple Silicon, and the named-pipe backend compiled for both x64 and ARM64 Windows. Native macOS and Windows execution were not covered.

Signed-off-by: Adrien Langou <alangou@nvidia.com>
Signed-off-by: Adrien Langou <alangou@nvidia.com>
Signed-off-by: Adrien Langou <alangou@nvidia.com>
Signed-off-by: Adrien Langou <alangou@nvidia.com>
@github-actions github-actions Bot added the state:accepted A maintainer decided OpenShell should pursue this issue label Nov 20, 2026
Signed-off-by: Adrien Langou <alangou@nvidia.com>
Signed-off-by: Adrien Langou <alangou@nvidia.com>
Signed-off-by: Adrien Langou <alangou@nvidia.com>
…SSH URLs

Signed-off-by: Adrien Langou <alangou@nvidia.com>
Signed-off-by: Adrien Langou <alangou@nvidia.com>
Signed-off-by: Adrien Langou <alangou@nvidia.com>
Signed-off-by: Adrien Langou <alangou@nvidia.com>

This branch has not been deployed

No deployments
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant