confine

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package confine restricts one local process to a sandbox grant (docs/adr-sandboxing.md, section 4) and then becomes the guest. It is the mechanism behind `ext sandbox exec`: a runner (the plugin engine, workload's local driver, a product) starts that command with a grant, and the command calls Exec, which confines its own process with an OS driver, reports what it enforced, and replaces itself with the guest.

The package owns mechanisms only. It never chooses a policy: the grant comes from the caller, computed with src/cto/sandbox from what a package requests and what the consumer allows.

A driver is one OS mechanism (Seatbelt on macOS, Landlock and seccomp on Linux, AppContainer and a job object on Windows). Each reports the classes it can enforce on this host (Capabilities); the library never picks a driver by name for the caller, and a launch that needs a class nobody enforces fails closed with sandbox.ErrUnsupported.

Some classes cannot be enforced by a process that confines itself and then becomes the guest: a wall-time bound and a fresh or snapshot lifecycle need something that outlives the guest. The runner that starts the launch step enforces those, and says so in Launch.Runner; they are reported as enforced on its word.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotExecutable reports a grant that does not let the guest's own executable run.
	ErrNotExecutable = fmt.Errorf("%w: the grant does not allow executing the guest", sandbox.ErrDenied)
	// ErrNoDriver reports that no driver is available here, or that more than one is and the
	// launch did not name one, or that it named one that is not available.
	ErrNoDriver = fmt.Errorf("%w: no such confinement driver here", sandbox.ErrUnsupported)
	// ErrDriver reports a native confinement call that failed after the plan was accepted.
	ErrDriver = errors.New("confine: the operating system refused to confine the process")
)

Errors beyond src/cto/sandbox's. Code maps them to the shared codes.

Functions

func Code

func Code(err error) string

Code returns the stable code of err: src/cto/sandbox's codes, "io" for ErrDriver or an exec failure, "" for nil.

func Exec

func Exec(l Launch, status io.Writer) (int, error)

Exec confines the calling process to the launch's grant and replaces it with the guest. It writes one Status line to status (when not nil) first: the report once the process is confined, or the code of the refusal. It returns only on failure; on POSIX a successful Exec never returns. On a platform without exec (Windows) it starts the guest confined, waits for it, and returns its exit code with a nil error.

Call it from a process that does nothing else: confining is not undone.

func Prepare

func Prepare(l Launch) (sandbox.Report, error)

Prepare checks a launch without changing anything: it picks the driver, checks the grant against what the driver and the runner enforce, and returns the report Exec would give.

Types

type Driver

type Driver interface {
	// Name is the driver's stable name, such as "seatbelt" or "landlock".
	Name() string
	// Capabilities reports what the driver enforces on this host. It probes and never
	// changes the process.
	Capabilities() sandbox.Capabilities
	// contains filtered or unexported methods
}

Driver is one OS confinement mechanism.

func Drivers

func Drivers() []Driver

Drivers returns the drivers this build offers on this OS, in a fixed order. A driver whose mechanism is missing on this host is still listed; its Capabilities say why it enforces nothing.

type Launch

type Launch struct {
	// Grant is what the guest may touch, already the overlap of a request and a policy
	// (sandbox.Grant).
	Grant sandbox.Policy
	// Accept names the classes the caller agrees to run without (sandbox.Enforce).
	Accept []string
	// Runner names the classes the caller enforces itself (wall time, lifecycle). They count
	// as enforced; the caller answers for them.
	Runner []string
	// Driver names the driver to use. Empty uses the only available driver, and fails when
	// there are several.
	Driver string
	// Path is the guest's executable, an absolute path that the grant allows executing.
	Path string
	// Args are the arguments after the executable name.
	Args []string
	// Env is the base environment the runner chose (for example PATH). The grant's entries are
	// added after it, and the values of its secrets from Secrets.
	Env []string
	// Secrets maps each secret name in the grant to the value the runner resolved from its
	// reference. A grant secret without a value is invalid.
	Secrets map[string]string
	// Dir is the working directory; empty keeps the launcher's.
	Dir string
}

Launch is one confined start.

type Status

type Status struct {
	Report *sandbox.Report `json:"report,omitempty"`
	Code   string          `json:"code,omitempty"`
}

Status is the one line Exec writes to the status writer before it starts the guest: the report of an accepted launch, or the code of a refused one.

Jump to

Keyboard shortcuts

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