config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const SERVICE_CHALL_RUN_CMD string = "xinetd -dontfork"
View Source
const SERVICE_CONTAINER_DEPS string = "xinetd"

Variables

View Source
var SkipAuthorization bool
View Source
var USED_PORTS_LIST []uint32

Functions

func GetAvailableChallengeTypes

func GetAvailableChallengeTypes() []string

func InitConfig

func InitConfig()

InitConfig loads the config from the global config file and populate the Cfg global variable used everywhere else.

func NewPortMapping

func NewPortMapping(hp, cp uint32) cr.PortMapping

NewPortMapping returns a new port mapping instance.

func ReloadBeastConfig

func ReloadBeastConfig() error

ReloadBeastConfig reloads the beast configuration and reinitializes the Cfg global variable.

func UpdateCompetitionInfo

func UpdateCompetitionInfo(competitionInfo *CompetitionInfo) error

func UpdateUsedPortList

func UpdateUsedPortList()

Update the USED_PORT_LIST variable in config. Don't do this very often, we do this once during syncing the git repository then whenever you need updated used port list you need to sync the git remote by beast.

Types

type Author

type Author struct {
	Name   string `toml:"name"`
	Email  string `toml:"email"`
	SSHKey string `toml:"ssh_key"`
}

Metadata related to author of the challenge, this structure includes

  • Name - Name of the author of the challenge
  • Email - Email of the author
  • SSHKey - Public SSH key for the challenge author, to give the access to the challenge container.

```toml # Optional fields name = ""

# Required Fields email = "" ssh_key = "" # Public ssh Key of the author. ```

func (*Author) PopulateAuthor

func (Author *Author) PopulateAuthor()

func (*Author) ValidateRequiredFields

func (config *Author) ValidateRequiredFields() error

type BeastChallengeConfig

type BeastChallengeConfig struct {
	Challenge   Challenge `toml:"challenge"`
	Author      Author    `toml:"author"`
	Resources   Resources `toml:"resource"`
	Maintainers []Author  `toml:"maintainer"`
}

This is the beast challenge config file structure any other field specified in the file other than this structure will be ignored.

Take a look at template beast.toml file in templates package to see how to specify the file and what all fields are available.

func (*BeastChallengeConfig) PopulateDefualtValues

func (config *BeastChallengeConfig) PopulateDefualtValues()

func (*BeastChallengeConfig) ValidateRequiredFields

func (config *BeastChallengeConfig) ValidateRequiredFields(challdir string) error

type BeastConfig

type BeastConfig struct {
	AuthorizedKeysFile   string                `toml:"authorized_keys_file"`
	BeastScriptsDir      string                `toml:"scripts_dir"`
	AllowedBaseImages    []string              `toml:"allowed_base_images"`
	AvailableSidecars    []string              `toml:"available_sidecars"`
	GitRemotes           []GitRemote           `toml:"remote"`
	JWTSecret            string                `toml:"jwt_secret"`
	NotificationWebhooks []NotificationWebhook `toml:"notification_webhooks"`
	CompetitionInfo      CompetitionInfo       `toml:"competition_info"`
	TickerFrequency      int                   `toml:"ticker_frequency"`

	RemoteSyncPeriod time.Duration `toml:"-"`
	Rsp              string        `toml:"remote_sync_period"`

	CPUShares int64 `toml:"default_cpu_shares"`
	Memory    int64 `toml:"default_memory_limit"`
	PidsLimit int64 `toml:"default_pids_limit"`
}

This is the global beast configuration structure

An example of a config file

