Documentation
¶
Overview ¶
Package ssh manages connections, command execution, and SFTP transfers.
Index ¶
- func ReconstructCommand(pipeline *parser.Pipeline, isPSQL bool, toolkitPath bool) string
- func ShellQuote(token string) string
- func ValidHostKeyMode(mode string) bool
- type Client
- type ConnectionParams
- type Dialer
- type ExecResult
- type HostKeyError
- type HostKeyMode
- type ManagedConnection
- type Option
- type SFTPClient
- type SSHManager
- func (m *SSHManager) Connect(ctx context.Context, params ConnectionParams) error
- func (m *SSHManager) Connected() bool
- func (m *SSHManager) Disconnect(_ context.Context, host string) error
- func (m *SSHManager) Execute(ctx context.Context, host, command string, timeout time.Duration) (ExecResult, error)
- func (m *SSHManager) ExecuteRaw(ctx context.Context, host, command string, timeout time.Duration) (ExecResult, error)
- func (m *SSHManager) ResolveConnection(host string) (*ManagedConnection, error)
- func (m *SSHManager) SFTPSession(host string) (SFTPClient, error)
- type SystemSSHDialer
- type XCryptoDialer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReconstructCommand ¶
func ShellQuote ¶
func ValidHostKeyMode ¶
ValidHostKeyMode reports whether mode is a recognized host key verification mode.
Types ¶
type Client ¶
type Client interface {
Execute(ctx context.Context, command string, timeout time.Duration) (ExecResult, error)
SFTPSession() (SFTPClient, error)
Close() error
}
type ConnectionParams ¶
type Dialer ¶
type Dialer interface {
Dial(ctx context.Context, params ConnectionParams) (Client, error)
}
type HostKeyError ¶
type HostKeyError struct {
Message string
}
HostKeyError is a user-facing error for host key verification failures.
func (*HostKeyError) Error ¶
func (e *HostKeyError) Error() string
type HostKeyMode ¶
type HostKeyMode string
HostKeyMode controls how SSH host keys are verified.
const ( // HostKeyAcceptNew accepts unknown hosts on first connect (TOFU), // writes their key to known_hosts, and rejects key changes. HostKeyAcceptNew HostKeyMode = "accept-new" // HostKeyStrict requires the host key to already exist in known_hosts. HostKeyStrict HostKeyMode = "strict" // HostKeyOff disables host key verification entirely. HostKeyOff HostKeyMode = "off" )
type ManagedConnection ¶
type ManagedConnection struct {
Client Client
Params ConnectionParams
}
type Option ¶
type Option func(*SSHManager)
func WithConnectTimeout ¶
func WithHostKeyChecking ¶
func WithHostKeyChecking(mode HostKeyMode) Option
func WithKnownHostsFile ¶
func WithRetries ¶
func WithRetryBackoff ¶
type SFTPClient ¶
type SSHManager ¶
type SSHManager struct {
// contains filtered or unexported fields
}
func NewSSHManager ¶
func NewSSHManager(dialer Dialer, opts ...Option) *SSHManager
func (*SSHManager) Connect ¶
func (m *SSHManager) Connect(ctx context.Context, params ConnectionParams) error
func (*SSHManager) Connected ¶
func (m *SSHManager) Connected() bool
func (*SSHManager) Disconnect ¶
func (m *SSHManager) Disconnect(_ context.Context, host string) error
func (*SSHManager) Execute ¶
func (m *SSHManager) Execute(ctx context.Context, host, command string, timeout time.Duration) (ExecResult, error)
func (*SSHManager) ExecuteRaw ¶
func (m *SSHManager) ExecuteRaw(ctx context.Context, host, command string, timeout time.Duration) (ExecResult, error)
func (*SSHManager) ResolveConnection ¶
func (m *SSHManager) ResolveConnection(host string) (*ManagedConnection, error)
func (*SSHManager) SFTPSession ¶
func (m *SSHManager) SFTPSession(host string) (SFTPClient, error)
type SystemSSHDialer ¶
type SystemSSHDialer struct {
// ControlDir is the directory for ControlMaster sockets.
// Defaults to /tmp/shellguard-ctl.
ControlDir string
// contains filtered or unexported fields
}
SystemSSHDialer implements Dialer by spawning the system ssh binary. It uses ControlMaster for connection multiplexing so that only the first Dial pays the SSH handshake cost; subsequent Execute calls reuse the existing control socket.
func (*SystemSSHDialer) CheckBinary ¶
func (d *SystemSSHDialer) CheckBinary() bool
CheckBinary returns true if ssh is available in PATH.
func (*SystemSSHDialer) Dial ¶
func (d *SystemSSHDialer) Dial(ctx context.Context, params ConnectionParams) (Client, error)
Dial establishes a ControlMaster connection by spawning a background ssh process. The process exits after ControlPersist seconds of idle.
type XCryptoDialer ¶
type XCryptoDialer struct {
ConnectTimeout time.Duration
HostKeyMode HostKeyMode
KnownHostsFile string
}
func (*XCryptoDialer) Dial ¶
func (d *XCryptoDialer) Dial(ctx context.Context, params ConnectionParams) (Client, error)