content

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 20 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.

README

CTN content verification and catalog

src/ctn/internal/content owns CTN's content verification workflow and durable file catalog. It is private to CTN, not a separately versioned library. The app chooses an existing protected root, or creates one with InitCatalog. This package does not select a home directory, network service, backend, or content policy.

An import streams a regular local file into a private staging directory, records its SHA-256, byte size, media type, source name, and import time, then publishes the item atomically. Inspect and List rehash stored bytes and fail on a changed record, extra file, link, or payload. Remove accepts an explicit item ID and can remove a damaged item. Imports are bounded to 4 GiB without loading the whole file into memory.

CTN exposes the same operations:

ctn content init /absolute/catalog
ctn content import /absolute/catalog /absolute/note.txt
ctn content list /absolute/catalog
ctn content inspect /absolute/catalog ITEM_ID
ctn content verify /absolute/catalog ITEM_ID
ctn content remove /absolute/catalog ITEM_ID

Import and inspection return JSON records. The catalog stores local bytes and metadata only; interpretation, indexing, remote sync, and access policy remain consumer choices.

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

View Source
const (
	ExitPass       = 0
	ExitFail       = 1
	ExitUsage      = 2
	ExitUnverified = 3
	ExitTimeout    = 124
)

Exit codes returned by verification.

View Source
const AdmissionApproval = "run\n"

AdmissionApproval is the complete approval CTN writes to the runner.

View Source
const AdmissionOperation = "run-verified"

AdmissionOperation is the evaluator adapter operation that gates execution on the report from the prepared runner.

View Source
const MaxCatalogItemBytes int64 = 4 << 30
View Source
const MaxContentBytes = 256 << 20

MaxContentBytes bounds the size of content that can be verified.

Variables

View Source
var ErrCatalogInvalid = errors.New("invalid content catalog entry")
View Source
var ErrCatalogNotFound = errors.New("content item not found")
View Source
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

func InitCatalog(path string) (*Catalog, error)

InitCatalog creates a new protected catalog root and opens it. The parent directory must already exist; an existing root is never overwritten.

func OpenCatalog

func OpenCatalog(path string) (*Catalog, error)

OpenCatalog opens an existing protected root without following a root link.

func (*Catalog) Close

func (c *Catalog) Close() error

func (*Catalog) Import

func (c *Catalog) Import(ctx context.Context, source string) (Record, error)

Import streams a regular source file into a private staging directory, hashes it, then publishes the complete item with one directory rename.

func (*Catalog) Inspect

func (c *Catalog) Inspect(ctx context.Context, id string) (Record, error)

Inspect rehashes the stored bytes before returning metadata.

func (*Catalog) List

func (c *Catalog) List(ctx context.Context) ([]Record, error)

List verifies every item and returns records in stable import order.

func (*Catalog) Path

func (c *Catalog) Path() string

func (*Catalog) Remove

func (c *Catalog) Remove(id string) error

Remove deletes a caller-named item, including one whose bytes are damaged.

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

type SandboxHost struct {
	Host string `json:"host"`
	Port int    `json:"port"`
}

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.

type Verdict

type Verdict string

Verdict is the outcome of content verification.

const (
	VerdictPass        Verdict = "PASS"
	VerdictFail        Verdict = "FAIL"
	VerdictUnsupported Verdict = "UNSUPPORTED"
	VerdictTimeout     Verdict = "TIMEOUT"
)

Jump to

Keyboard shortcuts

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