devsdk

package
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: AGPL-3.0 Imports: 24 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 devsdk selects and identifies the plugin SDK a workspace builds against, without importing native, plugin-process, profile or workspace orchestration packages. The controller's build graph, the host's managed plugin builder and the trusted artifact recorder share this vocabulary instead of each deriving "which SDK" from a path string.

A Selection mirrors the workspace manifest's single authority (links.sdkRepositoryID): a selected checkout means source mode, and no selection means the SDK each consumer's own Go dependency graph publishes. An Identity is the validated evidence of the SDK a build used. A published identity is produced by the verifier from a consumer's effective Go module graph (see NewVerifier) and admitted under the release policy.

"Verified" has one meaning for a published identity, and no more:

  • the extracted module-cache bytes hash (dirhash) to module and go.mod checksums the CONTROLLER itself reviewed (the compiled-in reviewed releases), not merely what a branch's go.sum says;
  • the module provides the Capability, observed in those bytes;
  • the compiled binary's Go buildinfo names exactly that version and sum with no replacement (VerifyBinary);
  • the identity was unchanged between a before and an after observation of the build (IdentityChanged).

Not claimed: that the SDK's behavior was reviewed for safety or sandboxing; that the executable's bytes were compiled from the hashed bytes (buildinfo is written by the go command, not measured); or that the toolchain or the Go environment is trustworthy. A Go environment whose effective GOFLAGS is not empty is refused, because it could change the source that is compiled.

Index

Constants

View Source
const (
	// CodeContractMismatch: a consumer's module files state no usable SDK requirement (exit 3).
	CodeContractMismatch = "sdk_contract_mismatch"
	// CodeChecksumsRequired: go.sum lacks the SDK checksums; repair the source branch (exit 3).
	CodeChecksumsRequired = "sdk_checksums_required"
	// CodeSelectionConflict: the consumer redirects or vendors the SDK, contradicting a published selection (exit 4).
	CodeSelectionConflict = "sdk_selection_conflict"
	// CodeReleaseUntrusted: the effective SDK is not an accepted release (exit 4).
	CodeReleaseUntrusted = "sdk_release_untrusted"
	// CodeIntegrityMismatch: module-cache bytes and recorded checksums disagree (exit 4).
	CodeIntegrityMismatch = "sdk_integrity_mismatch"
	// CodeIdentityChanged: the effective SDK differs from the one verified before a build (exit 4).
	CodeIdentityChanged = "sdk_identity_changed"
	// CodeDependencyUnavailable: the SDK module could not be resolved or downloaded (exit 5).
	CodeDependencyUnavailable = "sdk_dependency_unavailable"
)

Typed refusal codes of published-SDK verification. Each keeps its exit class across the supervisor boundary through the controller's workspace exit table.

View Source
const (
	// FloorVersion is the lowest released plugin SDK a published build may use:
	// the SDK this controller is itself pinned to. A published SDK is a released
	// tag at or above it; older releases and pseudo-versions are not supported and
	// never converted. TestFloorMatchesTheControllerPin fails when the
	// controller's own pin moves, so raising the floor is always a deliberate edit
	// of this constant.
	FloorVersion = "v0.18.0"

	// Capability names the SDK's per-profile state-root isolation contract. A
	// published module must provide it, observed in its verified bytes.
	Capability = "state-root-v1"
)
View Source
const Module = "github.com/omniviewdev/plugin-sdk"

Module is the plugin SDK's Go module path.

Variables

View Source
var ErrNotAccepted = errors.New("SDK is not accepted")

ErrNotAccepted marks an SDK identity or selection the injected Policy does not admit. Callers translate it to their own refusal.

Functions

func AdmitDeclared

func AdmitDeclared(policy Policy, consumer string, published Published) error

AdmitDeclared applies policy to one complete published tuple and refuses it as an untrusted release (typed sdk_release_untrusted, joined to ErrNotAccepted) when it is not admitted. consumer labels the refusal. Callers that only read a consumer's declared tuple use it to report a refusal early; the verifier applies it to the declared and the effective tuples.

func CheckGoEnvironment

func CheckGoEnvironment(ctx context.Context, consumer Consumer, declared Published, run Runner) error

CheckGoEnvironment refuses a Go environment whose effective GOFLAGS is not empty, observed through the caller's runner under ModuleEnvironment. An empty GOFLAGS variable does not mask the Go environment file (`go env -w`, the file `go env GOENV` names): Go falls back to the file's value, so a user-level -overlay, -toolexec, -modfile or -mod=vendor there could change the SDK source that is compiled although only -mod=readonly is pinned. The refusal keeps the user's GOPRIVATE, GOPROXY, GOMODCACHE and checksum settings, which GOENV=off would have discarded. It runs before anything is resolved or downloaded, and a build that follows its verification in the same environment is covered by it. Verification and workspace preflight share this one check; it only reads.

func CheckGoEnvironmentFile

func CheckGoEnvironmentFile(consumer string, declared Published) error