```toml # Authorized key file used by ssh daemon running on the host # This is used for forwarding ssh connection to docker containers, the # access to a container is only given to the author, maintainers of challenge and admin. authorized_keys_file = "/home/fristonio/.beast/beast_authorized_keys"

# Directory which will contain all the autogenerated scripts by beast # These scripts are the heart to above authorized keys file. Each entry in authorized # keys file as a corresponding script which is executed during an SSH attempt. scripts_dir = "/home/fristonio/.beast/scripts"

# Base OS image that beast allows the challenges to use. allowed_base_images = ["ubuntu:18.04", "ubuntu:16.04", "debian:jessie"]

# For authentication purposes beast uses JWT based authentication, this is the # key used for encrypting the claims of a user. Keep this strong. jwt_secret = "beast_jwt_secret_SUPER_STRONG_0x100010000100"

# To allow beast to send notification to a notification channel povide this webhook URL # We are also working on implmeneting notification using Discord and IRC. slack_webhook = ""

# The sidecar that we support with beast, currently we only support two MySQL and # MongoDB. available_sidecars = ["mysql", "mongodb"]

# The frequency for any periodic event in beast, the value is provided in seconds. # This is currently only used for health check periodic duration.s ticker_frequency = 3000

# Container default resource limits for each challenge, this can be # Overridden by challenge configuration beast.toml file. default_cpu_shares = 1024 default_memory_limit = 1024 default_pids_limit = 100

# Configuration corresponding to the remote repository used by beast # We use ssh authentication mechanism for interacting with git repository. [remote]

# URL of the remote git repository, this should be user@host:<git_repository> format url = "git@github.com:sdslabs/hack-test.git"

# Name of the remote name = "hack-test"

# Branch we are tracking the remote in beast. branch = "master"

# Path to private SSH key for interacting with the git repository. ssh_key = "/home/fristonio/.beast/secrets/key.priv" ```

var Cfg *BeastConfig

func LoadBeastConfig

func LoadBeastConfig(configPath string) (BeastConfig, error)

From the path of the config file provided as an arguement this function loads the parse the config file and load it into the BeastConfig structure. After parsing it validates the data in the config file and returns error if the validation fails.

func (*BeastConfig) ValidateConfig

func (config *BeastConfig) ValidateConfig() error

type Challenge

type Challenge struct {
	Metadata ChallengeMetadata `toml:"metadata"`
	Env      ChallengeEnv      `toml:"env"`
}

This structure contains information related to challenge, Challenge Metadata

* ChallengeEnv - Challenge environment configuration variables * ChallengeMetadata - Challenge Metadata configuration variables

func (*Challenge) ValidateRequiredFields

func (config *Challenge) ValidateRequiredFields(challdir string) error

type ChallengeEnv

type ChallengeEnv struct {
	AptDeps          []string         `toml:"apt_deps"`
	Ports            []uint32         `toml:"ports"`
	DefaultPort      uint32           `toml:"default_port"`
	PortMappings     []string         `toml:"port_mappings"`
	SetupScripts     []string         `toml:"setup_scripts"`
	StaticContentDir string           `toml:"static_dir"`
	RunCmd           string           `toml:"run_cmd"`
	BaseImage        string           `toml:"base_image"`
	WebRoot          string           `toml:"web_root"`
	ServicePath      string           `toml:"service_path"`
	Entrypoint       string           `toml:"entrypoint"`
	DockerCtx        string           `toml:"docker_context"`
	EnvironmentVars  []EnvironmentVar `toml:"var"`
	Traffic          string           `toml:"traffic"`
}

This contains challenge specific properties which includes the following toml fields

```toml # Ports to reserve for the challenge, we bind only one of these to host other are for internal communictaions only. # Should be within a particular permissible range. ports = [0, 0] default_port = 0 # Default port to use for any port specific action by beast. This is the container port.

# Ports can also be specified as a mapping between host and the container. # This can be used when we need customized port mapping between container and the host. port_mappings = ["10001:80"]

# Dependencies required by challenge, installed using default package manager of base image apt for most cases. apt_deps = ["", ""]

# A list of setup scripts to run for building challenge enviroment. # Keep in mind that these are only for building the challenge environment and are executed # in the iamge building step of the deployment pipeline. setup_scripts = ["", ""]

# A directory containing any of the static assets for the challenge, exposed by beast static endpoint. static_dir = ""

# Command to execute inside the container, if a predefined type is being used try to # use an existing field to let beast automatically calculate what command to run. # If you want to host a binary using xinetd use type service and specify absolute path # of the service using service_path field. run_cmd = ""

# Similar to run_cmd but in this case you have the entire container to yourself # and everything you are doing is done using root permissions inside the container # When using this keep in mind you are root inside the container. entrypoint = ""

# Relative path to binary which needs to be executed when the specified # Type for the challenge is service. # This can be anything which can be exeucted, a python file, a binary etc. service_path = ""

# Relative directory corresponding to root of the challenge where the root # of the web application lies. web_root = ""

# Any custom base image you might want to use for your particular challenge. # Exists for flexibility reasons try to use existing base iamges wherever possible. base_image = ""

# Docker file name for specific type challenge - `docker`. # Helps to build flexible images for specific user-custom challenges docket_context = ""

# Environment variables that can be used in the application code. [[var]]

key = ""
value = ""

[[var]]

key = ""
value = ""

Type of traffic to expose through the port mapping provided. traffic = "udp" / "tcp" ```

