Documentation
¶
Overview ¶
Package sandbox runs one verify command inside bubblewrap.
The layout: the host read-only, with DD's state, the host owner's secrets, the socket dirs, $HOME and /tmp hidden behind empty, size-capped tmpfs mounts; the job's own worktrees and a per-run tmp and cache dir bound back writable; each clone's .git read-only; fresh /proc and /dev. No network of its own: a socat bridge inside forwards 127.0.0.1:ProxyPort to the egress proxy's Unix socket, bound in read-only. The environment is built by the caller, never inherited.
Every bound path is checked first: no symlink anywhere on it, inside one of the run's Roots, and never equal to or holding a hidden path. A path that fails is a layout the sandbox refuses (ErrUnavailable), never a mount: a symlink planted by the agent can't bind a secret in.
The command runs in a new PID namespace whose first process is bwrap itself, with --die-with-parent: killing the launcher kills every process the command started.
Index ¶
Constants ¶
const ProxyPort = 18080
ProxyPort is where the egress bridge listens inside the sandbox. The sandbox has its own network namespace, so the port is always free.
Variables ¶
ErrUnavailable wraps every reason the sandbox cannot start.
var FixedHidden = []string{"/run", "/var/run", "/tmp"}
FixedHidden are hidden in every sandbox: the socket dirs and /tmp.
var ProxyURL = "http://127.0.0.1:" + strconv.Itoa(ProxyPort)
ProxyURL is the value of HTTP(S)_PROXY inside the sandbox.
Functions ¶
Types ¶
type Launcher ¶
type Launcher struct {
Bwrap string
Socat string
// Size: bwrap takes --size (caps a tmpfs). DisableUserns: bwrap takes
// --disable-userns (no further user namespaces inside).
Size bool
DisableUserns bool
}
Launcher is the host's bwrap and socat, and the bwrap options it has.
func Find ¶
Find looks the tools up on PATH. A host without them, or not Linux, has no sandbox, and verify is skipped there.
func (Launcher) Args ¶
Args is the bwrap argument list for r (after the bwrap binary), or an ErrUnavailable when a bound path fails the layout checks.
func (Launcher) SelfTest ¶
SelfTest is the startup check behind verify_sandbox.v1 (V9). It runs the sandbox with the verify layout's parts (a hidden dir, a read-only bind, a writable dir, the egress bridge) and checks each: the hidden file is gone, the read-only dir refuses a write, the writable one takes it, a CONNECT to an allowed host is tunnelled and one to another host is refused. It needs no network: the allowed host is a fake target in this process. The error, if any, wraps ErrUnavailable and reads as a reason.
type Proc ¶
Proc is one sandboxed command.
type Run ¶
type Run struct {
// Command runs as `sh -c Command` in Dir.
Command string
Dir string
// Home is hidden like Hide; HOME should point at it.
Home string
// Hide are paths hidden behind an empty tmpfs (a dir) or /dev/null (a
// file). FixedHidden and Home are added. A path that does not exist
// is skipped: there is nothing to hide.
Hide []string
// Roots are where every Writable and ReadOnly path must lie (the
// worker's job dir and clones dir).
Roots []string
// Writable are bound back read-write after the hiding: the job's
// worktrees and the run's tmp and cache dirs.
Writable []string
// ReadOnly are bound read-only last, over anything writable: each
// clone's .git and each worktree's .git file.
ReadOnly []string
// Env is the whole environment (KEY=VALUE).
Env []string
// ProxySock is the egress proxy's socket ("": no network at all).
ProxySock string
}
Run is one command and the layout it runs in. Paths are host paths.