sshx

package
v0.1.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package sshx is the DevHub's outbound SSH client (S47). The DevHub on the dev box dials OUT to registered servers — Miguel keeps his single laptop→devbox tunnel; no inbound ports are opened anywhere.

Security invariants (non-negotiable):

  • Private keys are referenced by filesystem path only; key material never reaches SQLite, API responses or logs.
  • Host keys are TOFU: pinned on first connect (persisted by the caller via OnHostKey) and strictly verified afterwards. A changed host key is an explicit error — never InsecureIgnoreHostKey, never silent continue.
  • Callers run FIXED commands with validated arguments; nothing here ever receives a command string originating from the UI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close(serverID int64)

Close drops the pooled connection for a server (e.g. when it is deleted from the registry).

func Dial

func Dial(s *Server) (*ssh.Client, error)

Dial returns a live SSH client for the server, reusing the pooled connection when it is still alive and reconnecting when it is not.

func Forward

func Forward(s *Server, remotePort int) (net.Listener, error)

Forward opens an ephemeral local listener that tunnels every connection to 127.0.0.1:remotePort on the server (scraping /metrics, smoke checks — no remote ports get exposed). The caller must Close() the listener. For local servers it returns a direct listener-less address via ForwardAddr instead; callers that may handle local servers should use ForwardAddr.

func ForwardAddr

func ForwardAddr(s *Server, remotePort int) (addr string, closer io.Closer, err error)

ForwardAddr returns a "host:port" address reaching the server's remotePort: localhost directly for local servers, an SSH tunnel otherwise. closer is non-nil only when a tunnel was opened.

func Push

func Push(s *Server, localPath, remotePath string) error

Push copies a local file to remotePath on the server via SFTP (or a plain file copy for local servers), preserving an executable mode.

Types

type RunResult

type RunResult struct {
	Stdout   string
	Stderr   string
	ExitCode int
}

RunResult carries the outcome of one fixed command.

func Run

func Run(s *Server, cmd string, timeout time.Duration) (*RunResult, error)

Run executes a FIXED command (built by Go callers, never UI input) on the server and returns its output. Local servers execute directly.

type Server

type Server struct {
	ID      int64
	Name    string
	Host    string
	Port    int
	User    string
	KeyPath string
	// HostKey is the pinned public host key in authorized_keys format, empty
	// until the first successful connect.
	HostKey string
	// OnHostKey persists a newly-pinned host key (TOFU first connect). May be
	// nil, in which case the key is pinned for this process only.
	OnHostKey func(authorizedKey string) error
}

Server is the connection identity of a registered server. The api layer loads it from SQLite and persists TOFU host keys via OnHostKey.

func (*Server) Local

func (s *Server) Local() bool

Local reports whether the server is this box itself: commands run directly (no SSH) and the engine is reached on localhost.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL