Documentation
¶
Overview ¶
Package sandbox confines a command with what the operating system offers: no network unless asked for, a read-only view of the host, and one writable directory. It knows nothing about tasks. The engine turns a task body into a set of paths and a network flag (a Spec), and a Backend turns that into a command (spec 053).
The only backend is bubblewrap, on Linux. Every other system has none, and says so: a caller never gets a command that looks confined and is not.
Index ¶
- Variables
- func Ancestors(workspace, path string) []string
- func BwrapArgs(spec Spec, argv []string) []string
- func CheckProtected(workspace, path string, links bool) error
- func RepoRoot(dir string) string
- func Resolve(path string) string
- func VarRunDir() bool
- func Within(parent, path string) bool
- type Backend
- type Bubblewrap
- type LinkedError
- type Mode
- type Spec
- type SymlinkError
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("bubblewrap (bwrap) was not found on the PATH") ErrCannotStart = errors.New("bubblewrap could not start a sandbox") )
The two ways bubblewrap can be unavailable on Linux.
var ErrUnsupported = errors.New("no sandbox backend")
ErrUnsupported is the reason of a system with no backend.
Functions ¶
func Ancestors ¶
Ancestors lists the directories between workspace and path, shallowest first, excluding both. A path outside the workspace has none.
func BwrapArgs ¶
BwrapArgs is the argument list that runs argv under spec. The order is the contract: a later mount covers an earlier one, so the workspace is visible again where a hidden directory covered it, a hidden location inside the workspace is mounted after the workspace, and the read-only remounts come after every mount that needs a mount point inside them.
func CheckProtected ¶
CheckProtected reports why path, which lies inside workspace, cannot be protected by a mount: a part of it below the workspace is a symbolic link, or, when links is set, it is a file with more than one name. A path that does not exist has nothing to protect and passes.
func RepoRoot ¶
RepoRoot returns the nearest directory at or above dir that holds a .git entry, or dir when there is none. It runs no git: the answer decides what git itself may see.
func Resolve ¶
Resolve returns path with the symbolic links of its existing part followed. The part that does not exist yet is kept as written.
Types ¶
type Backend ¶
type Backend interface {
// Name is recorded in the audit log and shown to the operator. A host
// with no backend has the empty name.
Name() string
// Path is the resolved program the backend runs, or "".
Path() string
// Probe starts a real sandbox. Nil means the backend can confine.
Probe(ctx context.Context) error
// Command returns the command that runs argv under the rules of spec.
Command(ctx context.Context, spec Spec, argv []string) (*exec.Cmd, error)
}
Backend provides the sandbox on a host.
type Bubblewrap ¶
type Bubblewrap struct {
// contains filtered or unexported fields
}
Bubblewrap is the Linux backend: the bwrap program with user namespaces.
func NewBubblewrap ¶
func NewBubblewrap(lookPath func(string) (string, error), probe []string) *Bubblewrap
NewBubblewrap returns the backend. lookPath finds the program, as exec.LookPath does, and probe is the command a Probe runs inside.
func (*Bubblewrap) Name ¶
func (*Bubblewrap) Name() string
Name is the backend's name in records and messages.
func (*Bubblewrap) Path ¶
func (b *Bubblewrap) Path() string
Path is the program with its links followed, or "" when there is none. It is looked up on every call, so a program installed later is found.
type LinkedError ¶
LinkedError reports a protected file that has more than one name. A mount protects a name, and the file could be written through the other one.
func (*LinkedError) Error ¶
func (e *LinkedError) Error() string
type Mode ¶
type Mode string
Mode is the operator's choice for a server.
The modes. There is no automatic one: confining where it works and running unconfined elsewhere would be a silent fallback.
type Spec ¶
type Spec struct {
// Workspace is the directory the command may write, and where it starts.
Workspace string
// ReadOnly makes the workspace read-only as well: nothing is writable.
ReadOnly bool
// Protected are paths inside the workspace that stay readable and cannot
// be changed, removed, renamed or replaced.
Protected []string
// HiddenDirs and HiddenFiles are seen empty and read-only.
HiddenDirs, HiddenFiles []string
// Empty is an empty file that stands in for each hidden file. A tool
// that insists on reading its configuration then reads nothing, where
// the null device, which is used when Empty is not set, cannot be opened
// at all under a mount that allows no devices.
Empty string
// Tmp is bound at /tmp. Empty gives an empty read-only /tmp.
Tmp string
// Cache is a second writable directory, bound at its own path.
Cache string
// Network keeps the host's network. Without it the command has a
// loopback of its own and nothing else.
Network bool
// ResolvConf is the resolver file to bind back for a command with the
// network, when it lies under a hidden directory.
ResolvConf string
// VarRunDir says /var/run is a directory of its own, not a link to /run.
VarRunDir bool
// Exe is a program to keep reachable at its own path, wherever it lies.
Exe string
}
Spec is the rule set for one command. Every path is absolute and resolved, and exists: the caller chooses and classifies them, and nothing here reads a file.
type SymlinkError ¶
SymlinkError reports a protected path that is reached through a symbolic link inside the workspace. A mount follows the link, so the link itself stays replaceable.
func (*SymlinkError) Error ¶
func (e *SymlinkError) Error() string