conformance

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package conformance is the driver-agnostic parity gate for runner.Runner implementations. Call Run(t, r) from driver-specific test files, and RunPlacementRouting(t, substrate, opts) beside it: a placement is honoured or refused, never substituted.

Contract assertions enforced here:

  1. Capabilities sanity: if ConfinementClasses is non-empty, CreateSandbox must honour the strongest class and must never silently downgrade it.
  2. Create → Status → Stop idempotency: a second StopSandbox on a stopped sandbox must return nil.
  3. KillSandbox on a missing/unknown ref must return nil. A self-hosted runner answers only for a sandbox it holds or can prove it created and refuses any other ref, so there the missing ref is one it could have created.
  4. L0 assertion hook: if StructuralEgress is declared, an injectable probe (DefaultRouteProbe) asserts that no default route is reachable from the sandbox.
  5. Wait exit-code propagation: Exec'ing a short-lived command, Wait must block until it exits and return its exit code (incl. a non-zero code).
  6. Loopback relay parity: ExecStream reaches a port the sandbox is already listening on inside its own netns, full-duplex, with stdin still open — the transport the UI-sandbox gateway rides.
  7. Ephemeral disk enforcement: on a driver that declares EphemeralDiskEnforcement `eviction`, a run that writes past its DiskMiB limit really does die, and a run with an oversized limit still schedules (its request is the small floor, never a copy of the limit).
  8. User drives: a drive inside the substrate's ceiling binds at runner.DriveTarget, writable by uid 1000 with DAC intact beneath it, and a drive outside that ceiling is refused at CreateSandbox.

Index

Constants

View Source
const (
	UserDriveLockedDir  = "locked"
	UserDriveLockedFile = "secret"
)

UserDriveLockedDir is the directory UserDriveFixture.Lock makes at the root of the allowed drive, holding UserDriveLockedFile.

Variables

This section is empty.

Functions

func CheckRecordingCapability

func CheckRecordingCapability(t *testing.T, r runner.Runner, opts RecordingOptions)

CheckRecordingCapability is the recording-capability honesty gate. It is an ADDITIVE, standalone helper (NOT part of Run) so existing driver suites are unaffected: a driver opts in by calling it explicitly.

The contract it enforces, fail-closed both ways:

  • A driver that declares SessionRecording=true MUST honour the recording contract. When opts.RecordingProbe is supplied, the suite creates a sandbox, execs a (recorded) command, and delegates to the probe, which asserts a real recording artifact exists. A driver that "declares but does not produce" therefore fails. If no probe is injected the check is marked pending (skipped with a notice) rather than passing silently.

  • A driver that declares SessionRecording=false MUST NOT pretend to record. The suite asserts the honest-empty posture: the driver makes no recording claim, and (when a probe IS supplied for a non-recording driver, which is a misuse) refuses to run it — a false-declaring driver cannot smuggle a "recording happened" result past the gate.

Drivers that declare no ConfinementClasses (honest stubs) cannot create a sandbox, so the artifact-producing half is necessarily skipped for them; the declaration-honesty assertion still runs and must pass.

func ExecKeyValues added in v0.8.2

func ExecKeyValues(t *testing.T, ctx context.Context, r runner.Runner, ref, script string) map[string]string

