sshx

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: AGPL-3.0 Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sshx dials hosts from the inventory (with jump-host chains, keychain/agent/password auth and TOFU host-key checking) and runs commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildCommand

func BuildCommand(c *Client, r RunRequest) (cmd string, sudoPass []byte, err error)

BuildCommand assembles the final remote shell line: env exports, cd, sudo wrapping. Exposed so --dry-run can show exactly what would run. sudoPass is the sudo password Run feeds on request, or nil.

func EnvExports added in v0.2.0

func EnvExports(c *Client, extra map[string]string) (string, error)

EnvExports is the "export K='v'; " prefix for the host's env and extra. A value written secret:NAME is read from the vault here, so it never passes through the agent (and output hides vault values too).

func ExpandProxy added in v0.2.0

func ExpandProxy(cmd string, h *store.Host) string

ExpandProxy fills in a ProxyCommand's tokens like OpenSSH: %h address, %p port, %r user, %n the name in the inventory, %% a percent sign.

func FetchHostKey added in v0.3.0

func FetchHostKey(ctx context.Context, st *store.State, h *store.Host, o Options) (ssh.PublicKey, error)

FetchHostKey fetches h's host key the way komando reaches h: directly, through a VPN, its proxy command or its --via path (those jump hosts are checked and logged in to as usual). h itself is not logged in to, and nothing is pinned for it: the caller compares and decides.

func HostKeyMismatch added in v0.3.0

func HostKeyMismatch(host string) *out.Error

HostKeyMismatch is the error for a server whose key is not the pinned one. An AI agent must not re-trust the key itself: it reports it, and a person checks the new fingerprint another way first.

func KnownHostsPath

func KnownHostsPath() string

func Output

func Output(ctx context.Context, c *Client, cmd string, timeout time.Duration) (string, int, error)

Output is a convenience for internal probes: run and return trimmed stdout.

func ParseAdhoc

func ParseAdhoc(s string) (*store.Host, error)

ParseAdhoc parses user@host:port into a transient host.

func PinHostKey added in v0.3.0

func PinHostKey(addr string, key ssh.PublicKey, replace bool) (removed int, err error)

PinHostKey pins key for addr (host:port). A key that is pinned already is not written again. With replace, every other line for addr goes in the same write, so a failure never leaves the server unpinned; removed is how many lines went. Whether a pin may be replaced is the caller's decision (`host trust --reset` needs a person's yes).

func PinnedKeys added in v0.3.0

func PinnedKeys(addr string) ([]ssh.PublicKey, error)

PinnedKeys are the keys komando's known_hosts pins for addr (host:port).

func Pipe added in v0.2.0

func Pipe(ctx context.Context, c *Client, cmd string, stdin io.Reader, stdout io.Writer) (int, string, error)

Pipe runs cmd and streams stdin and stdout without buffering them, for transfers too large for Run (database dumps). stderr is kept up to 64 KiB for error messages. It returns the remote exit code.

func Q

func Q(s string) string

Q single-quotes s for POSIX sh.

func Route added in v0.2.0

func Route(st *store.State, h *store.Host) (*store.Vpn, []*store.Host, error)

Route is the way to h: the VPN it starts with (or nil) and the SSH hops, ending with h itself. It reads the inventory only; nothing is dialed.

func SameKey added in v0.3.0

func SameKey(a, b ssh.PublicKey) bool

SameKey reports whether a and b are the same public key.

func ValidEnvKey added in v0.2.0

func ValidEnvKey(k string) bool

ValidEnvKey reports whether k can be exported as a shell variable. The key goes into the command line unquoted, so anything else could inject a command.

func WithDeadlines added in v0.2.0

func WithDeadlines(c net.Conn) net.Conn

SSH channels do not support deadlines, but database and cache clients use them for timeouts. WithDeadlines emulates them: when a deadline passes the connection is closed, which ends any blocked read or write.

Types

type Client

type Client struct {
	*ssh.Client
	Host *store.Host
	// contains filtered or unexported fields
}

Client wraps an ssh.Client plus the path of jump hosts it came through (shared with other servers behind the same hosts, shared.go).

func Dial

func Dial(ctx context.Context, st *store.State, h *store.Host, o Options) (*Client, error)

Dial connects to h, honouring its --via chain. A chain may start with a VPN; it is opened inside this process. The jump hosts are shared with other servers behind them (one login per jump host per command).

func (*Client) Close

func (c *Client) Close() error

type Options

type Options struct {
	ConnectTimeout time.Duration
	HostKeyPolicy  string // accept-new | strict | off
	// contains filtered or unexported fields
}

type RunRequest

type RunRequest struct {
	Command   string
	Sudo      bool
	SudoUser  string
	Env       map[string]string
	NoEnv     bool // leave out the exports (job start writes them to a private file instead)
	Dir       string
	Stdin     []byte
	Timeout   time.Duration
	MaxOutput int
	PTY       bool
	// Stream, when set, receives output chunks as they arrive (follow mode).
	Stream func(stream string, chunk []byte)
}

type RunResult

type RunResult struct {
	ExitCode        int    `json:"exit_code"`
	Stdout          string `json:"stdout"`
	Stderr          string `json:"stderr"`
	StdoutTruncated bool   `json:"stdout_truncated,omitempty"`
	StderrTruncated bool   `json:"stderr_truncated,omitempty"`
	TimedOut        bool   `json:"timed_out,omitempty"`
	Signal          string `json:"signal,omitempty"`
	DurationMS      int64  `json:"duration_ms"`
}

func Run

func Run(ctx context.Context, c *Client, r RunRequest) (*RunResult, error)

Run executes a command and never returns an error for a non-zero exit: that is reported in RunResult.ExitCode. err is for transport failures.

Jump to

Keyboard shortcuts

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