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 ¶
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 ¶
Code returns the stable code of err: src/cto/sandbox's codes, "io" for ErrDriver or an exec failure, "" for nil.
func Exec ¶
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.
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.
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.