Documentation
¶
Overview ¶
Package process defines provider-neutral executable resolution and process launch contracts used by compiled tools and daemon applications.
The package describes lookup intent, process intent, verified executable ownership, and child ownership. VerifyExecutable opens and hashes one exact executable object without resolving or launching it. On systems that cannot execute a held descriptor, MaterializeForLaunch creates and reverifies an exact private snapshot while preserving explicit lease ownership. Platform path resolution, launch, process-tree containment, and resource joining remain injected implementations. In particular, this package does not claim that an operating system can universally contain descendants.
@import { NamedInterface } from "github.com/spice-framework/spice/annotation/modulith" @NamedInterface("process")
Index ¶
- Constants
- func NewFailure(operation Operation, cause error) error
- type Config
- type DigestError
- type DigestProblem
- type ExecutableLease
- func (lease *ExecutableLease) Close() error
- func (lease *ExecutableLease) Digest() SHA256
- func (lease *ExecutableLease) DuplicateForLaunch() (*os.File, error)
- func (lease *ExecutableLease) Format(state fmt.State, _ rune)
- func (*ExecutableLease) GoString() string
- func (lease *ExecutableLease) LogValue() slog.Value
- func (lease *ExecutableLease) MarshalJSON() ([]byte, error)
- func (lease *ExecutableLease) MaterializeForLaunch(ctx context.Context) (*MaterializedExecutable, error)
- func (lease *ExecutableLease) Path() string
- func (lease *ExecutableLease) Recheck(ctx context.Context) error
- func (*ExecutableLease) String() string
- func (lease *ExecutableLease) ValidateSpec(spec Spec) error
- type ExecutableResolver
- type Failure
- type Launcher
- type LauncherFunc
- type Lookup
- func (lookup Lookup) Clone() Lookup
- func (lookup Lookup) Environment() []string
- func (Lookup) Format(state fmt.State, _ rune)
- func (Lookup) GoString() string
- func (Lookup) MarshalJSON() ([]byte, error)
- func (lookup Lookup) RequestedExecutable() string
- func (Lookup) String() string
- func (lookup Lookup) Validate() error
- func (lookup Lookup) WorkingDirectory() string
- type LookupError
- type MaterializedExecutable
- func (executable *MaterializedExecutable) Close() error
- func (executable *MaterializedExecutable) Format(state fmt.State, _ rune)
- func (*MaterializedExecutable) GoString() string
- func (executable *MaterializedExecutable) LogValue() slog.Value
- func (executable *MaterializedExecutable) MarshalJSON() ([]byte, error)
- func (executable *MaterializedExecutable) Path() string
- func (executable *MaterializedExecutable) Recheck(ctx context.Context) error
- func (*MaterializedExecutable) String() string
- type Operation
- type Outcome
- type OutcomeError
- type OutcomeKind
- type Process
- type ResolverFunc
- type SHA256
- type Spec
- func (spec Spec) Arguments() []string
- func (spec Spec) Capabilities() []tool.Capability
- func (spec Spec) Clone() Spec
- func (spec Spec) Environment() []string
- func (spec Spec) Executable() string
- func (Spec) Format(state fmt.State, _ rune)
- func (Spec) GoString() string
- func (Spec) MarshalJSON() ([]byte, error)
- func (spec Spec) Stderr() io.Writer
- func (spec Spec) Stdin() io.Reader
- func (spec Spec) Stdout() io.Writer
- func (Spec) String() string
- func (spec Spec) Validate() error
- func (spec Spec) WorkingDirectory() string
- type SpecError
- type SpecProblem
- type VerificationError
- func (failure *VerificationError) Error() string
- func (failure *VerificationError) Format(state fmt.State, _ rune)
- func (failure *VerificationError) LogValue() slog.Value
- func (failure *VerificationError) MarshalJSON() ([]byte, error)
- func (failure *VerificationError) Operation() VerificationOperation
- func (failure *VerificationError) Unwrap() error
- type VerificationOperation
- type VerifiedLauncher
- type VerifiedLauncherFunc
Constants ¶
const ( OutcomeExited OutcomeKind = "exited" OutcomeSignaled OutcomeKind = "signaled" OutcomeUnknown OutcomeKind = "unknown" // MaximumExitCode preserves every unsigned 32-bit Windows exit code while // also covering Unix exit statuses. MaximumExitCode int64 = 1<<32 - 1 )
const ( // MaximumArguments bounds the number of discrete child arguments. MaximumArguments = 4096 // MaximumEnvironment bounds the number of exact child environment entries. MaximumEnvironment = 4096 // MaximumCapabilities bounds security-relevant capability metadata. MaximumCapabilities = 128 // MaximumValueBytes bounds one path, argument, or environment entry. MaximumValueBytes = 1 << 20 // MaximumSpecBytes bounds all copied string data in one specification. MaximumSpecBytes = 4 << 20 )
Variables ¶
This section is empty.
Functions ¶
func NewFailure ¶
NewFailure returns nil for a nil cause and otherwise creates a redacted typed failure. Unknown operations are represented safely as an empty Operation rather than copied into human-facing output.
Types ¶
type Config ¶
type Config struct {
Executable string
Arguments []string
WorkingDirectory string
Environment []string
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
Capabilities []tool.Capability
}
Config is copied and validated by NewSpec. Arguments exclude argv[0]. Environment entries use the ordinary name=value representation. An empty environment is explicit; all three streams must be non-nil.
type DigestError ¶
type DigestError struct {
// contains filtered or unexported fields
}
DigestError reports an invalid executable digest without retaining or formatting the caller-supplied value.
func (*DigestError) Error ¶
func (failure *DigestError) Error() string
func (*DigestError) MarshalJSON ¶
func (failure *DigestError) MarshalJSON() ([]byte, error)
func (*DigestError) Problem ¶
func (failure *DigestError) Problem() DigestProblem
type DigestProblem ¶
type DigestProblem string
DigestProblem classifies a secret-safe SHA-256 validation failure.
const ( DigestProblemMalformed DigestProblem = "malformed" DigestProblemZero DigestProblem = "zero" )
type ExecutableLease ¶
type ExecutableLease struct {
// contains filtered or unexported fields
}
ExecutableLease holds one verified executable object open across process launch. The lease binds an immutable canonical path and expected digest to a platform file identity. Close is idempotent and concurrency-safe.
func VerifyExecutable ¶
func VerifyExecutable( ctx context.Context, path string, expected SHA256, ) (*ExecutableLease, error)
VerifyExecutable opens and hashes one canonical absolute executable before any child is started. It performs no PATH lookup, shell invocation, network access, or dependency resolution.
func (*ExecutableLease) Close ¶
func (lease *ExecutableLease) Close() error
Close releases the held executable object. A nil or already-closed lease is harmless. Callers must not close a live child's lease before containment is proved.
func (*ExecutableLease) Digest ¶
func (lease *ExecutableLease) Digest() SHA256
Digest returns the immutable expected executable digest.
func (*ExecutableLease) DuplicateForLaunch ¶
func (lease *ExecutableLease) DuplicateForLaunch() (*os.File, error)
DuplicateForLaunch returns a caller-owned duplicate of the verified file object. A trusted native launcher uses this handle for exact-image execution on platforms that support descriptor-backed exec. The lease remains owned by its caller and must outlive process containment.
func (*ExecutableLease) GoString ¶
func (*ExecutableLease) GoString() string
func (*ExecutableLease) LogValue ¶
func (lease *ExecutableLease) LogValue() slog.Value
func (*ExecutableLease) MarshalJSON ¶
func (lease *ExecutableLease) MarshalJSON() ([]byte, error)
func (*ExecutableLease) MaterializeForLaunch ¶
func (lease *ExecutableLease) MaterializeForLaunch(ctx context.Context) (*MaterializedExecutable, error)
MaterializeForLaunch copies bytes only from the verified file object into a newly created process-owned directory, synchronizes and closes the writer, and verifies the exact expected digest again before returning. It performs no PATH lookup and never reopens the configured source pathname.
func (*ExecutableLease) Path ¶
func (lease *ExecutableLease) Path() string
Path returns the immutable canonical path whose file object was verified.
func (*ExecutableLease) Recheck ¶
func (lease *ExecutableLease) Recheck(ctx context.Context) error
Recheck reopens the configured path and proves it still resolves to the same platform file identity and content digest. Native launchers use it before a suspended child can execute where descriptor-backed exec is unavailable; callers may also retain it as defense-in-depth after launch.
func (*ExecutableLease) String ¶
func (*ExecutableLease) String() string
func (*ExecutableLease) ValidateSpec ¶
func (lease *ExecutableLease) ValidateSpec(spec Spec) error
ValidateSpec proves that a child specification selects the leased path. It deliberately does not relax or reconstruct the independently validated Spec.
type ExecutableResolver ¶
ExecutableResolver resolves natural executable names and relative paths to the exact lexically canonical absolute executable required by Spec. Resolve's context bounds only the lookup. Implementations must use only Lookup's working directory and environment, perform no hidden network access, and return failures through NewFailure with OperationResolve. The caller must pass the returned path through NewSpec before launch.
type Failure ¶
type Failure struct {
// contains filtered or unexported fields
}
Failure wraps an implementation failure while keeping its formatted and serialized form free of command, path, environment, and platform details. Unwrap preserves cancellation and implementation-specific error identity for deliberate programmatic inspection.
func (*Failure) MarshalJSON ¶
type Launcher ¶
Launcher is an injected provider-neutral process constructor. Start's context bounds launch only; a successfully returned Process has an independent lifetime. When Start returns both a Process and an error, ownership of that Process still transfers to the caller and must be joined. Implementations must never return a nil Process with a nil error.
type LauncherFunc ¶
LauncherFunc adapts an ordinary function for constructor injection and ordered policy decoration.
type Lookup ¶
type Lookup struct {
// contains filtered or unexported fields
}
Lookup is immutable executable-resolution intent. RequestedExecutable may be a natural platform name, a relative path interpreted from WorkingDirectory, or an absolute path. Environment is the exact explicit child environment; resolvers may use its platform search variables but never ambient process state. Lookup performs no filesystem or network access.
func NewLookup ¶
func NewLookup( requestedExecutable, workingDirectory string, environment []string, ) (Lookup, error)
NewLookup validates and defensively copies executable-resolution intent.
func (Lookup) Environment ¶
func (Lookup) MarshalJSON ¶
func (Lookup) RequestedExecutable ¶
func (Lookup) WorkingDirectory ¶
type LookupError ¶
type LookupError struct {
// contains filtered or unexported fields
}
LookupError identifies a secret-safe executable-lookup input failure.
func (*LookupError) Error ¶
func (failure *LookupError) Error() string
func (*LookupError) Field ¶
func (failure *LookupError) Field() string
func (*LookupError) Index ¶
func (failure *LookupError) Index() int
func (*LookupError) MarshalJSON ¶
func (failure *LookupError) MarshalJSON() ([]byte, error)
func (*LookupError) Problem ¶
func (failure *LookupError) Problem() SpecProblem
type MaterializedExecutable ¶
type MaterializedExecutable struct {
// contains filtered or unexported fields
}
MaterializedExecutable is a private, digest-reverified executable snapshot. It supports platforms such as Darwin that cannot execute an already-open descriptor. Close keeps its verification lease until the caller has proved child containment, then removes exactly the snapshot and its private directory.
func (*MaterializedExecutable) Close ¶
func (executable *MaterializedExecutable) Close() error
Close releases the materialized lease, removes exactly its private file, and removes the now-empty private directory. It is idempotent and refuses to recursively delete unexpected contents.
func (*MaterializedExecutable) Format ¶
func (executable *MaterializedExecutable) Format(state fmt.State, _ rune)
func (*MaterializedExecutable) GoString ¶
func (*MaterializedExecutable) GoString() string
func (*MaterializedExecutable) LogValue ¶
func (executable *MaterializedExecutable) LogValue() slog.Value
func (*MaterializedExecutable) MarshalJSON ¶
func (executable *MaterializedExecutable) MarshalJSON() ([]byte, error)
func (*MaterializedExecutable) Path ¶
func (executable *MaterializedExecutable) Path() string
Path returns the absolute private path selected for launch. It is intended only as the executable argument of a trusted VerifiedLauncher.
func (*MaterializedExecutable) Recheck ¶
func (executable *MaterializedExecutable) Recheck(ctx context.Context) error
Recheck proves that the private launch path still identifies the exact materialized object and digest.
func (*MaterializedExecutable) String ¶
func (*MaterializedExecutable) String() string
type Outcome ¶
type Outcome struct {
// contains filtered or unexported fields
}
Outcome is an immutable root-process result. It says nothing about whether descendants or platform containment resources have joined; Wait owns that separate fact.
func NewExitedOutcome ¶
NewExitedOutcome creates an ordinary process-exit outcome.
func NewSignaledOutcome ¶
func NewSignaledOutcome() Outcome
NewSignaledOutcome reports termination by a platform signal or analogous forced mechanism without exposing a platform-specific signal value.
func NewUnknownOutcome ¶
func NewUnknownOutcome() Outcome
NewUnknownOutcome reports that the root is known to have terminated but no portable exit classification is available. Unknown is never successful.
func (Outcome) Kind ¶
func (outcome Outcome) Kind() OutcomeKind
func (Outcome) Successful ¶
type OutcomeError ¶
type OutcomeError struct {
// contains filtered or unexported fields
}
OutcomeError is a typed, secret-safe invalid-outcome failure.
func (*OutcomeError) Error ¶
func (failure *OutcomeError) Error() string
func (*OutcomeError) Problem ¶
func (failure *OutcomeError) Problem() string
type OutcomeKind ¶
type OutcomeKind string
OutcomeKind classifies the provider-neutral root-process outcome.
type Process ¶
type Process interface {
Done() <-chan struct{}
Result() (Outcome, error)
RequestStop(context.Context) error
ForceKill(context.Context) error
Wait(context.Context) error
}
Process owns one launched root and its implementation-defined containment resources. Done closes when the root outcome becomes stable. Result is then deterministic and returns a validated Outcome; its error is only an observation failure, never a containment/join failure.
RequestStop and ForceKill request graceful and forced termination respectively. They are concurrency-safe and idempotent after success. A failure does not poison a later retry. Wait honors its context and returns nil only when all owned descendants and containment resources are safe to release. A canceled, unclassified, or explicitly retryable Wait retains ownership and a later Wait must perform a fresh join attempt. A Wait error implementing Retryable() bool with a false result declares that repeating containment cleanup is unsafe; ownership remains for manual recovery.
type ResolverFunc ¶
ResolverFunc adapts an ordinary function for constructor injection.
type SHA256 ¶
type SHA256 struct {
// contains filtered or unexported fields
}
SHA256 is an immutable exact executable-content identity. Its bytes remain private so callers cannot mutate a validated digest through shared storage.
func ParseSHA256 ¶
ParseSHA256 accepts exactly 64 lowercase hexadecimal characters. Parsing does not accept a zero digest as a usable pin; callers must also use Validate.
type Spec ¶
type Spec struct {
// contains filtered or unexported fields
}
Spec is immutable process intent. It performs no filesystem access and does not establish a permission or containment boundary. Capability metadata is declarative input for injected policy decorators.
func (Spec) Capabilities ¶
func (spec Spec) Capabilities() []tool.Capability
func (Spec) Environment ¶
func (Spec) Executable ¶
func (Spec) MarshalJSON ¶
func (Spec) String ¶
String prevents command arguments, environment values, paths, or stream implementations from leaking through incidental formatting.
func (Spec) WorkingDirectory ¶
type SpecError ¶
type SpecError struct {
// contains filtered or unexported fields
}
SpecError identifies a field and optional element without including its potentially sensitive value. Index returns -1 for a scalar field.
func (*SpecError) MarshalJSON ¶
func (*SpecError) Problem ¶
func (failure *SpecError) Problem() SpecProblem
type SpecProblem ¶
type SpecProblem string
SpecProblem classifies one secret-safe specification validation failure.
const ( ProblemRequired SpecProblem = "required" ProblemNotAbsolute SpecProblem = "not_absolute" ProblemNotCanonical SpecProblem = "not_canonical" ProblemInvalidUTF8 SpecProblem = "invalid_utf8" ProblemContainsNUL SpecProblem = "contains_nul" ProblemMalformed SpecProblem = "malformed" ProblemDuplicate SpecProblem = "duplicate" ProblemTooMany SpecProblem = "too_many" ProblemTooLarge SpecProblem = "too_large" ProblemMissingCapability SpecProblem = "missing_capability" )
type VerificationError ¶
type VerificationError struct {
// contains filtered or unexported fields
}
VerificationError preserves cancellation and platform error identity for deliberate inspection. Its formatted and serialized forms never include a path, digest, environment entry, file identity, or platform error text.
func (*VerificationError) Error ¶
func (failure *VerificationError) Error() string
func (*VerificationError) Format ¶
func (failure *VerificationError) Format(state fmt.State, _ rune)
func (*VerificationError) LogValue ¶
func (failure *VerificationError) LogValue() slog.Value
func (*VerificationError) MarshalJSON ¶
func (failure *VerificationError) MarshalJSON() ([]byte, error)
func (*VerificationError) Operation ¶
func (failure *VerificationError) Operation() VerificationOperation
func (*VerificationError) Unwrap ¶
func (failure *VerificationError) Unwrap() error
type VerificationOperation ¶
type VerificationOperation string
VerificationOperation identifies one secret-safe verified-executable step.
const ( VerificationOperationValidate VerificationOperation = "validate" VerificationOperationOpen VerificationOperation = "open" VerificationOperationInspect VerificationOperation = "inspect" VerificationOperationHash VerificationOperation = "hash" VerificationOperationDuplicate VerificationOperation = "duplicate" VerificationOperationMaterialize VerificationOperation = "materialize" VerificationOperationRecheck VerificationOperation = "recheck" VerificationOperationClose VerificationOperation = "close" )
type VerifiedLauncher ¶
type VerifiedLauncher interface {
StartVerified(context.Context, *ExecutableLease, Spec) (Process, error)
}
VerifiedLauncher starts a child from a previously verified executable lease. Implementations must validate the Spec against the lease and must prevent a pathname substitution from selecting a different image. On a partial launch, Process ownership follows the same rules as Launcher.Start.
This interface is intentionally separate from Launcher: a security-sensitive caller must not silently fall back to pathname-only launch.
type VerifiedLauncherFunc ¶
VerifiedLauncherFunc adapts a verified launch function for constructor injection and conformance tests.
func (VerifiedLauncherFunc) StartVerified ¶
func (launcher VerifiedLauncherFunc) StartVerified( ctx context.Context, lease *ExecutableLease, spec Spec, ) (Process, error)