Documentation ¶
Overview ¶
A runner package that executes commands on remote hosts.
Index ¶
- Constants
- func AddKnownHost(host string, remote net.Addr, key ssh.PublicKey, knownFile string) (err error)
- func CheckKnownHost(host string, remote net.Addr, key ssh.PublicKey, knownFile string) (found bool, err error)
- func DefaultIdentityFilePath() (string, error)
- func DefaultKnownHosts() (ssh.HostKeyCallback, error)
- func DefaultKnownHostsPath() (string, error)
- func EncodePrivateKeyToPEM(privateKey *rsa.PrivateKey) ([]byte, error)
- func GeneratePrivateKey(bitSize int) (*rsa.PrivateKey, error)
- func GetKeyBytes() ([]byte, []byte, error)
- func GetPublicKeyBytes(key *rsa.PublicKey) ([]byte, error)
- func GetSSMCommandInvocationStdErr(out ssm.GetCommandInvocationOutput) string
- func GetSSMCommandInvocationStdOut(out ssm.GetCommandInvocationOutput) string
- type AWSRunner
- func (run AWSRunner) AssociateInstanceProfileWithRunner(cfg aws.Config, instanceProfile types.InstanceProfile) (string, error)
- func (run AWSRunner) DisassociateInstanceProfileFromRunner(cfg aws.Config, associationID string) error
- func (run AWSRunner) RunSSMCommandOnRemoteHost(cfg aws.Config, operation string) (ssm.GetCommandInvocationOutput, error)
- func (run AWSRunner) SendAndUseIdentityFile(cfg aws.Config) error
- func (run AWSRunner) SendPublicKey(pubBytes []byte, cfg aws.Config) error
- type GCPRunner
- type Runner
Constants ¶
const SSMInstancePolicy string = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
Variables ¶
This section is empty.
Functions ¶
func AddKnownHost ¶
AddKnownHost adds a host to the provided known hosts file, if no known hosts file is provided, it will fallback to default known_hosts file
func CheckKnownHost ¶
func CheckKnownHost(host string, remote net.Addr, key ssh.PublicKey, knownFile string) (found bool, err error)
CheckKnownHost checks if a host is in known hosts file, if no known hosts file is provided, it will fallback to default known_hosts file
func DefaultIdentityFilePath ¶
func DefaultKnownHosts ¶
func DefaultKnownHosts() (ssh.HostKeyCallback, error)
DefaultKnownHosts returns a host key callback from default known hosts path
func DefaultKnownHostsPath ¶
DefaultKnownHostsPath returns default user ~/.ssh/known_hosts file
func EncodePrivateKeyToPEM ¶
func EncodePrivateKeyToPEM(privateKey *rsa.PrivateKey) ([]byte, error)
Encodes private key from RSA struct to PEM formatted bytes
func GeneratePrivateKey ¶
func GeneratePrivateKey(bitSize int) (*rsa.PrivateKey, error)
Helper function to generate a random private key. This key will stay in memory and does not persist across test runs.
func GetKeyBytes ¶
Generates SSH keys in EC2-readable format Returns public key bytes, private key bytes, error
func GetPublicKeyBytes ¶
Takes an rsa.PublicKey and returns bytes suitable for writing to .pub file Returns in the format "ssh-rsa ..."
func GetSSMCommandInvocationStdErr ¶
func GetSSMCommandInvocationStdErr(out ssm.GetCommandInvocationOutput) string
GetSSMCommandInvocationStdErr is a helper function to safely deference the SSM struct we receive from the AWS API.
func GetSSMCommandInvocationStdOut ¶
func GetSSMCommandInvocationStdOut(out ssm.GetCommandInvocationOutput) string
GetSSMCommandInvocationStdOut is a helper function to safely deference the SSM struct we receive from the AWS API.
Types ¶
type AWSRunner ¶
type AWSRunner struct { Runner Runner Region string AvailabilityZone string InstanceID string ImageName string }
func NewAWSRunner ¶
func (AWSRunner) AssociateInstanceProfileWithRunner ¶
func (run AWSRunner) AssociateInstanceProfileWithRunner( cfg aws.Config, instanceProfile types.InstanceProfile, ) (string, error)
AssociateInstanceProfileWithRunner associates a given instance profile with the receiving runner. First checks if there are any instance profiles already associated with the runner, and returns an error if so (since a runner can only have one instance profile associated with it). Then associates the instance profile with the runner. Returns the association ID or an error.
func (AWSRunner) DisassociateInstanceProfileFromRunner ¶
func (AWSRunner) RunSSMCommandOnRemoteHost ¶
func (run AWSRunner) RunSSMCommandOnRemoteHost(cfg aws.Config, operation string) ( ssm.GetCommandInvocationOutput, error, )
RunSSMCommandOnRemoteHost takes a shell command to install the agent on the runner the runner and executes it using SSM. `operation` must be one of the commands allowed by the SSM document. This function will not return until the command is in a terminal state, or until 2min have passed.
func (AWSRunner) SendAndUseIdentityFile ¶
func (AWSRunner) SendPublicKey ¶
Helper function to send a public key to a test instance. Uses EC2InstanceConnect. The AWS account used to run the tests must have EC2InstanceConnect permissions attached to its IAM role. First checks to make sure the instance is still running.
type GCPRunner ¶
type GCPRunner struct { Runner Runner ParentUsername string ProjectID string AvailabilityZone string InstanceID string }
func NewGCPRunner ¶
func NewGCPRunner( host, parentUsername, projectID, availabilityZone, instanceID string, callback ssh.HostKeyCallback, ) (*GCPRunner, error)
func (GCPRunner) SendAndUseIdentityFile ¶
func (GCPRunner) SendPublicKey ¶
SendPublicKey is a helper function to send a public key to a GCP account for OSLogin authentication. The account must have the "Compute OS Login" IAM role and "Service Account User" authorization for the GCE default service account. When the SSH key is sent, it will persist in the GCP account for 10min.
type Runner ¶
type Runner struct { Hostname string Port int *ssh.ClientConfig }