ExecKeyValues runs script in the sandbox through ExecStream and returns its `key=value` stdout lines (parseKeyValueLines' rules). For probes that report several verdicts at once: one exec, one recording, one transport to trust.

func LoadableProxyConfig added in v0.8.0

func LoadableProxyConfig() runner.ProxyConfig

LoadableProxyConfig is the smallest ProxyConfig proxy.LoadConfigBytes accepts. A zero value is refused ("control_plane_url is required"), and the k8s driver waits for its proxy pod to be Ready, so a sandbox without it never starts there. The URL only has to pass startup, not be reachable: Injection is empty, so nothing calls it. Loopback, because the proxy refuses plaintext to any other host (hoptls.CheckURL).

func MemberDriveMount added in v0.9.0

func MemberDriveMount(t *testing.T, backend types.DriveBackend, owner string, sizeMiB int) types.DriveMount

MemberDriveMount is the mount a person's own drive gets: a managed object named for the drive and its owner, as the control plane derives it at dispatch and again at delete.

func Run

func Run(t *testing.T, r runner.Runner, opts Options)

Run executes the full conformance suite against r. It is the single entry-point called from driver-specific _test files.

func RunMemberDriveLifecycle added in v0.9.0

func RunMemberDriveLifecycle(t *testing.T, r runner.Runner, opts Options, mount types.DriveMount, objectExists func(t *testing.T) bool)

RunMemberDriveLifecycle is the member-drive row. The substrate must say it can delete what it creates; a file run A writes is there for run B; while a sandbox holds the drive (kept after its end where the substrate keeps one, else running) ReclaimDrive refuses with ErrDriveInUse and the object stays; once nothing holds it ReclaimDrive deletes the object, and a second call finds it already absent. objectExists reads the substrate from outside the runner.

func RunPlacementRouting added in v0.9.0

func RunPlacementRouting(t *testing.T, local substrate.Substrate, opts RoutingOptions)

RunPlacementRouting proves, against a real substrate, that a placement is honoured or refused and never substituted: asked for a runner that is not there or a class nobody advertises, the orchestrator refuses naming what was asked and local sees no create.

Types

type DefaultRouteProbe

type DefaultRouteProbe func(t *testing.T, ref string)

DefaultRouteProbe is called by Run when the driver declares StructuralEgress. Implementations should verify that no default-route connectivity exists from within the sandbox identified by ref, and call t.Errorf if one is found. The probe is injected so that the conformance library does not itself require network access or a running sandbox substrate.

type Options

type Options struct {
	// DefaultRouteProbe is called when StructuralEgress is declared. If nil
	// and StructuralEgress is true the suite marks the L0 check as skipped.
	DefaultRouteProbe DefaultRouteProbe
	// SandboxImage is the OCI image used for CreateSandbox calls. If empty,
	// "scratch" is used (drivers that cannot pull scratch should substitute
	// their own minimal image).
	SandboxImage string
	// Timeout is applied to each individual operation. Defaults to 30s.
	Timeout time.Duration
	// ExitArgv, when non-nil, builds the argv for a short-lived in-sandbox
	// command that exits with the given code. It gates the Wait exit-code
	// conformance case: when nil (or the driver declares no ConfinementClasses)
	// the case is skipped, because the suite cannot otherwise run a real process
	// inside SandboxImage. Drivers supply something like
	// {"sh", "-c", fmt.Sprintf("exit %d", code)} for their minimal image.
	ExitArgv func(code int) []string
	// EphemeralStorageProbe, when non-nil, is called by the ephemeral-disk case
	// with the ref of a sandbox admitted under a DELIBERATELY OVERSIZED disk
	// limit. It must read that sandbox's own accepted resource requests back from
	// the substrate (k8s: `pods: get`) and assert the request is the small fixed
	// floor, NEVER a copy of the limit — the one assertion that catches an
	// API-server defaulting the driver's own unit tests cannot see. Injected for
	// DefaultRouteProbe's reason: only the substrate knows how to read its own
	// object. Nil ⇒ that sub-case is skipped.
	EphemeralStorageProbe func(t *testing.T, ref string)
	// AgentUserImage, when set, is SandboxImage run as uid 1000 — the identity
	// the image contract gives every agent image. The managed-files case runs
	// on it and then requires the probe to report uid 1000, because a root
	// probe can rename, chmod and rewrite a root-owned file without any
	// capability and so proves nothing about immutability. Empty ⇒ the case
	// runs on SandboxImage, asserting those refusals only when the probe is not
	// root (the Kubernetes substrate runs the agent as uid 1000 whatever the
	// image's USER) and logging them otherwise.
	AgentUserImage string
	// UserDrives, when non-nil, is the substrate's user-drive fixture: a drive
	// its ceiling allows and drives it must refuse. Nil ⇒ the UserDrives case
	// is skipped (the must-pass floor in scripts/test-report.sh reddens that
	// skip on a real substrate). See UserDriveFixture.
	UserDrives *UserDriveFixture
	// ExecState, when non-nil, returns the substrate's own record of the exec
	// Exec returned (running, exit code, pid). Diagnostic only: the Wait
	// exit-code case logs it when the code is wrong, and asserts nothing on it.
	ExecState func(ctx context.Context, execID string) string
}

Options controls optional behaviour of the conformance suite.

type RecordingOptions

type RecordingOptions struct {
	Options
	// RecordingProbe is invoked when the driver declares SessionRecording. If
	// the driver declares recording but RecordingProbe is nil, the check is
	// marked pending (skipped with a notice) — the same fail-soft posture
	// DefaultRouteProbe uses, so a driver CI without a recorder substrate does
	// not hard-fail, but a driver CI that wires the probe verifies the contract.
	RecordingProbe RecordingProbe
	// MutateSpec, when non-nil, edits the recording sandbox's spec after the
	// confinement class is pinned and before CreateSandbox. A recording
	// driver's proxy needs a control plane to upload the cast to, which
	// minimalSpec does not carry; the caller supplies it here.
	MutateSpec func(*runner.SandboxSpec)
}

RecordingOptions controls CheckRecordingCapability. It embeds Options for the SandboxImage/Timeout/ExitArgv fields the recording case shares with Run's suite; it is intentionally a SEPARATE type from Options so that adding the recording gate does not change the signature or behaviour of Run / the existing driver suites — only RecordingOptions literal construction (embedding changes neither).

type RecordingProbe

type RecordingProbe func(t *testing.T, ref string)

RecordingProbe is called by CheckRecordingCapability when the driver declares SessionRecording. Implementations should verify that the driver actually honoured the recording contract for the sandbox identified by ref — i.e. a cast/recording artifact was genuinely produced (uploaded through the proxy's brokered route or written to the shared-mount fallback) — and call t.Errorf if it was not. Like DefaultRouteProbe, the probe is injected so the conformance library itself needs no recorder substrate.

type RefusedDrive added in v0.8.2

type RefusedDrive struct {
	Name  string
	Mount types.DriveMount
	// WantErr is a substring the refusal must carry, so a failure for an
	// unrelated reason (an image pull, a missing network) cannot pass as the
	// drive refusal.
	WantErr string
	// Allowing, when non-nil, is the same substrate configured so that THIS
	// drive is inside its ceiling. The case mounts it there first and
	// requires the agent to write it: the positive control that makes the
	// refusal attributable to the ceiling rather than to anything else about
	// the fixture (a missing directory, an unmountable path).
	Allowing runner.Runner
}

RefusedDrive is one drive the substrate must refuse.

type RoutingOptions added in v0.9.0

type RoutingOptions struct {
	// Timeout bounds each subtest's calls; zero means 30 seconds.
	Timeout time.Duration
	// Image is the OCI image a honoured placement creates.
	Image string
	// Offline, when set, is a registered runner substrate whose link is down.
	Offline substrate.Substrate
}

RoutingOptions configures RunPlacementRouting.

type UserDriveFixture added in v0.8.2

type UserDriveFixture struct {
	// Mount is a drive inside the ceiling. The case binds it and requires the
	// agent (uid 1000) to write and read it back.
	Mount types.DriveMount
	// Lock makes UserDriveLockedDir at the drive's root, holding
	// UserDriveLockedFile, mode 0700 and owned by an identity other than uid
	// 1000. Called AFTER the sandbox holding Mount exists: on kubernetes that
	// create is what provisions the storage.
	Lock func(t *testing.T)
	// ReadBack, when non-nil, returns a file at the drive's root as seen from
	// OUTSIDE any sandbox (the host directory a docker share binds). It is
	// what proves the bind landed in the allowed directory and not on some
	// other storage that happens to be writable.
	ReadBack func(t *testing.T, name string) string
	// Refused are drives outside the ceiling; CreateSandbox must refuse each.
	Refused []RefusedDrive
	// Also, when set, is a second drive at its own derived path (below
	// runner.DrivesRoot or runner.SharedRoot). The case mounts it beside Mount
	// in one sandbox and requires the agent to write and read back both, then
	// requires a second drive at Mount's own target to be refused.
	Also *types.DriveMount
}

UserDriveFixture is a substrate's half of the UserDrives case: the drives it is held to, built by the driver-specific test file, because what the "ceiling" is differs by substrate (docker: WARDYN_USER_DRIVE_HOST_ROOTS over a host path; kubernetes: only a claim in the run's namespace).

Directories

Path Synopsis
Command hopfake stands in for wardynd's proxy-facing TLS listener in two docker conformance cases.
Command hopfake stands in for wardynd's proxy-facing TLS listener in two docker conformance cases.

Jump to

Keyboard shortcuts

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