Documentation
¶
Index ¶
- Constants
- func GetKnownHostsPath() (string, error)
- func InteractivePrompt(host, fingerprint, keyType string) (bool, error)
- func RemoveHostKey(host string) error
- func SetGlobalHostKeyMode(mode HostKeyMode)
- type Client
- func NewClient(host string, port int, user string, keyPath string) (*Client, error)
- func NewClientFromConfig(cfg ServerConfig) (*Client, error)
- func NewClientFromConfigPinned(config ServerConfig, expected RecordedHostKey) (*Client, error)
- func NewClientWithAuth(host string, port int, user string, keyPath string, password string) (*Client, error)
- func NewClientWithPassword(host string, port int, user string, password string) (*Client, error)
- func (c *Client) Close() error
- func (c *Client) Connect() error
- func (c *Client) ConnectContext(ctx context.Context) error
- func (c *Client) CopyDirectory(localPath, remotePath string) error
- func (c *Client) CopyFile(localPath, remotePath string) error
- func (c *Client) CopyFileWithMode(localPath, remotePath string, mode os.FileMode) error
- func (c *Client) CopyFromRemote(remotePath, localPath string) error
- func (c *Client) DialUnixSocket(ctx context.Context, path string) (net.Conn, error)
- func (c *Client) Execute(cmd string) (string, error)
- func (c *Client) ExecuteInteractive(cmd string) error
- func (c *Client) ExecuteStream(cmd string, stdout, stderr io.Writer) error
- func (c *Client) ExecuteStreamWithContext(ctx context.Context, cmd string, stdout, stderr io.Writer) error
- func (c *Client) ExecuteStreamWithInput(ctx context.Context, cmd string, input io.Reader, stdout, stderr io.Writer) error
- func (c *Client) ExecuteWithContext(ctx context.Context, cmd string) (string, error)
- func (c *Client) ExecuteWithInput(ctx context.Context, cmd string, input io.Reader) (string, error)
- func (c *Client) Host() string
- func (c *Client) IsConnected() bool
- func (c *Client) IsHealthy() bool
- func (c *Client) Port() int
- func (c *Client) StartStream(cmd string) (*StreamingSession, error)
- func (c *Client) UploadReader(reader io.Reader, remotePath string, mode os.FileMode) error
- func (c *Client) UploadReaderPrivateTemp(ctx context.Context, reader io.Reader, mode os.FileMode) (string, func(), error)
- type HostKeyMode
- type HostKeyVerifier
- type MultiplexConfig
- type Multiplexer
- type MuxConnection
- type Pool
- func (p *Pool) CloseAll() error
- func (p *Pool) Get(host string, port int, user string) *Client
- func (p *Pool) GetOrCreate(host string, port int, user string, keyPath string) (*Client, error)
- func (p *Pool) GetOrCreateWithAuth(host string, port int, user string, keyPath string, password string) (*Client, error)
- func (p *Pool) GetOrCreateWithAuthPinned(host string, port int, user string, keyPath string, password string, ...) (*Client, error)
- func (p *Pool) OperationFenceSource() takodclient.OperationFenceSource
- func (p *Pool) Remove(host string, port int, user string) error
- func (p *Pool) SetOperationFenceSource(source takodclient.OperationFenceSource)
- type RecordedHostKey
- type ServerConfig
- type StreamingSession
Constants ¶
const DefaultCommandTimeout = 30 * time.Minute
Variables ¶
This section is empty.
Functions ¶
func GetKnownHostsPath ¶ added in v0.0.4
GetKnownHostsPath returns the path to Tako's known_hosts file
func InteractivePrompt ¶ added in v0.0.4
InteractivePrompt prompts the user to accept an unknown host key Use this with SetPromptFunc for interactive CLI sessions
func RemoveHostKey ¶ added in v0.2.0
RemoveHostKey removes a host key from Tako's known_hosts file This should be called when recreating a server to allow clean reconnection.
func SetGlobalHostKeyMode ¶ added in v0.0.4
func SetGlobalHostKeyMode(mode HostKeyMode)
SetGlobalHostKeyMode sets the global host key verification mode
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps an SSH connection with additional functionality
func NewClient ¶
NewClient creates a new SSH client with key-based authentication Also tries ssh-agent for passphrase-protected keys
func NewClientFromConfig ¶ added in v0.0.3
func NewClientFromConfig(cfg ServerConfig) (*Client, error)
NewClientFromConfig creates a new SSH client from server configuration Automatically chooses between key-based and password-based authentication
func NewClientFromConfigPinned ¶ added in v0.10.0
func NewClientFromConfigPinned(config ServerConfig, expected RecordedHostKey) (*Client, error)
NewClientFromConfigPinned constructs an SSH client whose in-memory callback accepts only the exact host key captured during enrollment. It is immune to later known_hosts removal, TOFU mode changes, and reconnect races.
func NewClientWithAuth ¶ added in v0.0.3
func NewClientWithAuth(host string, port int, user string, keyPath string, password string) (*Client, error)
NewClientWithAuth creates a new SSH client with either key or password authentication If both keyPath and password are provided, key-based auth is preferred Also tries ssh-agent as fallback for passphrase-protected keys
func NewClientWithPassword ¶ added in v0.0.3
NewClientWithPassword creates a new SSH client with password-based authentication
func (*Client) Connect ¶
Connect establishes the SSH connection with retry logic and optimized TCP settings.
func (*Client) ConnectContext ¶ added in v0.7.0
ConnectContext establishes the SSH connection with retry logic and context cancellation support.
func (*Client) CopyDirectory ¶
CopyDirectory copies a directory from local to remote server
func (*Client) CopyFileWithMode ¶
CopyFileWithMode uploads a file to the remote server with specific permissions
func (*Client) CopyFromRemote ¶
CopyFromRemote copies a file from remote to local
func (*Client) DialUnixSocket ¶ added in v0.8.1
getConnection returns the current connection, establishing it if needed This method properly handles the connection state to avoid TOCTOU race conditions DialUnixSocket opens a direct-streamlocal@openssh.com channel to a Unix socket on the remote host, returning a full-duplex connection to it. This is how interactive takod endpoints are reached: real HTTP over the socket, no remote curl process. Requires sshd's default AllowStreamLocalForwarding=yes.
func (*Client) ExecuteInteractive ¶ added in v0.2.5
ExecuteInteractive runs a command interactively with a remote PTY. It puts the local terminal in raw mode and forwards stdin/stdout/stderr bidirectionally, supporting full interactive sessions (shells, editors, etc.).
func (*Client) ExecuteStream ¶
ExecuteStream runs a command and streams output in real-time.
func (*Client) ExecuteStreamWithContext ¶ added in v0.7.0
func (c *Client) ExecuteStreamWithContext(ctx context.Context, cmd string, stdout, stderr io.Writer) error
ExecuteStreamWithContext runs a command, streams output in real-time, and respects context cancellation.
func (*Client) ExecuteStreamWithInput ¶ added in v0.8.0
func (c *Client) ExecuteStreamWithInput(ctx context.Context, cmd string, input io.Reader, stdout, stderr io.Writer) error
ExecuteStreamWithInput runs a command feeding input to stdin while streaming output in real-time, respecting context cancellation.
func (*Client) ExecuteWithContext ¶
ExecuteWithContext runs a command with context support for cancellation
func (*Client) ExecuteWithInput ¶ added in v0.3.0
ExecuteWithInput runs a command on the remote server, streams input to stdin, and returns combined stdout/stderr output.
func (*Client) IsConnected ¶
IsConnected checks if the client is connected
func (*Client) IsHealthy ¶ added in v0.1.4
IsHealthy checks if the connection is still alive by sending a keepalive request This helps detect stale connections that appear connected but are actually dead
func (*Client) StartStream ¶
func (c *Client) StartStream(cmd string) (*StreamingSession, error)
StartStream creates a new streaming session for long-running commands
func (*Client) UploadReader ¶
UploadReader uploads content from a reader to a remote file
func (*Client) UploadReaderPrivateTemp ¶ added in v0.10.0
func (c *Client) UploadReaderPrivateTemp(ctx context.Context, reader io.Reader, mode os.FileMode) (string, func(), error)
UploadReaderPrivateTemp uploads into a fresh 0700 remote directory created by mktemp. The unguessable directory prevents another local account from pre-placing a symlink at the destination before a privileged install.
type HostKeyMode ¶ added in v0.0.4
type HostKeyMode int
HostKeyMode controls host key verification behavior
const ( // HostKeyModeTOFU trusts on first use, verifies on subsequent connections (default) HostKeyModeTOFU HostKeyMode = iota // HostKeyModeStrict requires host to already be in known_hosts HostKeyModeStrict // HostKeyModeAsk prompts user for unknown hosts (interactive only) HostKeyModeAsk )
func GetGlobalHostKeyMode ¶ added in v0.0.4
func GetGlobalHostKeyMode() HostKeyMode
GetGlobalHostKeyMode returns the current global host key verification mode
func ParseHostKeyMode ¶ added in v0.0.4
func ParseHostKeyMode(s string) (HostKeyMode, error)
ParseHostKeyMode parses a string into HostKeyMode
func (HostKeyMode) String ¶ added in v0.0.4
func (m HostKeyMode) String() string
String returns string representation of HostKeyMode
type HostKeyVerifier ¶ added in v0.0.4
type HostKeyVerifier struct {
// contains filtered or unexported fields
}
HostKeyVerifier provides host key verification with TOFU support
func GetDefaultVerifier ¶ added in v0.0.4
func GetDefaultVerifier() (*HostKeyVerifier, error)
GetDefaultVerifier returns the default host key verifier
func NewHostKeyVerifier ¶ added in v0.0.4
func NewHostKeyVerifier(mode HostKeyMode) (*HostKeyVerifier, error)
NewHostKeyVerifier creates a new host key verifier
func (*HostKeyVerifier) GetCallback ¶ added in v0.0.4
func (v *HostKeyVerifier) GetCallback() ssh.HostKeyCallback
GetCallback returns an ssh.HostKeyCallback for use with ssh.ClientConfig
func (*HostKeyVerifier) SetMode ¶ added in v0.0.4
func (v *HostKeyVerifier) SetMode(mode HostKeyMode)
SetMode sets the verification mode
func (*HostKeyVerifier) SetPromptFunc ¶ added in v0.0.4
func (v *HostKeyVerifier) SetPromptFunc(fn func(host, fingerprint, keyType string) (bool, error))
SetPromptFunc sets the function to prompt user for unknown hosts
type MultiplexConfig ¶
MultiplexConfig holds multiplexing configuration
type Multiplexer ¶
type Multiplexer struct {
// contains filtered or unexported fields
}
Multiplexer manages SSH connection multiplexing for improved performance
func NewMultiplexer ¶
func NewMultiplexer() *Multiplexer
NewMultiplexer creates a new SSH multiplexer
func (*Multiplexer) CloseAll ¶
func (m *Multiplexer) CloseAll()
CloseAll closes all multiplexed connections
func (*Multiplexer) GetConnection ¶
func (m *Multiplexer) GetConnection(host string, port int, user string, sshKey string) (*MuxConnection, error)
GetConnection retrieves or creates a multiplexed connection
type MuxConnection ¶
type MuxConnection struct {
// contains filtered or unexported fields
}
MuxConnection represents a multiplexed SSH connection
func (*MuxConnection) Close ¶
func (c *MuxConnection) Close() error
Close closes the multiplexed connection
func (*MuxConnection) Execute ¶
func (c *MuxConnection) Execute(command string) (string, error)
Execute runs a command using the multiplexed connection
func (*MuxConnection) IsHealthy ¶
func (c *MuxConnection) IsHealthy() bool
IsHealthy checks if the multiplexed connection is still active
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool manages a pool of SSH connections
func (*Pool) GetOrCreate ¶
GetOrCreate gets an existing client from the pool or creates a new one Uses proper locking to avoid race conditions with double-checked locking
func (*Pool) GetOrCreateWithAuth ¶ added in v0.0.3
func (p *Pool) GetOrCreateWithAuth(host string, port int, user string, keyPath string, password string) (*Client, error)
GetOrCreateWithAuth gets an existing client from the pool or creates a new one Supports both key-based and password-based authentication Automatically removes and replaces unhealthy connections
func (*Pool) GetOrCreateWithAuthPinned ¶ added in v0.10.0
func (p *Pool) GetOrCreateWithAuthPinned(host string, port int, user string, keyPath string, password string, expected RecordedHostKey) (*Client, error)
GetOrCreateWithAuthPinned is the platform-membership runtime path. It never consults mutable known_hosts after enrollment and caches by exact pin.
func (*Pool) OperationFenceSource ¶ added in v0.10.0
func (p *Pool) OperationFenceSource() takodclient.OperationFenceSource
func (*Pool) SetOperationFenceSource ¶ added in v0.10.0
func (p *Pool) SetOperationFenceSource(source takodclient.OperationFenceSource)
type RecordedHostKey ¶ added in v0.8.0
RecordedHostKey is the SSH host key recorded for a host in a known_hosts file. Key is the base64-encoded wire form; Fingerprint is SHA256.
func LookupRecordedHostKey ¶ added in v0.8.0
func LookupRecordedHostKey(host string, port int) (*RecordedHostKey, error)
LookupRecordedHostKey returns the host key recorded for host:port in Tako's known_hosts (~/.tako/known_hosts), falling back to the user's ~/.ssh/known_hosts. It returns nil with no error when no key is recorded.
type ServerConfig ¶ added in v0.0.3
ServerConfig represents SSH connection parameters This mirrors config.ServerConfig to avoid circular imports
type StreamingSession ¶
type StreamingSession struct {
Stdout io.Reader
Stderr io.Reader
// contains filtered or unexported fields
}
StreamingSession represents a streaming SSH session
func (*StreamingSession) Close ¶
func (s *StreamingSession) Close() error
Close closes the streaming session
func (*StreamingSession) Wait ¶ added in v0.3.0
func (s *StreamingSession) Wait() error
Wait waits for the streaming command to finish.
func (*StreamingSession) WaitContext ¶ added in v0.4.27
func (s *StreamingSession) WaitContext(ctx context.Context) error
WaitContext waits for the streaming command to finish or for ctx to expire.