remote

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 23 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package remote implements SSH-based remote command execution for node workflows.

Index

Constants

View Source
const (
	ReasonConfig          = "config"
	ReasonDNS             = "dns"
	ReasonRefused         = "connection_refused"
	ReasonTimeout         = "timeout"
	ReasonConnect         = "connect"
	ReasonUnknownHostKey  = "unknown_host_key"
	ReasonHostKeyMismatch = "host_key_mismatch"
	ReasonHostKeyRevoked  = "host_key_revoked"
	ReasonAuth            = "auth"
	ReasonHandshake       = "handshake"
	ReasonSession         = "session"
)

Reasons a host failed before its command could run. A caller running one command across many hosts uses them to group hosts that failed the same way and explain each problem once instead of once per host.

View Source
const DefaultBootstrapURL = "https://omnitruck.cinc.sh/install.sh"

Variables

This section is empty.

Functions

func BootstrapCommand

func BootstrapCommand(opts BootstrapOptions) (string, error)

BootstrapCommand builds the shell command executed on the target.

func CheckOptions added in v0.30.0

func CheckOptions(opts SSHOptions) error

CheckOptions checks everything about opts that doesn't depend on which host is being reached: a user is set, the identity file is a usable private key, and known_hosts can be read when host keys are verified. Callers run it before doing anything with a side effect, so a typo in --ssh-identity-file doesn't surface only after work has started, and doesn't repeat once per host.

func JoinWords added in v0.30.0

func JoinWords(items []string) string

JoinWords joins items as English prose: "a", "a and b", "a, b, and c".

func QuoteArg added in v0.30.0

func QuoteArg(s string) string

QuoteArg quotes s for a POSIX shell, leaving it bare when it is made only of characters a shell treats literally, so suggested commands stay readable: web01.example.com and role:web need no quotes.

It is for display: control characters and terminal escapes are removed first, so a value from a remote host can't rewrite the screen.

func SanitizeLine added in v0.30.0

func SanitizeLine(s string) string

SanitizeLine is SanitizeText for a value printed on one line: newlines and tabs become spaces.

func SanitizeText added in v0.30.0

func SanitizeText(s string) string

SanitizeText makes text from a remote host or the server safe to print: it removes terminal escape sequences, control characters, and invisible formatting characters such as right-to-left overrides, keeping newlines and tabs. Host names come from what a node reports about itself, so a compromised node could otherwise clear the screen or disguise a command.

func ValidateBootstrapOptions added in v0.30.0

func ValidateBootstrapOptions(opts BootstrapOptions) error

ValidateBootstrapOptions checks the values the bootstrap script embeds, apart from the client key. The command calls it before registering a client on the server, so a value the script would refuse doesn't leave a client behind.

Types

type BootstrapOptions

type BootstrapOptions struct {
	NodeName         string
	ServerURL        string
	ClientKeyPEM     string
	RunList          []string
	Environment      string
	PolicyName       string
	PolicyGroup      string
	Sudo             bool
	BootstrapURL     string
	BootstrapVersion string
}

BootstrapOptions describes the remote Cinc Client bootstrap script.

type CommandResult

type CommandResult struct {
	Host     string `json:"host"`
	Stdout   string `json:"stdout,omitempty"`
	Stderr   string `json:"stderr,omitempty"`
	ExitCode int    `json:"exit_code"`
	Error    string `json:"error,omitempty"`
	// Skipped marks a host the command was never attempted on, because
	// --exit-on-error stopped the run first. It is not a failure: the host
	// was not asked to do anything, so nothing is known about it.
	Skipped bool `json:"skipped,omitempty"`
	// Reason classifies a failure that happened before the command could
	// run, such as an unknown host key or a refused connection; it is one of
	// the Reason constants. It is empty when the command itself ran.
	Reason string `json:"reason,omitempty"`
	// Hint explains Reason: why it happens and what to do about it. Error
	// holds the one-line summary.
	Hint string `json:"hint,omitempty"`
}

CommandResult is the result of one command on one host.

func RunMany

func RunMany(ctx context.Context, runner Runner, targets []Target, command string, opts SSHOptions, concurrency int, exitOnError bool) []CommandResult

RunMany executes command across targets, limiting concurrency and preserving the input order in the returned results.

With exitOnError, the first non-zero exit stops further launches. Commands already running are left to finish, which is what the flag promises, and every host that never ran comes back marked Skipped rather than failed.

type Error added in v0.30.0

type Error struct {
	Reason  string
	Summary string
	Hint    string
	Err     error
}

Error is an SSH failure explained for someone who may never have used SSH much. Summary is one line naming what went wrong; Hint says why it happens and what to do about it. Error() joins the two. Err is the underlying error, so errors.Is and errors.As still see through it.

func (*Error) Error added in v0.30.0

func (e *Error) Error() string

func (*Error) Unwrap added in v0.30.0

func (e *Error) Unwrap() error

type NativeRunner

type NativeRunner struct{}

NativeRunner is a Runner backed by golang.org/x/crypto/ssh.

func (NativeRunner) Run

func (NativeRunner) Run(ctx context.Context, target Target, command string, opts SSHOptions) CommandResult

Run executes command on target through SSH. A failure before the command could run comes back with Reason and Hint set, explaining it.

type Runner

type Runner interface {
	Run(ctx context.Context, target Target, command string, opts SSHOptions) CommandResult
}

Runner executes a command on a target.

type SSHOptions

type SSHOptions struct {
	User         string
	Password     string
	IdentityFile string
	AgentSocket  string
	Port         int
	Timeout      time.Duration
	UseAgent     bool
	VerifyHost   bool
}

SSHOptions configures native SSH connections.

type Target

type Target struct {
	Host string `json:"host"`
}

Target identifies one remote host.

Jump to

Keyboard shortcuts

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