Skip to content

feat(ssh): wire ProxyJump as bastion and ProxyCommand as transport#380

Merged
kke merged 5 commits into
mainfrom
proxyjump-proxycommand
Jun 8, 2026
Merged

feat(ssh): wire ProxyJump as bastion and ProxyCommand as transport#380
kke merged 5 commits into
mainfrom
proxyjump-proxycommand

Conversation

@kke

@kke kke commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Auto-populate Config.Bastion from the first ProxyJump entry in sshconfig when no explicit Bastion is configured (t-088). Support ProxyCommand as an alternative SSH transport by running the command and bridging its stdin/stdout as a net.Conn (t-099).

When both ProxyCommand and ProxyJump are set, ProxyCommand takes precedence. This intentionally diverges from OpenSSH's first-match semantics (whichever directive appears first in ssh_config wins): the sshconfig parser does not preserve directive order, so first-match cannot be replicated. In practice, both directives being set simultaneously is rare (they come from different Host blocks), and ProxyCommand-wins is a safe default. An explicitly-configured Config.Bastion (not from ProxyJump) always takes priority over ProxyCommand.

Key design decisions:

  • ProxyCommand process is bound to Connection lifetime (stored in c.proxyCmd, reaped in disconnect()), not the connect context, so the transport survives after Connect() returns.
  • SSH handshake runs in a goroutine with a select on the connect deadline so stalled handshakes are abortable even though SetDeadline is a no-op on a pipe transport.
  • cmdConn.RemoteAddr() returns the real dst address so the knownhosts callback can call SplitHostPort on it without error.
  • Token expansion (%h, %p, %r, etc.) is already handled by sshconfig.Setter.Finalize() called inside ConfigParser.Apply().
  • CheckHostIP is disabled for ProxyCommand transports: the subprocess stdin/stdout pipe does not expose the real TCP peer address, so DNS-based IP verification would give incorrect results (per ssh_config(5)).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the SSH protocol implementation to match OpenSSH jump/command semantics by (1) wiring ProxyJump into rig’s existing bastion support and (2) adding ProxyCommand as an alternative transport by running the configured command and bridging its stdin/stdout as a net.Conn.

Changes:

  • Auto-populate Config.Bastion from the first ProxyJump hop when no explicit bastion is configured.
  • Add ProxyCommand transport support (subprocess-backed net.Conn + deadline-aware handshake).
  • Add unit/integration tests covering ProxyJump parsing/bastion wiring and ProxyCommand precedence/end-to-end connect.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
protocol/ssh/connection.go Wires ProxyJump into Config.Bastion, adds ProxyCommand precedence, and reaps proxy subprocesses on disconnect.
protocol/ssh/proxy.go Implements ProxyJump parsing and the ProxyCommand subprocess transport (cmdConn) + handshake flow.
protocol/ssh/proxy_test.go Adds tests for ProxyJump parsing/bastion behavior and ProxyCommand precedence + end-to-end transport bridging.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread protocol/ssh/proxy.go
Comment thread protocol/ssh/proxy.go
Comment thread protocol/ssh/proxy.go Outdated
Comment thread protocol/ssh/proxy_test.go Outdated
@kke kke force-pushed the proxyjump-proxycommand branch from 6b20940 to 95423ef Compare June 7, 2026 20:31
@kke kke requested a review from Copilot June 7, 2026 20:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread protocol/ssh/proxy.go Outdated
Comment thread protocol/ssh/proxy_test.go Outdated
@kke kke force-pushed the proxyjump-proxycommand branch from 95423ef to 882e1bf Compare June 7, 2026 20:50
@kke kke requested a review from Copilot June 7, 2026 20:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread protocol/ssh/proxy.go Outdated
Comment thread protocol/ssh/proxy.go
Comment thread protocol/ssh/connection.go Outdated
@kke kke force-pushed the proxyjump-proxycommand branch from 882e1bf to a66847c Compare June 7, 2026 21:30
@kke kke requested a review from Copilot June 7, 2026 21:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

Comment thread protocol/ssh/proxy.go
Comment thread protocol/ssh/proxy_test.go
Comment thread protocol/ssh/connection.go Outdated
Comment thread protocol/ssh/connection.go
Comment thread protocol/ssh/connection.go Outdated
@kke kke force-pushed the proxyjump-proxycommand branch from a66847c to 886d4e9 Compare June 8, 2026 06:09
@kke kke requested a review from Copilot June 8, 2026 06:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread protocol/ssh/proxy.go
Comment thread protocol/ssh/connection.go
@kke kke force-pushed the proxyjump-proxycommand branch from 886d4e9 to c9a2401 Compare June 8, 2026 06:33
@kke kke requested a review from Copilot June 8, 2026 06:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread protocol/ssh/proxy.go
Comment thread protocol/ssh/proxy.go
@kke kke force-pushed the proxyjump-proxycommand branch from c9a2401 to 8e33437 Compare June 8, 2026 06:47
@kke kke requested a review from Copilot June 8, 2026 06:47
Comment thread protocol/ssh/connection.go Fixed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

Comment thread protocol/ssh/proxy_test.go
Comment thread protocol/ssh/proxy.go
Comment thread protocol/ssh/proxy_test.go
Comment thread protocol/ssh/proxy_test.go
Comment thread protocol/ssh/proxy_test.go
@kke kke force-pushed the proxyjump-proxycommand branch from 8e33437 to 7207ded Compare June 8, 2026 07:00
@kke kke requested a review from Copilot June 8, 2026 07:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread protocol/ssh/proxy.go
Comment thread protocol/ssh/proxy_test.go

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Comment thread protocol/ssh/connection.go
Comment thread protocol/ssh/connection.go
Comment thread protocol/ssh/proxy.go
Auto-populate Config.Bastion from the first ProxyJump entry in sshconfig
when no explicit Bastion is configured (t-088). Support ProxyCommand as
an alternative SSH transport by running the command and bridging its
stdin/stdout as a net.Conn (t-099). ProxyCommand takes precedence over
ProxyJump when both are set, matching OpenSSH behaviour.

Key design decisions:
- ProxyCommand process is bound to Connection lifetime (stored in
  c.proxyCmd, reaped in disconnect()), not the connect context, so the
  transport survives after Connect() returns.
- SSH handshake runs in a goroutine with a select on the connect
  deadline so stalled handshakes are abortable even though SetDeadline
  is a no-op on a pipe transport.
- cmdConn.RemoteAddr() returns the real dst address so the knownhosts
  callback can call SplitHostPort on it without error.
- Token expansion (%h, %p, %r, etc.) is already handled by
  sshconfig.Setter.Finalize() called inside ConfigParser.Apply().

Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
@kke kke force-pushed the proxyjump-proxycommand branch from 3a5315d to a53cd34 Compare June 8, 2026 12:14
@kke kke requested a review from Copilot June 8, 2026 12:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread protocol/ssh/proxy.go Outdated
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment thread protocol/ssh/proxy.go Outdated
Comment thread protocol/ssh/proxy.go Outdated
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread protocol/ssh/connection.go
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment thread protocol/ssh/proxy.go Outdated
Comment thread protocol/ssh/connection.go
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

@kke kke marked this pull request as ready for review June 8, 2026 13:21
@kke kke merged commit bc18919 into main Jun 8, 2026
13 checks passed
@kke kke deleted the proxyjump-proxycommand branch June 8, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants