Version: v0.6.0 Latest Latest

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

Go to latest
Published: Feb 25, 2020 License: Apache-2.0 Imports: 14 Imported by: 0




This section is empty.


This section is empty.


func CreateRemoteStateBucket

func CreateRemoteStateBucket(logger *logrus.Logger, bucket string) error

CreateRemoteStateBucket initialises a remote-state bucket

func EnsureLatestTfVarsFile

func EnsureLatestTfVarsFile(tfVarsDir, publicKey, accessCIDR, bucket, attackTag, attackRepo, extraCIDRs string) error

EnsureLatestTfVarsFile always writes an tfvars file

func Perturb

func Perturb(po *PerturbOptions, logger *logrus.Logger) (*string, error)

Perturb runs the perturb script with the supplied options


type Option

type Option func(*Simulator)

Option is a type used to configure a `Simulator` instance

func WithAttackRepo added in v0.6.0

func WithAttackRepo(attackRepo string) Option

WithAttackRepo returns a configurer for creating a `Simulator` instance with `NewSimulator`

func WithAttackTag

func WithAttackTag(attackTag string) Option

WithAttackTag returns a configurer for creating a `Simulator` instance with `NewSimulator`

func WithBucketName

func WithBucketName(bucketName string) Option

WithBucketName returns a configurer for creating a `Simulator` instance with `NewSimulator`

func WithExtraCIDRs added in v0.6.0

func WithExtraCIDRs(extraCIDRs string) Option

WithExtraCIDRs returns a configurer for creating a `Simulator` instance with `NewSimulator`

func WithLogger

func WithLogger(logger *logrus.Logger) Option

WithLogger returns a configurer for creating a `Simulator` instance with `NewSimulator`

func WithScenarioID

func WithScenarioID(scenarioID string) Option

WithScenarioID returns a configurer for creating a `Simulator` instance with `NewSimulator`

func WithScenariosDir

func WithScenariosDir(scenariosDir string) Option

WithScenariosDir returns a configurer for creating a `Simulator` instance with `NewSimulator`

func WithTfDir

func WithTfDir(tfDir string) Option

WithTfDir returns a configurer for creating a `Simulator` instance with `NewSimulator`

func WithTfVarsDir

func WithTfVarsDir(tfVarsDir string) Option

WithTfVarsDir returns a configurer for creating a `Simulator` instance with `NewSimulator`

func WithoutIPDetection added in v0.6.0

func WithoutIPDetection(disableIPDetection bool) Option

WithoutIPDetection returns a configurer for creating a `Simulator` instance with `NewSimulator`

type PerturbOptions

