Documentation
¶
Overview ¶
Package remote implements SSH-based remote command execution for node workflows.
Index ¶
- Constants
- func BootstrapCommand(opts BootstrapOptions) (string, error)
- func CheckOptions(opts SSHOptions) error
- func JoinWords(items []string) string
- func QuoteArg(s string) string
- func SanitizeLine(s string) string
- func SanitizeText(s string) string
- func ValidateBootstrapOptions(opts BootstrapOptions) error
- type BootstrapOptions
- type CommandResult
- type Error
- type NativeRunner
- type Runner
- type SSHOptions
- type Target
Constants ¶
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.
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
JoinWords joins items as English prose: "a", "a and b", "a, b, and c".
func QuoteArg ¶ added in v0.30.0
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
SanitizeLine is SanitizeText for a value printed on one line: newlines and tabs become spaces.
func SanitizeText ¶ added in v0.30.0
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
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.
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.