environment

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	VPNPortmin = 5000
	VPNPortmax = 6000
)
View Source
var (
	DefaultAdminUser = "guacadmin"
	DefaultAdminPass = "guacadmin"
)

Functions

func ShellExec

func ShellExec(cmd string, args ...string) ([]byte, error)

Types

type Action

type Action string

type Category

type Category struct {
	Tag            string `json:"tag,omitempty"`
	Name           string `json:"name,omitempty"`
	CatDescription string `json:"catDesc,omitempty"`
}

type Chain

type Chain string

type CreateRDPConnOpts

type CreateRDPConnOpts struct {
	Host             string
	Port             uint
	Name             string
	GuacUser         string
	Username         *string
	Password         *string
	EnableWallPaper  *bool
	ResolutionWidth  uint
	ResolutionHeight uint
	MaxConn          uint
	ColorDepth       uint
	EnableDrive      *bool
	CreateDrivePath  *bool
	DrivePath        *string
}

type EnvConfig

type EnvConfig struct {
	Tag             string
	TeamSize        int
	Type            lab.LabType
	VPNAddress      string
	VPNEndpointPort int
	VpnConfig       wg.WireGuardConfig
	WorkerPool      worker.WorkerPool
	LabConf         lab.LabConf
	Status          Status
}

func (*EnvConfig) NewEnv

func (ec *EnvConfig) NewEnv(ctx context.Context) (*Environment, error)

type EnvPool

type EnvPool struct {
	M *sync.RWMutex
	// Map of environments with eventTag as key
	Envs         map[string]*Environment
	StartingEnvs map[string]bool
	ClosingEnvs  map[string]bool
}

General environment types

func (*EnvPool) AddClosingEnv added in v1.0.0

func (ep *EnvPool) AddClosingEnv(eventTag string)

func (*EnvPool) AddEnv

func (ep *EnvPool) AddEnv(env *Environment)

func (*EnvPool) AddStartingEnv added in v1.0.0

func (ep *EnvPool) AddStartingEnv(eventTag string)

func (*EnvPool) DoesEnvExist

func (ep *EnvPool) DoesEnvExist(tag string) bool

func (*EnvPool) GetClosingEnvs added in v1.0.0

func (ep *EnvPool) GetClosingEnvs() map[string]bool

func (*EnvPool) GetEnv

func (ep *EnvPool) GetEnv(tag string) (*Environment, error)

func (*EnvPool) GetEnvList added in v1.0.0

func (ep *EnvPool) GetEnvList() (envList map[string]bool)

func (*EnvPool) GetFullLabCount

func (ep *EnvPool) GetFullLabCount() uint32

func (*EnvPool) GetLabByTag

func (ep *EnvPool) GetLabByTag(tag string) (*lab.Lab, error)

Returns a lab from the env pool if the lab tag exists in any of the environments

func (*EnvPool) GetStartingEnvs added in v1.0.0

func (ep *EnvPool) GetStartingEnvs() map[string]bool

func (*EnvPool) LockForFunc added in v1.0.0

func (ep *EnvPool) LockForFunc(function func())

func (*EnvPool) RemoveClosingEnv added in v1.0.0

func (ep *EnvPool) RemoveClosingEnv(eventTag string)

func (*EnvPool) RemoveEnv

func (ep *EnvPool) RemoveEnv(tag string) error

Removes an environment from the environment pool

func (*EnvPool) RemoveStartingEnv added in v1.0.0

func (ep *EnvPool) RemoveStartingEnv(eventTag string)

type Environment

type Environment struct {
	M             *sync.RWMutex
	EnvConfig     *EnvConfig
	Guac          Guacamole
	IpT           IPTables
	IpRules       map[string]IpRules
	IpAddrs       [][]int
	Wg            wgproto.WireguardClient
	GuacUserStore *GuacUserStore
	Dockerhost    virtual.Host
	Labs          map[string]*lab.Lab
}

func (*Environment) Close

func (env *Environment) Close() error

Closes environment including removing all related containers, and vpn configs

func (*Environment) CreateGuacConn

func (env *Environment) CreateGuacConn(lab lab.Lab) error

Connects VMs in a lab to the corresponding guacamole instance for the environment.

func (*Environment) RemoveVpnLabPeers