type PerturbOptions struct {
	Bastion      net.IP
	Master       net.IP
	Slaves       []net.IP
	ScenarioName string

PerturbOptions represents the parameters required by the script

func MakePerturbOptions

func MakePerturbOptions(tfo TerraformOutput, path string) PerturbOptions

MakePerturbOptions takes a TerraformOutput and a path to a scenario and makes a struct of PerturbOptions

func (*PerturbOptions) String

func (po *PerturbOptions) String() string

func (*PerturbOptions) ToArguments

func (po *PerturbOptions) ToArguments() []string

ToArguments converts a PerturbOptions struct into a slice of strings containing the command line options to pass to perturb

type SSHConfig

type SSHConfig struct {
	Alias              string
	Hostname           string
	KeyFilePath        string
	KnownHostsFilePath string
	BastionIP          string

SSHConfig represents the values needed to produce a config block to allow SSH to the private kubernetes nodes via the bastion

type Simulator

type Simulator struct {
	// Logger is the logger the simulator will use
	Logger *logrus.Logger
	// TfDir is the path to the terraform code used to standup the simulator cluster
	TfDir string
	// BucketName is the remote state bucket to use for terraform
	BucketName string
	// AttackTag is the docker tag for the attack container that terraform will use
	// when creating the infrastructure: e.g. latest
	AttackTag string
	// AttackRepo is the docker repo for the attack container that terraform will use
	// when creating the infrastructure: e.g. controlplane/simulator-attack
	AttackRepo string
	// scenarioID is the unique identifier of the scenario used for the launch function
	ScenarioID string
	// TfVarsDir is the location to store the terraform variables file that are detected
	// automatically for use when creating the infrastructure
	TfVarsDir string
	// ScenariosDir is the location of the scenarios for perturb to use when perturbing
	// the cluster
	ScenariosDir string
	// disableIPDetection enables IP checks used for cidr access. Enabled by default.
	DisableIPDetection bool
	// Extra CIDRs to be added to the bastion security group to allow SSH from arbitrary
	// locations
	ExtraCIDRs string

Simulator represents a session with simulator and holds all the configuration necessary to run simulator

func NewSimulator

func NewSimulator(options ...Option) *Simulator

NewSimulator constructs a new instance of `Simulator`

func (*Simulator) Attack

func (s *Simulator) Attack() error

Attack establishes an SSH connection to the attack container running on the bastion host ready for the user to attempt to complete a scenario

func (*Simulator) Create

func (s *Simulator) Create() error

Create runs terraform init, plan, apply to create the necessary infrastructure to run scenarios

func (*Simulator) Destroy

func (s *Simulator) Destroy() error

Destroy call terraform destroy to remove the infrastructure

func (*Simulator) InitIfNeeded

func (s *Simulator) InitIfNeeded() error

InitIfNeeded checks the IP address and SSH key and updates the tfvars if needed

func (*Simulator) Launch

func (s *Simulator) Launch() error

Launch runs to setup a scenario with the supplied `id` assuming the infrastructure has been created. Returns an error if the infrastructure is not ready or something goes wrong

func (*Simulator) PrepareTfArgs

func (s *Simulator) PrepareTfArgs(cmd string) []string

PrepareTfArgs takes a string with the terraform command desired and returns a slice of strings containing the complete list of arguments including the command to use when exec'ing terraform

func (*Simulator) SSHConfig

func (s *Simulator) SSHConfig() (*string, error)

SSHConfig returns a pointer to string containing the stanzas to add to an ssh config file so that the kubernetes nodes are connectable directly via the bastion or an error if the infrastructure has not been created

func (*Simulator) Status

func (s *Simulator) Status() (*TerraformOutput, error)

Status calls terraform output to get the state of the infrastruture and parses the output for programmatic use

func (*Simulator) Terraform

func (s *Simulator) Terraform(cmd string) (*string, error)

Terraform wraps running terraform as a child process func Terraform(wd, cmd string, bucket, tfVarsDir string) (*string, error) {

type StringOutput

type StringOutput struct {
	Sensitive bool   `json:"sensitive"`
	Type      string `json:"type"`
	Value     string `json:"value"`

StringOutput is a struct representing an output from terraform that contains a string

type StringSliceOutput

type StringSliceOutput struct {
	Sensitive bool          `json:"sensitive"`
	Type      []interface{} `json:"type"`
	Value     []string      `json:"value"`

StringSliceOutput is a struct representing an output from terraform that contains a slice of strings

type TerraformOutput

type TerraformOutput struct {
	BastionPublicIP       StringOutput      `json:"bastion_public_ip"`
	ClusterNodesPrivateIP StringSliceOutput `json:"cluster_nodes_private_ip"`
	MasterNodesPrivateIP  StringSliceOutput `json:"master_nodes_private_ip"`

TerraformOutput is a struct representing the expected output variables from the terraform script

func ParseTerraformOutput

func ParseTerraformOutput(output string) (*TerraformOutput, error)

ParseTerraformOutput takes a string containing the stdout from `terraform output -json` and returns a TerraformOutput struct

func (*TerraformOutput) IsUsable

func (tfo *TerraformOutput) IsUsable() bool

IsUsable checks whether the TerraformOutput has all the necessary information to be converted for use with perturb

func (*TerraformOutput) ToSSHConfig

func (tfo *TerraformOutput) ToSSHConfig() (*string, error)

ToSSHConfig produces the SSH config

type TfVars

type TfVars struct {
	PublicKey  string
	AccessCIDR string
	BucketName string
	AttackTag  string
	AttackRepo string
	ExtraCIDRs string

TfVars struct representing the input variables for terraform to create the infrastructure

func NewTfVars

func NewTfVars(publicKey, accessCIDR, bucketName, attackTag, attackRepo, extraCIDRs string) TfVars

NewTfVars creates a TfVars struct with all the defaults

func (*TfVars) String

func (tfv *TfVars) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL