Documentation
¶
Overview ¶
Package content implements CTN's verification workflow and durable file catalog. The app package supplies adapter selection, trust policy, and CLI output.
Index ¶
- Constants
- Variables
- type Backend
- type Catalog
- func (c *Catalog) Close() error
- func (c *Catalog) Import(ctx context.Context, source string) (Record, error)
- func (c *Catalog) Inspect(ctx context.Context, id string) (Record, error)
- func (c *Catalog) List(ctx context.Context) ([]Record, error)
- func (c *Catalog) Path() string
- func (c *Catalog) Remove(id string) error
- type Limits
- type Observer
- type Policy
- type Record
- type Result
- type SandboxGrant
- type SandboxHost
- type SandboxRefusal
- type SandboxReport
- type SandboxResources
- type Verdict
Constants ¶
const ( ExitPass = 0 ExitFail = 1 ExitUsage = 2 ExitUnverified = 3 ExitTimeout = 124 )
Exit codes returned by verification.
const AdmissionApproval = "run\n"
AdmissionApproval is the complete approval CTN writes to the runner.
const AdmissionOperation = "run-verified"
AdmissionOperation is the evaluator adapter operation that gates execution on the report from the prepared runner.
const MaxCatalogItemBytes int64 = 4 << 30
const MaxContentBytes = 256 << 20
MaxContentBytes bounds the size of content that can be verified.
Variables ¶
var ErrCatalogInvalid = errors.New("invalid content catalog entry")
var ErrCatalogNotFound = errors.New("content item not found")
var ErrMalformedReport = errors.New("malformed admission report")
ErrMalformedReport is returned for a report that is not a well-formed admission report of the sandbox contract.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend interface {
// Name returns the backend identity.
Name() string
// Run requests admission from the caller after preparing the runner and
// before executing content. An admission error prevents execution.
// A non-nil error with a non-zero
// exit code indicates the content itself failed; a non-nil error with a
// zero exit code indicates an infrastructure failure.
Run(ctx context.Context, file, selection string, timeout time.Duration, admit func(SandboxReport) error) (exitCode int, output []byte, err error)
}
Backend is a caller-selected execution backend for running content.
type Catalog ¶
type Catalog struct {
// contains filtered or unexported fields
}
Catalog owns a caller-selected local root. Items are atomically published as directories containing a record and a content file.
func InitCatalog ¶
InitCatalog creates a new protected catalog root and opens it. The parent directory must already exist; an existing root is never overwritten.
func OpenCatalog ¶
OpenCatalog opens an existing protected root without following a root link.
func (*Catalog) Import ¶
Import streams a regular source file into a private staging directory, hashes it, then publishes the complete item with one directory rename.
type Limits ¶
type Limits struct {
// MaxOutputBytes bounds the captured output size.
MaxOutputBytes int64
}
Limits bound resource usage during verification.
type Observer ¶
type Observer interface {
// Started is called when verification begins.
Started(backend string)
// Completed is called when verification ends with the final result.
Completed(result *Result)
}
Observer optionally receives verification events.
type Policy ¶
type Policy interface {
// IsTrusted reports whether the backend is trusted to run content.
IsTrusted(backend Backend) bool
// Admit checks the prepared runner's report against the consumer's policy.
Admit(report SandboxReport) error
}
Policy decides whether content may run through a given backend.
type Record ¶
type Record struct {
ID string `json:"id"`
Name string `json:"name"`
MediaType string `json:"mediaType"`
Size int64 `json:"size"`
SHA256 string `json:"sha256"`
ImportedAt string `json:"importedAt"`
}
Record describes one immutable, locally stored file. ID is a random identifier; SHA256 identifies the exact content bytes.
type Result ¶
type Result struct {
Verdict Verdict `json:"verdict"`
File string `json:"file"`
SHA256 string `json:"sha256"`
Backend string `json:"backend,omitempty"`
Selection string `json:"selection,omitempty"`
Isolation string `json:"isolation,omitempty"`
Boundary string `json:"boundary,omitempty"`
Sandbox *SandboxReport `json:"sandbox,omitempty"`
ExitCode int `json:"exitCode"`
Millis int64 `json:"millis"`
Reason string `json:"reason,omitempty"`
}
Result is the structured outcome of content verification.
func Verify ¶
func Verify(ctx context.Context, file string, selection string, backend Backend, policy Policy, limits Limits, timeout time.Duration, observer Observer) (*Result, error)
Verify runs content through a backend under a policy and returns a structured result. The caller supplies the backend, policy, limits, and optional observer. Content larger than MaxContentBytes is rejected.
type SandboxGrant ¶
type SandboxGrant struct {
Filesystem []struct {
Path string `json:"path"`
Access []string `json:"access"`
} `json:"filesystem,omitempty"`
Network struct {
Mode string `json:"mode,omitempty"`
Ports []int `json:"ports,omitempty"`
Hosts []SandboxHost `json:"hosts,omitempty"`
} `json:"network,omitzero"`
Process struct {
Children bool `json:"children,omitempty"`
} `json:"process,omitzero"`
Devices []string `json:"devices,omitempty"`
Resources SandboxResources `json:"resources,omitzero"`
Environment struct {
Names []string `json:"names,omitempty"`
Entries []string `json:"entries,omitempty"`
Secrets []struct {
Name string `json:"name"`
Ref string `json:"ref"`
} `json:"secrets,omitempty"`
} `json:"environment,omitzero"`
Lifecycle struct {
Mode string `json:"mode,omitempty"`
Name string `json:"name,omitempty"`
Restore string `json:"restore,omitempty"`
} `json:"lifecycle,omitzero"`
}
SandboxGrant is what the guest may touch. Everything not listed is denied.
func (SandboxGrant) HostAccess ¶
func (g SandboxGrant) HostAccess() bool
HostAccess reports whether the grant gives the guest anything beyond a fresh, empty, offline run: paths, child processes, devices, environment, a network or kept state. Resource bounds only take access away.
type SandboxHost ¶
SandboxHost is one destination an egress proxy allows.
type SandboxRefusal ¶
type SandboxRefusal struct {
Class string `json:"class"`
Path string `json:"path,omitempty"`
Access []string `json:"access,omitempty"`
Host *SandboxHost `json:"host,omitempty"`
Port int `json:"port,omitempty"`
Name string `json:"name,omitempty"`
}
SandboxRefusal is one part of the request the consumer's policy did not allow.
type SandboxReport ¶
type SandboxReport struct {
Boundary string `json:"boundary"`
Driver string `json:"driver,omitempty"`
Grant SandboxGrant `json:"grant"`
Refused []SandboxRefusal `json:"refused,omitempty"`
Enforced []string `json:"enforced"`
Unenforced []string `json:"unenforced,omitempty"`
}
SandboxReport is the runner's report: where it runs, what it was granted and refused, and which classes it enforces.
func ReadAdmissionReport ¶
func ReadAdmissionReport(input *bufio.Reader) (SandboxReport, error)
ReadAdmissionReport reads one bounded JSON line. Use the same buffered reader for subsequent output from the runner. An empty stream returns io.EOF.
func (SandboxReport) Sandboxed ¶
func (r SandboxReport) Sandboxed() bool
Sandboxed reports whether the launch meets the evaluator isolation "sandboxed" (docs/evaluator-adapters.md): a confined, runtime, container or kernel boundary, every required class enforced, and no open network.
type SandboxResources ¶
type SandboxResources struct {
MemoryBytes *int64 `json:"memoryBytes,omitempty"`
MilliCPU *int64 `json:"milliCpu,omitempty"`
Pids *int64 `json:"pids,omitempty"`
CPUTimeMs *int64 `json:"cpuTimeMs,omitempty"`
WallTimeMs *int64 `json:"wallTimeMs,omitempty"`
OpenFiles *int64 `json:"openFiles,omitempty"`
WriteBytes *int64 `json:"writeBytes,omitempty"`
}
SandboxResources are bounds; a nil field sets none.