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 ¶
- func BuildCommand(c *Client, r RunRequest) (cmd string, sudoPass []byte, err error)
- func EnvExports(c *Client, extra map[string]string) (string, error)
- func ExpandProxy(cmd string, h *store.Host) string
- func FetchHostKey(ctx context.Context, st *store.State, h *store.Host, o Options) (ssh.PublicKey, error)
- func HostKeyMismatch(host string) *out.Error
- func KnownHostsPath() string
- func Output(ctx context.Context, c *Client, cmd string, timeout time.Duration) (string, int, error)
- func ParseAdhoc(s string) (*store.Host, error)
- func PinHostKey(addr string, key ssh.PublicKey, replace bool) (removed int, err error)
- func PinnedKeys(addr string) ([]ssh.PublicKey, error)
- func Pipe(ctx context.Context, c *Client, cmd string, stdin io.Reader, stdout io.Writer) (int, string, error)
- func Q(s string) string
- func Route(st *store.State, h *store.Host) (*store.Vpn, []*store.Host, error)
- func SameKey(a, b ssh.PublicKey) bool
- func ValidEnvKey(k string) bool
- func WithDeadlines(c net.Conn) net.Conn
- type Client
- type Options
- type RunRequest
- type RunResult
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
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
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
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 ParseAdhoc ¶
ParseAdhoc parses user@host:port into a transient host.
func PinHostKey ¶ added in v0.3.0
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
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 Route ¶ added in v0.2.0
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 ValidEnvKey ¶ added in v0.2.0
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.
Types ¶
type Client ¶
Client wraps an ssh.Client plus the path of jump hosts it came through (shared with other servers behind the same hosts, shared.go).
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"`
}