Documentation
¶
Overview ¶
Package host is the runtime every sandbox mechanism plugs into. It implements core.Runtime once, over a backend.Backend: templates are resolved from artifacts and gated on platform parity, every fiber is born in its own cgroup v2 leaf with memory.max = w_budget_bytes and memory.oom.group = 1 (the kernel is the executioner, the leaf's memory.current is W), grants get a block ceiling, PSI feeds the pressure ladder, parks become W-sized deltas over the template's checkpoint and travel to other homes through the delta registry. The backend only forks, checkpoints and restores.
Index ¶
- Constants
- Variables
- func DefaultCeiling(g core.Grant, templateBytes uint64) uint64
- func ExportDelta(ctx context.Context, cfg Config, g core.Grant, session, dir string) ([]string, error)
- func FormatTemplateFlag(digest string, command []string) (string, error)
- func ParseTemplateFlag(m map[string]string, v string) error
- type Config
- type ExportInfo
- type Imported
- type Runtime
Constants ¶
const ( // ExportDeltaFile holds the delta's files (the parked images and their // manifest), ExportParentFile the template checkpoint the delta is // relative to (absent when the park was a full checkpoint), and // ExportInfoFile describes both. ExportDeltaFile = "fiberd-delta.tar" ExportParentFile = "fiberd-parent.tar" ExportInfoFile = "fiberd-delta.json" )
const DefaultEngineMemoryMax = 1 << 30
DefaultEngineMemoryMax is memory.max of an engine's leaf when Config names none. A simulated engine holds its whole pool in host memory, so it must fit here.
const DefaultEngineUID = 1<<30 - 1
DefaultEngineUID is the engine's uid when Config names none. It is one below the default -userns-pool (runcbackend.DefaultPool), so no runc grant's range holds it, and above the ranges hosts hand out by convention (useradd stops at 600100000). proc fibers run as fiberd's own uid.
Variables ¶
var DefaultFiberHide = []string{"/var/run/secrets/kubernetes.io/serviceaccount"}
DefaultFiberHide is hidden from every fiber. It holds the Kubernetes service-account token of the home's Pod.
var ErrNoTier = errors.New("offers no tier")
ErrNoTier is New's refusal of a backend that offers no tier, because its tools or files are missing. Confinement fails closed, so fiberd does not start over such a backend.
var ErrUnsupported = errors.New("host: not supported on this platform")
Functions ¶
func DefaultCeiling ¶
DefaultCeiling is Config.Ceiling when unset.
func ExportDelta ¶
func ExportDelta(ctx context.Context, cfg Config, g core.Grant, session, dir string) ([]string, error)
ExportDelta moves the published delta of session under grant g from the registry into dir and returns the names of the files it wrote. The session's tag is deleted from the registry afterwards: the home that exported it forgets its copy on its next Clone of the name, and only what dir holds can bring the session back.
func FormatTemplateFlag ¶
FormatTemplateFlag is the -template value ParseTemplateFlag reads back as digest and command, "digest=cmd arg arg". digest must match core.TemplateDigestPattern. command must not be empty, and no element may be empty or hold whitespace, since Command splits the line on whitespace.
Types ¶
type Config ¶
type Config struct {
// Backend is the sandbox mechanism (pkg/backend/proc, ...). Required.
Backend backend.Backend
// Templates maps a template digest to the template command line
// ("path [args...]"). The key "default" serves digests not listed.
Templates map[string]string
// Registry, when set, resolves digests not in Templates by pulling
// the template artifact "<Registry>@<digest>" into TemplateCache. A
// registry starting with http:// is reached over plain HTTP.
Registry string
// TemplateCache holds pulled artifacts, one directory per digest
// (default /var/lib/fiberd/templates), and the parent-checkpoint store.
// It is hidden from fibers like PrivateDir and DeltaDir: a proc fiber
// runs as fiberd's uid and could otherwise rewrite a cached
// template between the host's check and the exec, or read another
// grant's. A proc fiber still sees its own template's executable,
// bound back read-only at its path inside the cover, because CRIU
// names a mapped file by its path (sdk/c/template/core/src/mounts.rs).
TemplateCache string
// CgroupRoot is the delegated cgroup v2 subtree (from the home).
CgroupRoot string
// RunDir holds fiber endpoints (unix sockets); keep it short, the path
// limit is 108 bytes.
RunDir string
// Endpoints is the address family fibers are served on: unix sockets
// under RunDir (the zero value), or tcp on one declared address with
// a port per fiber. A backend that lists "tcp" in EndpointSchemes
// (proc) binds the port itself. Any other serves the unix socket and
// fiberd relays the port to it (relay.go).
Endpoints endpoint.Policy
// DeltaDir holds parked images: <DeltaDir>/<grant>/<epoch>-<seq>/.
DeltaDir string
// WorkspaceDir holds the workspace of every running fiber whose
// grant has a disk budget, <WorkspaceDir>/<grant>/<epoch>-<seq>/,
// with the fiber's tree under root/ and fiberd's staging beside it
// (default workspaces/ beside DeltaDir, so /var/lib/fiberd/workspaces
// under the default DeltaDir). It is fiberd's alone, mode
// 0700, and hidden from fibers like DeltaDir. Each fiber sees its
// own tree alone, mounted at backend.WorkspaceMount.
WorkspaceDir string
// DeltaRegistry, when set, is the OCI repository prefix (host/prefix)
// under which parked deltas are published (one repository per session
// domain, one tag per session) and looked up by other homes. A prefix
// starting with http:// is reached over plain HTTP.
DeltaRegistry string
// DeltaKeys signs every delta and parent checkpoint this home pushes to
// DeltaRegistry. The home pulls or imports only those a trusted key
// signed. Its Seal key encrypts each delta before it leaves the home, so
// homes that move sessions between them share it. Signer and Seal are
// required with DeltaRegistry.
DeltaKeys artifact.Keys
// Handoff routes callers' connections to the fibers of handoff-mode
// grants, whose handles name its address. Nil refuses such grants
// (ErrNoHandoff).
Handoff *handoff.Router
// HandoffKey derives each handoff grant's TLS identity. Homes that
// move sessions between them share it. Required, at least 32 bytes,
// when Handoff is set.
HandoffKey []byte
// HomeID names this home in published deltas, so a home that will not
// pull a session can tell the caller where it is (Miss.preferred_home).
HomeID string
// Parity is how strictly an artifact's images or another home's delta
// must match this host (architecture and backend always; kernel and
// libc per level). The zero value is strict.
Parity artifact.Parity
// Platform overrides what this home believes about its own host, for
// tests and for hosts whose uname is not what the checkpoints will
// run under. Zero fields are filled by the backend, then detected
// (ldd for the libc), so a Platform naming all three runs nothing.
// Backend is always the backend's name.
Platform artifact.Platform
// Ceiling computes the grant's block ceiling in bytes from the grant
// and the warm template's resident size; 0 means no ceiling. The
// default is fibers.max * w_budget + template + 25%, and nothing when
// either factor is unlimited. It is applied as memory.high (throttle,
// which PSI reports and the ladder reacts to) with memory.max one W
// budget above it as the hard stop.
Ceiling func(g core.Grant, templateBytes uint64) uint64
// FiberHide lists directories fibers must not see, besides
// DefaultFiberHide, DeltaDir and PrivateDir, in backends that give a
// fiber a mount namespace of its own. A directory holding RunDir is
// never hidden, because fiber endpoints live there.
FiberHide []string
// PrivateDir is fiberd's private state (its keys, the ledger
// snapshot, the epoch, the audit spool). Fibers run as fiberd's uid
// and would pass the owner checks on its files, so it is always
// hidden from them, like DeltaDir. Empty when fiberd has none.
PrivateDir string
// Engine is the device engine's command line, "path [args...]".
// fiberd starts one engine for each grant with a device budget, with
// --grant and --socket put after the path, and the grant is admitted
// once it is READY. Empty starts none, and a grant with a device
// budget is then refused.
Engine []string
// EngineUID is the uid and gid every engine runs as. It must not be
// 0 and must be no fiber's uid (DefaultEngineUID when 0).
EngineUID uint32
// EngineMemoryMax is memory.max of each engine's leaf, <grant>/engine
// (DefaultEngineMemoryMax when 0).
EngineMemoryMax uint64
}
Config selects the backend, the templates and where the runtime may write.
type ExportInfo ¶
type ExportInfo struct {
Session string `json:"session"`
Domain string `json:"domain"`
Digest string `json:"digest"`
Annotations map[string]string `json:"annotations"`
Parent string `json:"parent_sha256,omitempty"`
ParentAnnotations map[string]string `json:"parent_annotations,omitempty"`
}
ExportInfo is what ExportDelta writes beside the archives. Domain tells whoever ships the files where the session came from. ImportDelta never believes it, because the destination grant's domain decides that. Annotations and ParentAnnotations are the signed manifests of the delta and its parent, which ImportDelta checks the archives against. An export without ParentAnnotations has its parent refused.
type Imported ¶
Imported is what ImportDelta published: the session's tag and the digest it holds. A caller whose clone of the session fails can withdraw the tag if it still holds that digest.
func ImportDelta ¶
func ImportDelta(ctx context.Context, cfg Config, g core.Grant, session, dir string) (Imported, error)
ImportDelta publishes the files ExportDelta wrote in dir as session under grant g, so that Clone(session) on this home finds, claims and resumes it. The session name may differ from the exported one: a template's golden state imported under many names is many sessions.
type Runtime ¶
Runtime is a placeholder so callers build on platforms without cgroup v2. New never returns one here.
func (*Runtime) DevicePressure ¶
func (*Runtime) DevicePressure() core.PressureSource