Documentation
¶
Overview ¶
Package ssh provides strict, profile-based SSH command execution for local NFlow runtimes. Hostnames, usernames, identities, and known_hosts trust are loaded from local profiles; commands are bounded and every host key is checked against OpenSSH known_hosts data.
Package ssh provides profile-based SSH command execution.
Typical use:
profiles, err := ssh.LoadProfiles(ssh.DefaultProfilesPath()) result, err := ssh.RunCommand(ctx, profiles["staging"], "uname -s", 30*time.Second)
Index ¶
Constants ¶
const ( DefaultCommandTimeout = 30 * time.Second MaxOperationTimeout = 10 * time.Minute MaxCommandOutputBytes = 1 << 20 )
Variables ¶
var ErrOutputLimit = errors.New("ssh command output exceeded the configured byte limit")
Functions ¶
func DefaultProfilesPath ¶
func DefaultProfilesPath() string
DefaultProfilesPath returns the platform's user config path for SSH profiles.
func LoadProfiles ¶
LoadProfiles reads and validates a bounded YAML profile file. Relative identity and known_hosts paths are resolved relative to the profile file.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client owns an SSH connection and any local SSH-agent socket used to authenticate.
func Dial ¶
Dial opens a bounded SSH connection and rejects every host key absent from the profile's OpenSSH known_hosts file. It never enables agent forwarding.
type CommandResult ¶
type CommandResult struct {
Stdout string `json:"stdout"`
Stderr string `json:"stderr"`
ExitCode int `json:"exit_code"`
Duration time.Duration `json:"duration"`
}
CommandResult contains bounded command output and the remote process exit code.
func RunCommand ¶
func RunCommand(ctx context.Context, profile Profile, command string, timeout time.Duration) (CommandResult, error)
RunCommand executes one remote shell command with an overall timeout. A non-zero remote exit code is returned in the result; connection and execution failures are returned as errors.
type Profile ¶
type Profile struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
Username string `yaml:"username"`
IdentityFile string `yaml:"identity_file"`
KnownHostsFile string `yaml:"known_hosts_file"`
UseAgent bool `yaml:"use_agent"`
}
Profile describes one local SSH identity and its strict host-key trust file. Its fields are loaded from a local YAML file, never from an NFlow request.