Documentation
¶
Index ¶
- Constants
- Variables
- func IsAgentNotAvailableError(e error) bool
- type Agent
- type AgentCallback
- type Authorization
- type Handler
- type Hub
- func (h *Hub) Agents() []string
- func (h *Hub) Authorizations() []Authorization
- func (h *Hub) AuthorizeKey(agent string, key *Key)
- func (h *Hub) Await(agent string) chan int
- func (h *Hub) DeauthorizeKey(agent string, key *Key)
- func (h *Hub) IgnoreReplies(ch chan *Response)
- func (h *Hub) KnowsAgent(agent string) bool
- func (h *Hub) Listen() error
- func (h *Hub) ListenAndServe() error
- func (h *Hub) Send(agent string, message []byte, timeout time.Duration) (chan *Response, error)
- func (h *Hub) Serve() error
- type Key
- type KeyMaster
- type Message
- type Response
Constants ¶
const ( UnknownDisposition disposition = 0 Authorized = 1 NotAuthorized = 2 PublicKeyExtensionName = "sfab-pubkey" Wildcard = "*" )
const DefaultKeepAlive time.Duration = 60 * time.Second
const DefaultTimeout time.Duration = 30 * time.Second
DefaultTimeout will be used as a fallback, should an Agent not set its Timeout attribute to a non-zero connect timeout.
Variables ¶
var ( AgentNotFoundError = errors.New("agent not found") AgentNotAuthorizedError = errors.New("agent not authorized") )
Functions ¶
Types ¶
type Agent ¶
type Agent struct { // Name of this agent, which will be sent to any Hub this Agent connects // to, and used to validate authorization (along with its private key). // Identity string // Private Key to use for connecting to upstream sFAB Hubs. // PrivateKey *Key // How long to wait for an upstream Hub to connect. // Timeout time.Duration // contains filtered or unexported fields }
An Agent represents a client that connects to a Hub over SSH, and awaits instructions on what to do. Each Agent has an identity (its name and private key).
func (*Agent) AcceptAnyHostKey ¶
func (a *Agent) AcceptAnyHostKey()
Instruct the Agent to (insecurely) accept any host key presented by the Hub, when connecting. This is a terrible idea in production, but can be useful in development or debugging scenarios.
Note: calling this function will obliterate any keys authorized by the AuthorizeKey() method.
func (*Agent) AuthorizeKey ¶
Authorize a specific Hub Host Key, which will be accepted from any Hub with the name or IP address given as `host`.
type AgentCallback ¶ added in v1.1.2
type Authorization ¶
type Handler ¶
A Handler is the primary workhorse of the Hub + Agent distributed orchestration engine.
Each Handler will be passed the opaque message payload from the Hub as its first argument (a slice of bytes, arbitrarily long), and two output streams: one for standard output and the other for standard error.
A Handler function returns two values: a Unix-style integer exit code, and an error that (if non-nil) will terminate the Agent's main loop.
type Hub ¶
type Hub struct { // The IP address (or hostname / FQDN) and TCP port to // bind and listen on for incoming SSH connections from // sFAB Agents. // Bind string // connecting before their private keys have been authorized // by the hub (or its operators). // AllowUnauthorizedAgents bool // Which IP protocol (tcp4 or tcp6) to use for binding // the server component of this sFAB Hub. // IPProto string // Private Key to use for the server component of this Hub. // HostKey *Key // How frequently to send KeepAlive messages to connected // agents, to keep their TCP transport channels open. // // By default, no KeepAlives are sent. // KeepAlive time.Duration // An optional function to be called when a new agent // registers with the hub (authorized or not). // OnConnect AgentCallback // An optional function to be called when a registered // agent (authorized or not) deregisters from the hub, // or is forcibly deregistered after a missed heartbeat. // OnDisconnect AgentCallback // contains filtered or unexported fields }
A Hub represents a server from whence jobs to execute are dispatched. sFAB Agents connect _to_ a Hub, and await instructions.
func (*Hub) Agents ¶
Agents() returns a list of all registered (and current!) Agent names, to allow customers to blast out messages to _everyone_ if they so desire.
func (*Hub) Authorizations ¶
func (h *Hub) Authorizations() []Authorization
func (*Hub) AuthorizeKey ¶
AuthorizeKey tells the Hub to start trusting a given SSH key pair, given the public component, for a named agent.
This can be called dynamically, long after a call to Listen(), or before.
func (*Hub) DeauthorizeKey ¶
DeauthorizeKey tells the Hub to stop trusting a given SSH key pair, given the public component, for a named agent.
This can be called dynamically, long after a call to Listen(), or before.
func (*Hub) IgnoreReplies ¶
IgnoreReplies takes a response channel from a call to Send() and discards all of the responses that are sent across.
It's perfect for a goroutine!
func (*Hub) KnowsAgent ¶
KnowsAgent checks the Hub's agent directory to see if a named agent has registered with this Hub.
func (*Hub) ListenAndServe ¶
ListenAndServe combines both the Listen() and Serve() methods into a convenient helper method that runs both, serially, and returns whichever error pops up first.
You probably want to run this in the main goroutine, much like net/http's ListenAndServe().
func (*Hub) Send ¶
Send a message to an agent (by name). Returns an error if the named agent is not currently registered with this Hub.
If an Agent is found, Responses (including output and the ultimate exit code) will be sent via the returned channel.
func (*Hub) Serve ¶
Serve handls inbound cnnections on the listening socket, and services those agents, distributing messages via a session channel and an exec request, each.
It is the caller's responsibility to call Listen() before invoking this method, or to dispense with both and just use ListenAndServe().
type Key ¶ added in v1.1.0
type Key struct {
// contains filtered or unexported fields
}
func GenerateKey ¶ added in v1.1.0
func ParseKeyFromFile ¶ added in v1.1.0
func ParseKeyFromString ¶ added in v1.1.0
func (Key) EncodeString ¶ added in v1.1.0
func (Key) Fingerprint ¶ added in v1.1.3
func (Key) IsPrivateKey ¶ added in v1.1.0
func (Key) IsPublicKey ¶ added in v1.1.0
type KeyMaster ¶
type KeyMaster struct {
// contains filtered or unexported fields
}
A KeyMaster handles the specifics of tracking which SSH key pairs are acceptable for which subjects (either hostnames, IPs, or agent names). It provides primitives for authorizing and deauthorizing these key pairs, and sports some helper methods for integrating with the rest of the x/crypto/ssh library.
func (KeyMaster) Authorizations ¶
func (m KeyMaster) Authorizations() []Authorization
func (*KeyMaster) Authorize ¶
Authorize a key pair for one or more subjects (either hostnames, IP addresses, or agent names).
func (*KeyMaster) Authorized ¶
Checks whether or not a public key has been pre-authorized for a given subject (either a hostname, IP address, or agent name).
func (*KeyMaster) Deauthorize ¶
Deauthorize a key pair for one or more subjects (either hostnames, IP addresses, or agent names).