ssh

package
v0.23.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package ssh is the transport that carries go-adpwsh to a Windows jump box. One ssh.Client for the transport's lifetime, a fresh channel per operation: that amortizes the handshake while keeping every operation stateless, so a failure cannot corrupt the ones that follow.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dial added in v0.15.0

func Dial(cfg Config) (*ssh.Client, error)

Dial validates cfg and connects to the jump box, returning a live client. It is shared with transport/sshwarm, which needs the same auth/host-key handling to open its subsystem channel. cfg is validated and defaulted here (WithDefaults is idempotent, so callers that already defaulted are safe).

Types

type Config

type Config struct {
	Host string
	Port int
	User string

	// Exactly one of these must resolve to a usable credential.
	PrivateKeyPEM  string
	PrivateKeyPath string
	Password       string
	UseAgent       bool

	// Host key verification, checked in this order: InsecureIgnoreHostKey
	// wins if set, then a pinned HostKey, then KnownHostsFile. Setting both
	// HostKey and KnownHostsFile is an error rather than a silent precedence
	// surprise.
	KnownHostsFile        string
	HostKey               string // an authorized_keys-style line, e.g. "ssh-ed25519 AAAA…"
	InsecureIgnoreHostKey bool

	// Concurrency bounds simultaneous SSH channels. Windows sshd defaults to
	// MaxSessions 10 and Terraform's default parallelism is 10, so an
	// unbounded transport exhausts the jump box.
	Concurrency int
	Timeout     time.Duration
	PwshPath    string

	// RemoteTempDir is the directory Run writes a script file to over SFTP
	// when a command is too large for -EncodedCommand (see
	// largeCommandThreshold in ssh.go). Defaults to C:\Windows\Temp. Backslash
	// and forward-slash separators are both accepted; Run normalizes to
	// forward slashes, which Windows OpenSSH's sftp-server also accepts, and
	// that is what lets a test point this at an ordinary OS temp directory.
	RemoteTempDir string
}

Config configures the SSH transport.

func (Config) Validate

func (c Config) Validate() error

Validate checks the two precedence rules before anything dials.

func (Config) WithDefaults

func (c Config) WithDefaults() Config

WithDefaults fills the unset fields.

type Transport

type Transport struct {
	// contains filtered or unexported fields
}

Transport runs PowerShell on a Windows jump box over SSH.

func New

func New(cfg Config) (*Transport, error)

New validates the configuration and dials the jump box, so a bad credential or an unknown host key surfaces at configure time rather than on the first resource operation.

func (*Transport) Close

func (t *Transport) Close() error

Close releases the connection.

func (*Transport) Run

func (t *Transport) Run(ctx context.Context, encodedCommand string, payload []byte) (adpwsh.Result, error)

Run executes one operation on a fresh channel. Commands short enough for -EncodedCommand run directly; at largeCommandThreshold or beyond, the script travels to the jump box as a temp file over SFTP and runs by path instead (see runLarge).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址