staging

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: AGPL-3.0 Imports: 16 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 staging implements the stage_locally path delivery: copying job inputs to worker-local scratch before a task runs and outputs back afterward. sqi never copies bytes itself; it invokes an operator-configured sync command per path. The scratch destination paths are returned as path-map rules so the other deliveries advertise them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EffectiveScratchBase added in v0.3.0

func EffectiveScratchBase(scratchDir string) string

EffectiveScratchBase returns the scratch directory staging uses: scratchDir verbatim if set, otherwise the platform TEMP-based default. Exported so cmd/sqi-worker's boot-time isolation ancestor check (see isolation.ValidateTraversable) validates the EXACT path StageIn will actually use, rather than duplicating this default and risking drift.

Types

type Option added in v0.3.0

type Option func(*Stager)

Option configures a Stager at construction. See WithIsolationCapable.

func WithIsolationCapable added in v0.3.0

func WithIsolationCapable(capable bool) Option

WithIsolationCapable records, once at worker boot, whether this worker is capable of run-as-user isolation at all — the same predicate cmd/sqi-worker's effectiveSessionRoot already decides the session root's mode from (there: isRoot(); here: the caller passes the identical boolean). It is NOT "did this particular assignment carry a credential": scratchBase and scratchBase/jobID are shared by every attempt of every job, including a mix of isolated and non-isolated queues on the same worker, so a per-assignment decision would let whichever job type happens to run first after a fresh scratch base decide that shared directory's mode for every attempt after it — e.g. a non-isolated task landing first creates the base at 0750, and every subsequent isolated task then fails ValidateTraversable against a base it can never widen itself. Deciding the mode once, from a per-worker capability signal, makes it deterministic instead of a race against assignment order. A worker that is never capable of isolating keeps the pre-isolation 0750 default (the zero value) whether or not this option is called.

type Stager

type Stager struct {
	// contains filtered or unexported fields
}

Stager copies staged paths via an external sync command, or the built-in copy when unconfigured/defaults are enabled.

func New

func New(scratchBase, syncCommand string, defaults bool, logger *slog.Logger, opts ...Option) *Stager

New returns a Stager. scratchBase/syncCommand come from worker config; defaults enables the built-in copy + TEMP scratch when staging is otherwise unconfigured. Pass WithIsolationCapable so a worker capable of run-as-user isolation creates its shared scratch ancestors traversable from birth; omitting it keeps the narrower 0750 default.

func (*Stager) Cleanup

func (s *Stager) Cleanup(scratchDir string)

Cleanup removes the scratch directory, logging (not returning) any error.

func (*Stager) Configured

func (s *Stager) Configured() bool

Configured reports whether staging can proceed: explicitly configured (scratch + shell command), or the built-in copy is available (defaults on, or the `builtin` sentinel was set explicitly).

func (*Stager) StageIn

func (s *Stager) StageIn(ctx context.Context, jobID, attemptID string, entries []protocol.StageEntry, cred *isolation.Credential) ([]protocol.PathMapRule, string, error)

StageIn prepares a per-attempt scratch directory for every staged entry and returns one path-map rule per entry (original path -> scratch path) plus the scratch directory. IN/INOUT inputs are copied into scratch via the sync command; OUT entries only get their scratch destination created (the task writes the output there, and Stager.StageOut copies it back afterward). Returning a rule for OUT entries too is what lets the other deliveries redirect the task's OUTPUT paths into scratch — without it the task writes to the real path and copy-out fails on a missing scratch file. On any failure the partial scratch directory is removed.

cred is the run-as-user credential for the task that will read/write these paths, or nil when the assignment carries no isolation. Staging always runs as the daemon (this is an operator-configured command, not job code — see internal/worker/session and internal/worker/executor for the two launch sites that DO carry a credential), so every path it writes is daemon-owned by default. When cred is non-nil, StageIn chowns the scratch directory to cred's uid/gid so the isolated task can read its staged inputs and write into its staged output directories; without this the task would see permission-denied on its own files.

scratchBase (s.effectiveScratch()) and scratchBase/jobID are shared by every attempt of every job — and, across jobs, by every different run-as-user identity, including a mix of isolated and non-isolated queues on the same worker — so their mode (s.ancestorMode) is decided ONCE, at Stager construction (see WithIsolationCapable), from whether this WORKER is capable of isolating at all, never from whether THIS assignment's cred is non-nil: a per-assignment decision would let whichever job type happens to run first after a fresh scratch base decide that shared directory's mode for every attempt after it, on a coin that re-flips every time the base is recreated (e.g. after a reboot when it sits under /tmp). A capable worker therefore creates base/jobDir traversable FROM BIRTH (0711) rather than narrow and widened after the fact: chowning either to any one identity would grant that identity nothing extra (search doesn't require ownership) while breaking every other attempt's/user's access, and mutating an EXISTING directory's mode is exactly the anti-pattern this codebase's isolation split eliminates elsewhere (see workerconfig.LoadOrCreateWorkerID's doc). Creating fresh at 0711 is a different, safe operation: os.MkdirAll never touches the mode of a directory that already exists, so a pre-existing scratch_dir at a narrower mode is caught by cmd/sqi-worker's boot-time isolation.ValidateTraversable check (or, for a task that arrives before that boot-time check would apply, the per-assignment check just below) instead of being silently widened here. A worker that is never capable of isolating keeps the pre-isolation 0750 mode instead of gaining a needless traversable-by-anyone directory — the same reasoning this codebase's other unconditional-widening fix (the session root, see workerconfig.LoadOrCreateWorkerID's doc) already applied once, now extended to this file. Only the per-attempt leaf (scratchDir itself, via ChownRecursive below) is chowned per-assignment, since it belongs to exactly this one attempt/identity — chowning is safe per-assignment because it is a fresh directory this call alone owns, unlike base/jobDir which persist across every other attempt. Go's forkAndExecInChild sets process credentials BEFORE chdir, so without both ancestors being traversable the isolated task cannot reach its own staged inputs even though scratchDir itself is correctly chowned.

func (*Stager) StageOut

func (s *Stager) StageOut(ctx context.Context, scratchDir string, entries []protocol.StageEntry) error

StageOut copies every OUT/INOUT entry from scratch back to its original path. It iterates the full entries slice with its original index so the per-index subdirectory (<scratchDir>/<i>/<basename>) matches what copyInEntries created.

validateStageOutSource runs BEFORE transfer() for every entry — upstream of BOTH the built-in copy and an operator-configured sync_command, which is the only place a check can cover both identically. sqi cannot audit an arbitrary sync_command template: whether it dereferences symlinks is a property of that command ("rsync -a" preserves them; "rsync -aL" or plain "cp" follow them). See the function's own doc for the full threat model.

Jump to

Keyboard shortcuts

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