sshtool

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const ToolExecuteRemoteCommand = "execute_remote_command"

ToolExecuteRemoteCommand is the one tool; it is unprefixed because the namespace scopes toolsets, not tools, and this is the seeded HITL policy key.

View Source
const ToolsProviderName = "native-ssh"

ToolsProviderName is the registered toolset name an allowlist addresses; the native- scope is a namespace, so a declared MCP source cannot mint the same key.

Variables

View Source
var (
	// ErrNoAllowedHosts means nothing enumerated a reachable host, so the
	// toolset can reach none; declaring it is not by itself consent to a machine.
	ErrNoAllowedHosts = errors.New("ssh: no host allowlist")

	// ErrHostNotAllowed means the requested host is outside the enumerated allowlist.
	ErrHostNotAllowed = errors.New("ssh: host not in the allowlist")

	// ErrHostKeyMismatch means the server presented a key other than the pinned one.
	ErrHostKeyMismatch = errors.New("ssh: host key mismatch")
)

Functions

func NewSSHTools

func NewSSHTools(options ...SSHOption) (taskengine.ToolsRepo, error)

NewSSHTools fails rather than returning a toolset whose host key verification could not be established.

Types

type HostKeyVerifier

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

HostKeyVerifier checks a presented key against known_hosts plus any pinned fingerprints. An unknown host is always refused: there is no safe default accept for an unverified host key, so non-strict only decides whether an unreadable known_hosts file fails construction.

func NewHostKeyVerifier

func NewHostKeyVerifier(knownHostsFile string, strict bool) (*HostKeyVerifier, error)

func (*HostKeyVerifier) AddKnownHost

func (v *HostKeyVerifier) AddKnownHost(host, fingerprint string)

AddKnownHost pins host to an exact SHA256 fingerprint, which is accepted in place of a known_hosts entry for that host alone.

func (*HostKeyVerifier) VerifyHostKey

func (v *HostKeyVerifier) VerifyHostKey(hostname string, remote net.Addr, key ssh.PublicKey) error

type SSHConfig

type SSHConfig struct {
	Host           string
	Port           int
	User           string
	Password       string
	PrivateKey     string
	PrivateKeyFile string
	Timeout        time.Duration
	// HostKey is an OPTIONAL per-call SHA256 fingerprint pin; it is checked in
	// addition to known_hosts, never instead of it.
	HostKey string
}

type SSHOption

type SSHOption func(*SSHTools) error

SSHOption configures the toolset; an option that cannot be satisfied fails construction rather than degrading a security boundary silently.

func WithAllowedHosts

func WithAllowedHosts(entries ...string) SSHOption

WithAllowedHosts is the operator's ceiling on reach: every call must match one of these entries, and a declaration's own allowlist can only narrow within it.

func WithClientCache

func WithClientCache() SSHOption

func WithCustomHostKeyCallback

func WithCustomHostKeyCallback(callback ssh.HostKeyCallback) SSHOption

func WithDefaultPort

func WithDefaultPort(port int) SSHOption

func WithDefaultTimeout

func WithDefaultTimeout(timeout time.Duration) SSHOption

func WithFileRoot

func WithFileRoot(dir string) SSHOption

WithFileRoot scopes every local file this toolset reads — the known_hosts file and any private key file — to dir: a read that resolves outside it is refused. It is the operator's ceiling on local file reach, the same containment seam local_fs uses. Unset, only the control-plane deny binds (see containFile).

func WithKnownHostsFile

func WithKnownHostsFile(path string) SSHOption

func WithName

func WithName(name string) SSHOption

func WithStrictHostKey

func WithStrictHostKey() SSHOption

WithStrictHostKey records the intent; the verifier is built once after every option has run, so this no longer depends on being ordered after WithKnownHostsFile.

type SSHResult

type SSHResult struct {
	ExitCode  int     `json:"exit_code"`
	Stdout    string  `json:"stdout"`
	Stderr    string  `json:"stderr"`
	Duration  float64 `json:"duration_seconds"`
	Command   string  `json:"command"`
	Host      string  `json:"host"`
	User      string  `json:"user"`
	Success   bool    `json:"success"`
	Truncated bool    `json:"truncated,omitempty"`
	Error     string  `json:"error,omitempty"`
	HostKey   string  `json:"host_key,omitempty"`
}

type SSHTools

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

func (*SSHTools) Close

func (h *SSHTools) Close() error

func (*SSHTools) Exec

func (h *SSHTools) Exec(ctx context.Context, _ time.Time, input any, _ bool, tools *taskengine.ToolsCall) (any, taskengine.DataType, error)

func (*SSHTools) GetSchemasForSupportedTools

func (h *SSHTools) GetSchemasForSupportedTools(_ context.Context) (map[string]*openapi3.T, error)

func (*SSHTools) GetToolsForToolsByName

func (h *SSHTools) GetToolsForToolsByName(_ context.Context, name string) ([]taskengine.Tool, error)

func (*SSHTools) Precheck

func (h *SSHTools) Precheck(ctx context.Context, input any, tools *taskengine.ToolsCall) error

Precheck refuses a host the allowlist does not name without opening a connection, so an out-of-scope call never costs a human an approval decision; it is an early copy, never a replacement — Exec applies the same boundary.

func (*SSHTools) Supports

func (h *SSHTools) Supports(context.Context) ([]string, error)

Jump to

Keyboard shortcuts

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