Documentation
¶
Overview ¶
Package sshlife provides a thin SSH client used by xpc bootstrap and the agent-lifecycle subcommands. We deliberately use a minimal feature set:
Dial(addr, user, password) Run(cmd) (stdout, stderr, exitStatus, err) PutFile(localPath, remotePath) -- via `cat > <remote>` over stdin pipe PutBytes(data, remotePath) -- same, from an in-memory buffer
The remote shell is the Cygwin bash sshd that xpctl bootstraps on the VM. Paths are POSIX-style (/cygdrive/c/...) for the upload helpers; the PutFile/PutBytes wrappers convert from C:\... automatically.
Host-key trust uses TOFU (trust on first use): the first connection to a new host writes its key to ~/.xpc/known_hosts; subsequent connections require a byte-for-byte match. A changed key short-circuits the dial with an error.
Index ¶
- func TOFUHostKey(path string) ssh.HostKeyCallback
- type Client
- func (c *Client) Close() error
- func (c *Client) PutBytes(data []byte, remotePath string, timeout time.Duration) error
- func (c *Client) PutFile(localPath, remotePath string, timeout time.Duration) error
- func (c *Client) Run(cmd string, timeout time.Duration) (stdout, stderr string, exitStatus int, err error)
- type DialOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TOFUHostKey ¶
func TOFUHostKey(path string) ssh.HostKeyCallback
TOFUHostKey returns an ssh.HostKeyCallback that:
- accepts and records the host key on first contact (writes to path)
- rejects subsequent connections whose key differs from the recorded one
The known_hosts file uses the standard OpenSSH-ish line format "<host> <key-type> <base64-key>". Multiple entries per host are tolerated; the callback succeeds if any line matches the presented key exactly.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a thin wrapper around an *ssh.Client that opens a fresh session for each Run/PutFile/PutBytes call.
func Dial ¶
func Dial(addr string, opt DialOptions) (*Client, error)
Dial opens an SSH connection. addr is "host:port"; if no port, 22 is used.
func (*Client) PutFile ¶
PutFile uploads a local file to remotePath. remotePath is a Windows-style path (e.g. C:\xpc\agent.py); it's translated to /cygdrive/c/xpc/agent.py for the bash `cat > ...` invocation.
func (*Client) Run ¶
func (c *Client) Run(cmd string, timeout time.Duration) (stdout, stderr string, exitStatus int, err error)
Run executes cmd in a remote shell, returning combined stdout, stderr, and the exit status. A non-zero exit status is returned in the int but does NOT produce an error; callers decide whether to treat it as failure.
type DialOptions ¶
type DialOptions struct {
User string
Password string
Timeout time.Duration
// HostKeyCallback overrides the default TOFU callback. Leave nil to
// trust on first use against ~/.xpc/known_hosts.
HostKeyCallback ssh.HostKeyCallback
// KnownHostsPath overrides the default ~/.xpc/known_hosts location.
KnownHostsPath string
}
DialOptions configures Dial.