config

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RuntimeNative = "native"
	RuntimeGvisor = "gvisor"
)
View Source
const (
	NetModeOff      = "off"
	NetModeIsolated = "isolated"
)

Variables

This section is empty.

Functions

func Validate

func Validate(cfg *Config) error

func WriteBase added in v0.1.4

func WriteBase(path string, homeDir string) error

WriteBase writes a default base config file to path.

func WriteDefaultForEnv

func WriteDefaultForEnv(path string, noCwd bool, homeDir, cwd string) error

WriteDefaultForEnv writes a default config file for a new drop environment to path.

The config by default shares the cwd if sharing of cwd does not expose the home dir (cwd is homeDir or a parent of it). cwd sharing can be disabled by setting noCwd to true.

Types

type Config

type Config struct {
	Extends      string   `toml:"extends"`
	Runtime      string   `toml:"runtime"`
	Mounts       []Mount  `toml:"mounts"`
	BlockedPaths []string `toml:"blocked_paths"`
	Environ      Environ  `toml:"environ"`
	Net          Net      `toml:"net"`
}

func Read

func Read(path string, homeDir string) (*Config, error)

func (*Config) IsGvisorRuntime added in v0.1.8

func (c *Config) IsGvisorRuntime() bool

type DefaultMount added in v0.1.3

type DefaultMount struct {
	Entry   string
	Comment string
}

func (DefaultMount) IsHeader added in v0.3.0

func (d DefaultMount) IsHeader() bool

type EnvVar

type EnvVar struct {
	Name  string
	Value string
}

func (*EnvVar) Expand

func (e *EnvVar) Expand(mapping func(string) string) string

func (*EnvVar) UnmarshalTOML

func (e *EnvVar) UnmarshalTOML(data any) error

type Environ

type Environ struct {
	ExposedVars []string `toml:"exposed_vars"`
	SetVars     []EnvVar `toml:"set_vars"`
}

type Firewall added in v0.3.2

type Firewall struct {
	// ToggleUnset when no config file sets it, which leaves the firewall
	// enabled if the [net.firewall] table is present.
	Enabled Toggle `toml:"enabled"`
	// An action when no rule matches: "allow", "deny" or "ask".
	DefaultAction string `toml:"default_action"`
	// What to do with if "ask" prompt cannot be shown: "allow" or
	// "deny".
	AskFallback string `toml:"ask_fallback"`
	// Files with rules. Relative paths are resolved relative to the
	// directory where config file which includes the rules is placed.
	RuleFiles []string `toml:"rule_files"`
	// File where "always allow" and "always deny" decisions are
	// saved. Used as a rule file automatically (no need to list it in
	// rule_files).
	SavedRulesFile string `toml:"saved_rules_file"`
	// Inline rules.
	Rules []string `toml:"rules"`
}

Firewall configures filtering of outgoing connections in the isolated network mode.

type HostPort

type HostPort struct {
	Auto      bool
	HostPort  int
	GuestPort int
}

Different from PublishedPort because Pasta, contrary to its man page, doesn't seem to support HostIP for ports forwarded from host to the namespace.

func ParseHostPort

func ParseHostPort(spec string) (*HostPort, error)

ParseHostPort parses host port string. Like ParsePublishedPort, but does not allow to specify hostIP/, only HOST_PORT[:DROP_PORT] or "auto".

func (*HostPort) UnmarshalTOML

func (p *HostPort) UnmarshalTOML(data any) error

Custom toml.Unmarshaler for HostPort field. Input is a string in the format hostPort[:guestPort] or "auto" for automatic port forwarding of all ports.

type Mount

type Mount struct {
	Source  string
	Target  string
	RW      bool
	Overlay bool
}

func ParseMountCompact

func ParseMountCompact(str string) (*Mount, error)

ParseMountCompact parses mount configuration from a string of a form source:target:options, where target and options are optional. If target is not given or empty, it equals source. Options are comma separated and can be "rw" and "overlay". Valid strings: "~/go", "~/go:~/host-go" "~/go:~/host-go:rw", "~/go::rw,overlay

func (*Mount) UnmarshalTOML

func (m *Mount) UnmarshalTOML(data any) error

Custom toml.Unmarshaler for mount field which is of mixed type (TOML 1.0 feature). In TOML mount entry can be either a single Docker-style mount string source:target:option (like "~/go:~/host-go:ro"), or a more verbose TOML table {source = "~/go", target = "~/host-go", rw = true, overlay = false}, where target is optional and defaults to source if not specified.

type Net

type Net struct {
	Mode              string          `toml:"mode"`
	Firewall          *Firewall       `toml:"firewall"`
	TCPPublishedPorts []PublishedPort `toml:"tcp_published_ports"`
	TCPHostPorts      []HostPort      `toml:"tcp_host_ports"`
	UDPPublishedPorts []PublishedPort `toml:"udp_published_ports"`
	UDPHostPorts      []HostPort      `toml:"udp_host_ports"`
}

func (*Net) IsFirewallEnabled added in v0.3.2

func (n *Net) IsFirewallEnabled() bool

type PublishedPort

type PublishedPort struct {
	Auto      bool
	HostIP    string
	HostPort  int
	GuestPort int
}

func ParsePublishedPort

func ParsePublishedPort(spec string) (*PublishedPort, error)

ParsePublishedPort parses and validates a published port string.

To keep things simple and keep an option of using a different connectivity tool, only the simplest Pasta mapping expressions are allowed.

Supported format of forwardSpecs items:

  • port (e.g., "8080") -> publishes Drop port 8080 as host port 8080 bound to 127.0.0.1 only
  • hostPort:guestPort (e.g., "8080:80") -> publishes Drop port 80 as host port 8080 bound to 127.0.0.1 only
  • hostIP/hostPort:guestPort (e.g., "192.168.0.3/8080:80") -> published Drop port 80 as host port 8080 bound to IP address 192.168.0.3
  • "127.0.0.1/auto" -> automatically publishes all open ports, binds them to localhost only
  • "auto" -> automatically publishes all open ports, binds them to ALL available IP addresses

func (*PublishedPort) UnmarshalTOML

func (p *PublishedPort) UnmarshalTOML(data any) error

Custom toml.Unmarshaler for PublishedPort field. Input entry is a string in the format [hostIP/][hostPort:]guestPort or "auto" for automatic port forwarding of all ports.

type Toggle added in v0.3.2

type Toggle uint8

Toggle is an optional boolean setting. Used instead of *bool, because gob, which passes config between Drop processes, doesn't send a pointer to false and makes it indistinguishable from nil.

const (
	ToggleUnset Toggle = iota
	ToggleOn
	ToggleOff
)

func (*Toggle) UnmarshalTOML added in v0.3.2

func (t *Toggle) UnmarshalTOML(data any) error

Jump to

Keyboard shortcuts

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