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 ForgetHost(addr string) (int, 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 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 ScanHostKey(ctx context.Context, addr string, timeout time.Duration) (ssh.PublicKey, error)
- func TrustKey(addr string, key ssh.PublicKey) error
- 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 ForgetHost ¶
ForgetHost removes known_hosts lines for addr (host:port normalised).
func KnownHostsPath ¶
func KnownHostsPath() string
func ParseAdhoc ¶
ParseAdhoc parses user@host:port into a transient host.
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 ScanHostKey ¶
ScanHostKey fetches the server's host key without authenticating.
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 chain of jump clients that must be closed with it.
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"`
}