CheckGoEnvironmentFile is the read-only, process-free preflight counterpart of CheckGoEnvironment: it parses the Go environment file (GOENV, "off" meaning none, else <user config dir>/go/env; KEY=VALUE lines, "#" comments, the last GOFLAGS line wins) and refuses a non-empty GOFLAGS there. The ambient GOFLAGS variable is not read: launch neutralizes it. A missing or unreadable file, an unresolvable config directory or an empty GOFLAGS is no refusal; launch's authoritative check still runs.

func GoFlagsRefusal

func GoFlagsRefusal(consumer string, declared Published, flags string) error

GoFlagsRefusal is the one typed refusal of a non-empty effective GOFLAGS, shared by the launch check (the go command's answer) and preflight (the Go environment file). flags is redacted and bounded here.

func IdentityChanged

func IdentityChanged(consumer, message string) error

IdentityChanged reports an effective SDK that differs from the identity verified before a build. Nothing built against it may be attested or launched.

func ModuleEnvironment

func ModuleEnvironment() []string

ModuleEnvironment is appended to every published-SDK Go command, over the runner's base environment: no workspace file, no ambient GOFLAGS variable. Settings in the Go environment file are not masked by an empty variable: an empty GOFLAGS falls back to the file's value. Every command therefore passes -mod and -modfile explicitly, and the verifier refuses an effective GOFLAGS before it resolves anything (see CheckGoEnvironment). A published build that is not itself run by the verifier's runner appends this too.

func PublishedDirectory

func PublishedDirectory(ctx context.Context, consumer Consumer, run Runner) (string, error)

PublishedDirectory returns the module-cache directory Go resolves the SDK to for consumer, for read-only advisory scans after a successful verification. It is an observed build input, never selection authority, and is not itself a verification.

func VerifyBinary

func VerifyBinary(consumer, binary string, identity Identity) error

VerifyBinary checks the Go build information of a built executable against the SDK identity its build was verified under. Every identity requires the SDK module to be part of the binary. A published identity additionally requires exactly the verified version and module checksum and no replacement. A source identity keeps its stronger path binding in the callers' before and after source observations: the compiled build information of a replaced module names only the replacement.

The build information proves which module the Go command selected, not that the executable's bytes were compiled from it; the trusted builder's before and after verification brackets that gap.

Types

type Consumer

type Consumer struct {
	// Name labels the consumer in diagnostics, normally its repository ID.
	Name string
	// Directory is the module root: the absolute clean directory holding go.mod
	// and go.sum, where Go commands run.
	Directory string
	// Modfile optionally names the absolute effective module file Go builds with
	// instead of Directory/go.mod, the host's generated host.mod. Its sum file is
	// the same path ending in .sum. It is verified in addition to Directory/go.mod
	// and must state the same SDK tuple.
	Modfile string
}

Consumer is a Go module whose effective plugin SDK dependency is observed.

type Identity

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

Identity is the validated evidence of the SDK a build used: a tagged union of a source checkout's identity or a published module's identity. Construct one with NewSourceIdentity or NewPublishedIdentity; the zero Identity is invalid. Identities are comparable, so before/after observations compare with ==.

func NewPublishedIdentity

func NewPublishedIdentity(published Published) (Identity, error)

NewPublishedIdentity validates a published module's resolved identity.

func NewSourceIdentity

func NewSourceIdentity(source devsource.Identity) (Identity, error)

NewSourceIdentity validates evidence that devsource.Verify observed.

func (Identity) Mode

func (i Identity) Mode() Mode

Mode reports which variant the identity holds, or "" for the zero Identity.

func (Identity) Published

func (i Identity) Published() (Published, bool)

Published returns the published variant. It reports false for any other variant.

func (Identity) Source

func (i Identity) Source() (devsource.Identity, bool)

Source returns the source variant. It reports false for any other variant.

func (Identity) Validate

func (i Identity) Validate() error

Validate rejects the zero identity, incomplete evidence and mixed variants.

type Mode

type Mode string

Mode says which SDK a Selection or Identity describes.

const (
	// ModeSource builds against the explicitly selected SDK checkout.
	ModeSource Mode = "source"
	// ModePublished builds against each consumer's published SDK dependency.
	ModePublished Mode = "published"
)

type ModuleFiles

type ModuleFiles struct {
	GoMod []byte
	GoSum []byte
	// Vendored reports that the module root holds a vendor entry. Go would
	// default to compiling repository-local bytes instead of the module cache.
	Vendored bool
}

ModuleFiles are one consumer's module files as committed or checked out. They are read without running Go and without touching the network.

type Policy

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

Policy decides which SDK identities may build, attest and launch. It is passed to constructors; nothing reads it from the environment or a global.

Source identities are admitted by their own checkout verification and path binding. A published identity is admitted only when the function given to NewPolicy accepts it: always a complete, validated tuple. The zero Policy accepts none; production uses ReleasePolicy.

func NewPolicy

func NewPolicy(acceptPublished func(Published) error) Policy

NewPolicy returns a Policy that admits a published identity exactly when acceptPublished returns nil. A nil function accepts no published identity.

func NewReleasePolicy

func NewReleasePolicy(floor string, reviewed ...Published) Policy

NewReleasePolicy is ReleasePolicy for a caller-supplied floor and table of reviewed releases. Production passes the compiled-in ones through ReleasePolicy; tests that serve synthetic releases name them here, through the same constructors that inject every other policy.

func ReleasePolicy

func ReleasePolicy() Policy

ReleasePolicy is the policy production uses: it admits a published identity exactly when it is a released tag at or above FloorVersion whose module and go.mod checksums equal the reviewed row for that version. It is a constructor value, never read from the environment or a global.

What an admitted, verified identity means is stated on the package: the bytes hash to checksums this controller reviewed, the module provides Capability, and the compiled binary names exactly that version and sum. It does not mean the SDK's behavior was reviewed for safety or sandboxing.

func (Policy) Admit

func (p Policy) Admit(identity Identity) error

Admit validates identity and applies the policy. An identity that is not admitted wraps ErrNotAccepted.

type Published

type Published struct {
	Module    string `json:"module"`
	Version   string `json:"version"`
	ModuleSum string `json:"moduleSum"`
	GoModSum  string `json:"goModSum"`
}

Published identifies a released SDK module by what Go resolved: the module version and the go.sum content hashes of its source tree and go.mod.

func Declare

func Declare(consumer string, files ModuleFiles) (Published, error)

Declare reads the SDK tuple a consumer's own module files state: the required version and the go.sum checksums recorded for it. It refuses what no later step could repair: an unusable go.mod, any replacement of the SDK (including a dormant version-specific one, which a different graph resolution could activate), a vendored dependency tree, a missing requirement, and missing or conflicting checksums. It never selects, downloads or applies release policy. Replacement targets are never echoed: they can carry credentials.

func ReviewedReleases

func ReviewedReleases() []Published

ReviewedReleases returns a copy of the append-only table of reviewed releases.

type Request

type Request struct {
	Selection Selection
	Consumer  Consumer
	// Run executes the Go commands a published verification needs. It is unused
	// for a source selection.
	Run Runner
}

Request names what a Verifier identifies. A source selection is identified from its checkout alone. A published selection is identified from the effective Go module graph of one consumer, resolved with the caller's runner.

type Runner

type Runner func(ctx context.Context, directory string, environment []string, args ...string) ([]byte, error)

Runner runs one Go command ("go" plus args) in directory under the caller's process ownership and returns its standard output. Entries in environment are appended after the runner's own base environment, so they win. A failed command returns an error whose text carries bounded, sanitized diagnostics. Verification never starts a Go process of its own.

type Selection

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

Selection is the SDK a workspace selected. The zero Selection is published: no checkout is selected, exactly like a null links.sdkRepositoryID.

func PublishedSelection

func PublishedSelection() Selection

PublishedSelection selects the SDK each consumer's Go module graph publishes.

func SelectionOf

func SelectionOf(workspace devcontract.ResolvedWorkspace) (Selection, error)

SelectionOf derives the selection a resolved workspace manifest defines: the linked SDK repository's checkout, or the published SDK when none is linked.

func SourceSelection

func SourceSelection(directory string) (Selection, error)

SourceSelection selects the SDK checkout at directory, which must be an absolute clean path. It does not touch the filesystem: verification binds the directory to the live repository.

func (Selection) Directory

func (s Selection) Directory() (string, bool)

Directory returns the selected checkout. It reports false for the published SDK, which has no directory authority.

func (Selection) MarshalText

func (s Selection) MarshalText() ([]byte, error)

MarshalText encodes a source selection as its checkout directory, the form the link journal has always persisted. A published selection has no textual form: persist it by omission (`omitzero`), never as an empty string.

func (Selection) Mode

func (s Selection) Mode() Mode

Mode reports whether the selection is a source checkout or the published SDK.

func (*Selection) UnmarshalText

func (s *Selection) UnmarshalText(text []byte) error

UnmarshalText decodes a persisted source selection.

type Verifier

type Verifier func(ctx context.Context, request Request) (Identity, error)

Verifier observes the identity of the SDK a request resolves to. Production code builds one with NewVerifier; tests inject deterministic verifiers.

func NewVerifier

func NewVerifier(policy Policy) Verifier

NewVerifier returns the production Verifier. A source selection is identified with devsource.Verify (HEAD plus the exact tracked and untracked source bytes) and admitted under policy. A published selection is identified from the consumer's effective module graph: see observePublished.

Directories

Path Synopsis
Package sdktest builds hermetic Go module worlds for tests of published-SDK handling: a scratch module cache and a file:// module proxy that serve real plugin SDK releases.
Package sdktest builds hermetic Go module worlds for tests of published-SDK handling: a scratch module cache and a file:// module proxy that serve real plugin SDK releases.

Jump to

Keyboard shortcuts

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