func (env *Environment) RemoveVpnLabPeers(ctx context.Context, labTag string) error

func (*Environment) Start

func (env *Environment) Start(ctx context.Context) error

type Errori

type Errori struct {
	Out []byte
	Err error
}

func (Errori) Error

func (e Errori) Error() string

type ExecFunc

type ExecFunc func(cmd string, args ...string) ([]byte, error)

type GuacError

type GuacError struct {
	// contains filtered or unexported fields
}

TODO Go through all the code, make sure it makes sense, comment the code

func (*GuacError) Error

func (ge *GuacError) Error() string

type GuacUser

type GuacUser struct {
	Username string
	Password string
}

type GuacUserStore

type GuacUserStore struct {
	// contains filtered or unexported fields
}

func NewGuacUserStore

func NewGuacUserStore() *GuacUserStore

type Guacamole

type Guacamole struct {
	Client     *http.Client
	Token      string
	Port       uint
	AdminPass  string
	Containers map[string]*virtual.Container
}

Guac types

func NewGuac

func NewGuac(ctx context.Context, eventTag string) (Guacamole, error)

Creates a new Guacamole struct for an environment.

func (*Guacamole) Close

func (guac *Guacamole) Close() error

func (*Guacamole) CreateRDPConn

func (guac *Guacamole) CreateRDPConn(opts CreateRDPConnOpts) error

Creates the Apache Guacamole RDP connection to a specific vm

func (*Guacamole) CreateUser

func (guac *Guacamole) CreateUser(username, password string) error

Creates a new user in Apache guacamole which can access a specific set of VMs

func (*Guacamole) GetPortFromConnectionIdentifier

func (guac *Guacamole) GetPortFromConnectionIdentifier(connectionIdentifier string) (string, error)

func (*Guacamole) RawLogin

func (guac *Guacamole) RawLogin(username, password string) ([]byte, error)

type IPTables

type IPTables struct {
	Sudo bool

	// Flags to service
	Flags []string

	// enable Debug or not
	Debug bool

	// Implementation of ExecFunc.
	ExecFunc ExecFunc

	// Implementation of PipeFunc.
	PipeFunc PipeFunc
}

func (*IPTables) CreateAcceptRule

func (ipTab *IPTables) CreateAcceptRule(labSubnet string, vpnIPs string) error

iptables --insert DOCKER-USER -s 77.179.248.0/24 -d 25.136.240.250/32,25.136.241.249/32,25.136.242.248/32,25.136.243.247/32,77.179.248.0/24 -j ACCEPT

func (*IPTables) CreateRejectRule

func (ipTab *IPTables) CreateRejectRule(labSubnet string) error

iptables --insert DOCKER-USER -s 77.179.248.0/24 -j REJECT --reject-with icmp-port-unreachable

func (*IPTables) CreateStateRule

func (ipTab *IPTables) CreateStateRule(labSubnet string) error

sudo iptables --insert DOCKER-USER -s 77.218.127.0/24 -m state --state RELATED,ESTABLISHED -j RETURN

func (*IPTables) RemoveAcceptRule

func (ipTab *IPTables) RemoveAcceptRule(labSubnet string, vpnIps string) error

func (*IPTables) RemoveRejectRule

func (ipTab *IPTables) RemoveRejectRule(labSubnet string) error

func (*IPTables) RemoveStateRule

func (ipTab *IPTables) RemoveStateRule(labSubnet string) error

type IpRules

type IpRules struct {
	Labsubnet string
	VpnIps    string
}

type PChallenge

type PChallenge struct {
	Tag  string `json:"tag,omitempty"`
	Name string `json:"name,omitempty"`
}

type PipeFunc

type PipeFunc func(stdin io.Reader, cmd string, args ...string) ([]byte, error)

type Policy

type Policy string

type Profile

type Profile struct {
	Name       string       `json:"name,omitempty"`
	Secret     bool         `json:"secret,omitempty"`
	Challenges []PChallenge `json:"challenges,omitempty"`
}

type Status

type Status uint8
const (
	StatusRunning Status = iota
	StatusUpdating
	StatusClosing
	StatusClosed
)

Directories

Path Synopsis
lab

Jump to

Keyboard shortcuts

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