func (*ChallengeEnv) GetAllContainerPorts

func (config *ChallengeEnv) GetAllContainerPorts() ([]uint32, error)

GetAllContainerPorts is utility function for the ChallengeEnv configuration which returns the entire list of all the container ports which are being used by the challenge.

func (*ChallengeEnv) GetAllHostPorts

func (config *ChallengeEnv) GetAllHostPorts() ([]uint32, error)

GetAllHostPorts is utility function for the ChallengeEnv configuration which returns the entire list of all the host ports which are being used by the challenge.

func (*ChallengeEnv) GetDefaultPort

func (config *ChallengeEnv) GetDefaultPort() uint32

GetDefaultPort returns the default port used by the challenge from the challenge environment configuration.

func (*ChallengeEnv) GetPortMappings

func (config *ChallengeEnv) GetPortMappings() ([]cr.PortMapping, error)

GetPortMappings returns the entire port mapping for the challenge from the challenge environment configuration.

func (*ChallengeEnv) PopulateChallengeEnv

func (Env *ChallengeEnv) PopulateChallengeEnv()

func (*ChallengeEnv) TrafficType

func (config *ChallengeEnv) TrafficType() cr.TrafficType

func (*ChallengeEnv) ValidateRequiredFields

func (config *ChallengeEnv) ValidateRequiredFields(challType string, challdir string) error

ValidateRequiredFields validates required fields for the Challenge environment configuration. This requires challenge type to be passed so that we can verfiy based on type of the challenge.

type ChallengeMetadata

type ChallengeMetadata struct {
	Flag        string   `toml:"flag"`
	Name        string   `toml:"name"`
	Type        string   `toml:"type"`
	Tags        []string `toml:"tags"`
	Sidecar     string   `toml:"sidecar"`
	Description string   `toml:"description"`
	Hints       []string `toml:"hints"`
	Points      uint     `toml:"points"`
}

This contains challenge meta data

```toml # Required Fields flag = "" # Flag for the challenge name = "" # Name of the challenge type = "" # Type of the challenge, one of - Get available types from /api/info/types/available description = "" # Descritption for the challenge.

# Optional fields. tags = ["", ""] # Tags that the challenge might belong to, used to do bulk query and handling eg. binary, misc etc. hints = ["", ""] sidecar = "" # Name of the sidecar if any used by the challenge. ```

func (*ChallengeMetadata) PopulateChallengeMetadata

func (Metadata *ChallengeMetadata) PopulateChallengeMetadata()

func (*ChallengeMetadata) ValidateRequiredFields

func (config *ChallengeMetadata) ValidateRequiredFields() (error, bool)

In this validation returned boolean value represents if the challenge type is static or not.

type CompetitionInfo

type CompetitionInfo struct {
	Name         string `toml:"name"`
	About        string `toml:"about"`
	Prizes       string `toml:"prizes"`
	StartingTime string `toml:"starting_time"`
	EndingTime   string `toml:"ending_time"`
	TimeZone     string `toml:"timezone"`
	LogoURL      string `toml:"logo_url"`
}

func GetCompetitionInfo

func GetCompetitionInfo() (CompetitionInfo, error)

type EnvironmentVar

type EnvironmentVar struct {
	Key   string `toml:"key"`
	Value string `toml:"value"`
}

type GitRemote

type GitRemote struct {
	Url        string `toml:"url"`
	RemoteName string `toml:"name"`
	Branch     string `toml:"branch"`
	Secret     string `toml:"ssh_key"`
	Active     bool   `toml:"active"`
}

func (*GitRemote) ValidateGitConfig

func (config *GitRemote) ValidateGitConfig() error

type NotificationWebhook

type NotificationWebhook struct {
	URL         string `toml:"url"`
	ServiceName string `toml:"service_name"`
	Active      bool   `toml:"active"`
}

type Resources

type Resources struct {
	CPUShares int64 `toml:"cpu_shares"`
	Memory    int64 `toml:"memory_limit"`
	PidsLimit int64 `toml:"pids_limit"`
}

func (*Resources) ValidateRequiredFields

func (config *Resources) ValidateRequiredFields()

Jump to

Keyboard shortcuts

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