Documentation
¶
Overview ¶
Package contracts defines the shared version 1 types, validation rules and component interfaces. It contains no archive extraction, tool execution or output publication.
Index ¶
- Constants
- func StripPatchPath(value string) (string, error)
- func ValidateBasename(value string) error
- func ValidateRelativePath(value string) error
- type ConfinedInputs
- type ExecuteRequest
- type ExecutionResult
- type Executor
- type Failure
- type FileRecord
- type InputEntry
- type InputError
- type InventoryResult
- type Manifest
- type Operation
- type Options
- type Outcome
- type Patch
- type PatchInventory
- type PatchRequest
- type PatchResult
- type PatchStatus
- type PatchTarget
- type PreparedSource
- type Reason
- type Report
- type RunError
- type Source
- type SourcePreparer
- type SourceRequest
- type SourceResult
- type Stage
- type StagedFile
- type StagedPatch
Constants ¶
const ( SchemaVersion = 1 MaxManifestBytes int64 = 1 << 20 MaxArchiveBytes int64 = 2 << 30 MaxPatches = 256 MaxPatchBytes int64 = 16 << 20 MaxArchiveEntries = 100000 MaxExtractedBytes int64 = 2 << 30 MaxPatchLogBytes int64 = 1 << 20 PatchTimeoutSeconds = 30 NewFileMode uint32 = 0644 DirectoryMode uint32 = 0755 DigestDefinition = "" /* 222-byte string literal not displayed */ EvidenceLimitations = "" /* 211-byte string literal not displayed */ )
Variables ¶
This section is empty.
Functions ¶
func StripPatchPath ¶
StripPatchPath checks a diff header path and removes its first component: a/src/main.c becomes src/main.c. Quotes and whitespace, including Unicode whitespace, are unsupported. /dev/null returns an empty path; the diff parser must allow that marker only for the missing side of an addition or deletion.
func ValidateBasename ¶
ValidateBasename applies ValidateRelativePath and requires a single name with no slash separators.
func ValidateRelativePath ¶
ValidateRelativePath checks that a path is a nonempty UTF-8 relative path using slash separators, without control characters, backslashes, empty components, or . or .. components. It checks spelling only. Input readers must also reject symlinks using operations relative to open directories, so a pathname change between checking and opening cannot redirect a read.
Types ¶
type ConfinedInputs ¶
type ConfinedInputs interface {
OpenRegular(context.Context, string) (io.ReadCloser, error)
ReadDir(context.Context, string) ([]InputEntry, error)
}
ConfinedInputs is a read-only view of an input directory kept open throughout source and patch preparation. Paths are normalized relative slash paths. Implementations reject symlink components and nonregular input files. They open paths relative to retained directory handles so a changed pathname cannot redirect a read. ReadDir includes hidden entries and rejects symlinks and special files. The owner closes the root after preparation.
Reads return InputError with an unsafe-input, I/O or cancellation reason. Source and inventory callers add their stage with FailureFromError. Preparation hashes bytes while copying them into private files for all later use.
type ExecuteRequest ¶
type ExecuteRequest struct {
Source PreparedSource
Patches []StagedPatch
PatchExecutable string
}
type ExecutionResult ¶
type ExecutionResult struct {
Patches []PatchResult
Files []FileRecord
FinalTreeSHA256 string
Failure *Failure
Diagnostics string
}
ExecutionResult contains ordered patch results and, only after the whole series succeeds, file records and a final tree hash. Contents are hashed while readable, with intended final permissions included; final modes are then restored. New files receive 0644 and directories 0755. Failure stops execution, leaves later patches not_run, and returns no file records or tree hash. Diagnostics are bounded stderr material, excluded from reports and successful output packages.
type Executor ¶
type Executor interface {
Execute(context.Context, ExecuteRequest) (ExecutionResult, error)
}
type Failure ¶
Failure records a stage and reason without host paths, timestamps or tool logs. Hash, inventory and patch application mismatches return this result with a nil error. Operational failures also return a RunError.
func FailureFromError ¶
FailureFromError extracts a stage and reason from a typed error. It uses the supplied stage unless a RunError provides its own valid failure stage. Unknown errors become I/O failures. Diagnostic text is never copied into the result.
type FileRecord ¶
type FileRecord struct {
Path string `json:"path"`
Mode string `json:"mode"`
SHA256 string `json:"sha256"`
}
FileRecord describes a regular file in the completed source tree. Path is relative to that tree and SHA256 hashes the contents. Mode is the file's final permissions as four octal digits, such as "0644". It excludes temporary access permissions used during preparation.
type InputEntry ¶
type InputError ¶
InputError describes a failed read beneath the retained input directory. Input readers use ReasonUnsafeInput, ReasonIO or ReasonCancelled. Source and inventory preparation add their own stage while preserving this reason.
func (*InputError) Error ¶
func (e *InputError) Error() string
func (*InputError) Unwrap ¶
func (e *InputError) Unwrap() error
type InventoryResult ¶
type InventoryResult struct {
Patches []StagedPatch
Failure *Failure
}
type Manifest ¶
type Manifest struct {
SchemaVersion int `json:"schema_version" yaml:"schema_version"`
Source Source `json:"source" yaml:"source"`
PatchDir string `json:"patch_dir" yaml:"patch_dir"`
Patches []Patch `json:"patches" yaml:"patches"`
}
Manifest describes a source archive and a sequence of patches. It records declarations, not verified input bytes. Validate checks values constructed or changed in Go as well as values returned by the YAML loader.
type Options ¶
type Options struct {
// InputRoot is an existing directory containing the declared inputs.
// Symlinks are rejected in every path component.
InputRoot string
// OutputDir is a new path outside InputRoot, beneath an existing parent.
// The parent must have no symlink components and support atomic rename
// without replacement on Linux.
OutputDir string
// PatchExecutable selects GNU patch. Empty uses "patch" from PATH.
PatchExecutable string
}
Options selects the local input, output and GNU patch paths for an audit. These paths are used to run the audit and do not enter its report.
type Patch ¶
type Patch struct {
ID string `json:"id" yaml:"id"`
File string `json:"file" yaml:"file"`
SHA256 string `json:"sha256" yaml:"sha256"`
Upstream string `json:"upstream" yaml:"upstream"`
CVEs []string `json:"cves,omitempty" yaml:"cves,omitempty"`
}
Patch identifies one file in the patch directory. Upstream and CVEs describe declared origins and CVE associations; the audit does not authenticate them.
type PatchInventory ¶
type PatchInventory interface {
Prepare(context.Context, PatchRequest) (InventoryResult, error)
}
type PatchRequest ¶
type PatchRequest struct {
Inputs ConfinedInputs
PatchDir string
Patches []Patch
StagingDir string
}
type PatchResult ¶
type PatchResult struct {
Patch
Status PatchStatus `json:"status"`
Reason Reason `json:"reason"`
}
PatchResult combines a patch declaration with its application status and reason. Results stay in manifest order. Preparation or tooling failures leave every patch not_run. Once execution stops, all later patches remain not_run.
type PatchStatus ¶
type PatchStatus string
PatchStatus describes whether a patch was not run, applied or failed.
const ( PatchNotRun PatchStatus = "not_run" PatchApplied PatchStatus = "applied" PatchFailed PatchStatus = "failed" )
type PatchTarget ¶
PatchTarget describes a target that passed diff header validation. Paths have their first component removed. OldPath is empty for an addition, and NewPath is empty for a deletion; a modification uses equal paths. Renames and mode changes are unsupported. Git mode metadata does not override version 1 final permissions, and multiple mode declarations must agree. Targets remain in diff order. Patch inventory is responsible for parsing hunks.
type PreparedSource ¶
type PreparedSource struct {
Archive StagedFile
WorkspaceDir string
IntendedModes map[string]uint32
}
PreparedSource describes the extracted workspace. Files remain readable and writable by their owner until final hashing. IntendedModes records original file permissions masked to 0777; output directories receive 0755. Archive owner and group IDs and timestamps are discarded.
type Reason ¶
type Reason string
Reason is a stable classification for an audit result or error.
const ( ReasonNone Reason = "none" ReasonInvalidManifest Reason = "invalid_manifest" ReasonHashMismatch Reason = "hash_mismatch" ReasonInventoryMismatch Reason = "inventory_mismatch" ReasonPatchFailed Reason = "patch_failed" ReasonUnsafeInput Reason = "unsafe_input" ReasonLimitExceeded Reason = "limit_exceeded" ReasonIO Reason = "io_failure" ReasonUnsupportedTool Reason = "unsupported_tool" ReasonTimeout Reason = "timeout" ReasonCancelled Reason = "cancelled" ReasonOutputExists Reason = "output_exists" ReasonUnsupportedPublication Reason = "unsupported_publication" ReasonOutputWrite Reason = "output_write_failure" )
type Report ¶
type Report struct {
SchemaVersion int `json:"schema_version"`
Outcome Outcome `json:"outcome"`
Stage Stage `json:"stage"`
Reason Reason `json:"reason"`
Source Source `json:"source"`
Patches []PatchResult `json:"patches"`
FinalTreeSHA256 string `json:"final_tree_sha256,omitempty"`
Files []FileRecord `json:"files,omitempty"`
DigestDefinition string `json:"digest_definition"`
Limitations string `json:"limitations"`
}
Report records an audit's input declarations and result without host paths, timestamps or raw tool logs. Patches remain in application order. Files are sorted by their relative paths' UTF-8 bytes. Files and FinalTreeSHA256 are present only on success. Writers validate the report without repeating the audit.
func (Report) ExitCode ¶
ExitCode combines the report and error into a CLI exit status: 0 for complete success, 1 for an expected mismatch, or 2 for an operational error or invalid report. Always pass the returned error; any non-nil error takes precedence, including a report-write failure after complete output has been published.
type RunError ¶
RunError describes invalid input, setup or I/O problems, tooling failures, timeouts or cancellation. Stage and Reason are stable classifications. Err is an optional diagnostic cause; it must never be copied into a Report.
type Source ¶
type Source struct {
Path string `json:"path" yaml:"path"`
SHA256 string `json:"sha256" yaml:"sha256"`
RootDir string `json:"root_dir" yaml:"root_dir"`
}
Source identifies a source archive by its relative path and expected hash. RootDir is the single archive root directory removed during extraction.
type SourcePreparer ¶
type SourcePreparer interface {
Prepare(context.Context, SourceRequest) (SourceResult, error)
}
type SourceRequest ¶
type SourceRequest struct {
Inputs ConfinedInputs
Source Source
StagingDir string
WorkspaceDir string
}
type SourceResult ¶
type SourceResult struct {
Source PreparedSource
Failure *Failure
}
type Stage ¶
type Stage string
Stage identifies the part of an audit associated with a result or error.
type StagedFile ¶
StagedFile identifies a private verified copy of an input file. SHA256 and Size describe those exact bytes. Path is used to run the audit, not stored in reports.
type StagedPatch ¶
type StagedPatch struct {
Patch Patch
Input StagedFile
Targets []PatchTarget
}