Help us shape the future of Go! Take the 2026 Go Developer Survey

shim

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MPL-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnveilShared = "@shared" // shared libraries ( /lib, /usr/lib, ...)
	UnveilStdio  = "@stdio"  // standard I/O devices (/dev/null, /dev/zero, ...)
	UnveilDNS    = "@dns"    // name resolution files (/etc/resolv.conf, ...)
	UnveilCerts  = "@certs"  // TLS trust store (/etc/ssl/certs, ...)
)

These built-ins identify go-landlock's built-in path sets. Each expands to an environment-specific set of paths that go-landlock resolves when the sandbox is applied. They travel in the unveil list as plain strings, which keeps the go-landlock import confined to the shim: the driver can reference these sets by name without importing go-landlock itself.

View Source
const (
	// SubCommand is the first argument to the clone of the nomad agent process
	// for invoking the exec2 driver sandbox shim.
	SubCommand = "exec2-shim"

	// ExitWrongArgs indicates the shim has terminated early due to recieving
	// the wrong expected arguments. We use a special return code here since logs
	// will not have been configured yet.
	ExitWrongArgs = 40

	// ExitBadLogging indicates the shim has terminated early due to being unable
	// to open stdout or stderr output files (fifos).
	ExitBadLogging = 41

	// ExitBadConfig indicates the shim has terminated early due to being unable
	// to read or parse the shim config file.
	ExitBadConfig = 42
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Environment

type Environment struct {
	User         string            // user the command will run as (may be empty / synthetic)
	OutPipe      string            // io pipe path for stdout
	ErrPipe      string            // io pipe path for stderr
	Env          map[string]string // environment variables
	TaskDir      string            // task directory
	WorkDir      string            // working directory for the task; defaults to TaskDir
	Cgroup       string            // task cgroup path
	Net          string            // allocation network namespace path
	Memory       uint64            // memory in megabytes
	MemoryMax    uint64            // memory_max in megabytes
	CPUBandwidth uint64            // cpu / cores bandwidth
	OOMScoreAdj  int               // oom_score_adj for the task
}

Environment represents runtime configuration.

type ExecTwo

type ExecTwo interface {
	// Start the Task process.
	Start(context.Context) error

	// PID returns the process ID associated with exec.
	//
	// Must only be called after Start.
	PID() int

	// Wait on the process (until exit).
	//
	// Must only be called after Start.
	WaitCh() process.WaitCh

	// Stats returns current resource utilization.
	//
	// Must only be called after Start.
	Stats() *resources.Utilization

	// Signal [kill()] the process.
	//
	// Must be called after Start.
	Signal(string) error

	// Stop the process.
	//
	// Must be called after Start.
	Stop(string, time.Duration) error
}

func New

func New(env *Environment, opts *Options, l hclog.Logger) ExecTwo

New an ExecTwo, an instantiation of the exec2 driver.

func Recover

func Recover(pid int, env *Environment, l hclog.Logger) ExecTwo

Recover an ExecTwo, an already running instance of the execc2 driver.

type Mount added in v0.2.0

type Mount struct {
	Source   string `json:"source"`
	Target   string `json:"target"`
	Readonly bool   `json:"readonly"`
}

Mount describes a single bind mount to establish inside the task's private mount namespace before the task command is executed. Source is the host path and Target is the path as seen by the task.

type Options

type Options struct {
	Command      string
	Arguments    []string
	UnveilPaths  []string
	OOMScoreAdj  int
	Capabilities []string
	WorkDir      string  // working directory for the task; defaults to TaskDir
	Mounts       []Mount // bind mounts to set up inside the task mount namespace
}

Options represent Task configuration options.

type ShimConfig added in v0.2.0

type ShimConfig struct {
	// Version identifies the config format. Always set to configVersion (1).
	Version int `json:"version"`

	// OutPipe is the filesystem path to the named pipe for task stdout.
	OutPipe string `json:"out_pipe"`

	// ErrPipe is the filesystem path to the named pipe for task stderr.
	ErrPipe string `json:"err_pipe"`

	// UID is the numeric user ID the task process should run as.
	UID int `json:"uid"`

	// GID is the numeric group ID the task process should run as.
	GID int `json:"gid"`

	// Capabilities is the list of Linux capability names to raise as ambient
	// capabilities for the task process. Empty means no extra capabilities.
	Capabilities []string `json:"capabilities"`

	// UnveilPaths is the complete list of Landlock entries to expose.
	// Each entry is either a "mode:path" pair (e.g. "r:/some/path", "rwxc:/alloc/data")
	// or built-ins (e.g. UnveilShared, UnveilCerts) that the shim expands
	// to a go-landlock path set.
	UnveilPaths []string `json:"unveil_paths"`

	// Command is the executable to run as the task process.
	Command string `json:"command"`

	// Arguments are the command-line arguments passed to Command.
	Arguments []string `json:"arguments"`

	// Mounts is the list of bind mounts.
	Mounts []Mount `json:"mounts"`
}

ShimConfig holds all parameters the exec2-shim subprocess needs at startup.

Jump to

Keyboard shortcuts

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