conformance

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 28 Imported by: ? 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 conformance is the one test suite every sandbox driver must pass (design §11.3). It is what makes "a sandbox sees placeholders only and has no way out except the allowlisted proxy" a tested property of each driver, not a promise of its documentation.

A driver's test file builds a Harness and calls Run:

func TestConformance(t *testing.T) {
	conformance.Run(t, conformance.Harness{
		NewDriver:    func(t *testing.T) sandbox.Driver { ... },
		Image:        "alpine/curl",
		Capabilities: conformance.Capabilities{EgressEnforced: true},
		Egress:       egress,
		Reap:         func(ctx context.Context, d sandbox.Driver) error { ... },
	})
}

Run covers: create, exec, copy and destroy; exit codes; environment; stdin; streaming; a timeout that kills the command; the output cap; workspace persistence across a new driver instance; ErrNotFound; egress allow and deny through the proxy and directly; credential placeholder to injection; no secret visible inside the sandbox; TTL cleanup.

A case the driver cannot run is skipped with a reason that names the missing capability (a nil Egress, a nil Reap, Capabilities.EgressEnforced false). It is never passed silently, so a test report shows what a driver was not tested for.

The suite runs commands with relative paths from the default working directory (the workspace), and names the workspace only in Dir, CopyIn and CopyOut. Inside the sandbox it needs sh, cat, printf, sleep, wc, kill, grep, tr and env, and curl for the egress cases.

Drivers whose sandboxes can reach a proxy on the machine running the tests (docker, sbx) get the proxy, the upstream server and the Egress description from NewLocalEgress. A driver with a remote proxy (k8s) deploys its own and fills Egress by hand.

Index

Constants

View Source
const (
	AllowedHost = "allowed.conformance.test"
	DeniedHost  = "denied.conformance.test"
)

Hosts of the local upstream. They resolve nowhere but in the proxy that NewLocalEgress starts.

Variables

This section is empty.

Functions

func DockerHostNames

func DockerHostNames(t *testing.T, bin string) []string

DockerHostNames lists how a container with a route out reaches the test's machine: Docker's name for the host and the default bridge's gateway.

func DockerImage

func DockerImage() string

DockerImage is the sandbox image of the Docker-based conformance runs: an Alpine with curl. KOJO_CONFORMANCE_IMAGE replaces it.

func DockerListenHost

func DockerListenHost() string

DockerListenHost is the address a server in the test process must listen on for containers to reach it: loopback with Docker Desktop, which forwards host.docker.internal there, and every interface on Linux, where containers arrive over the bridge.

func NewDockerNetwork

func NewDockerNetwork(t *testing.T, bin string, internal bool) string

NewDockerNetwork creates a Docker network with a random name for one test and removes it, with every container still attached to it and their workspace volumes, when the test ends.

func RequireDocker

func RequireDocker(t *testing.T) string

RequireDocker skips the test, naming the reason, when no Docker daemon answers. It returns the docker binary to use (KOJO_DOCKER, or docker).

func Run

func Run(t *testing.T, h Harness)

Run runs the suite against the driver h builds.

Types

type Capabilities

type Capabilities struct {
	// NeedsDocker: the driver gives a sandbox its own Docker daemon when
	// SandboxSpec.NeedsDocker is set. Without it, the suite checks that such
	// a spec is refused with sandbox.ErrUnavailable; with it, Image must
	// hold a docker CLI.
	NeedsDocker bool
	// EgressEnforced: a sandbox has no route out except the proxy. Without
	// it the direct-egress case is skipped, since it would fail by design.
	EgressEnforced bool
}

Capabilities are the optional things a driver may support.

type Egress

type Egress struct {
	// AllowedURL is the base URL of the upstream on the host the suite puts
	// on the allowlist: https://allowed.example:8443.
	AllowedURL string
	// DeniedURL is the base URL of the same upstream under a host that is
	// never allowlisted. A proxy that let it through would reach the
	// upstream, so a pass means the proxy refused.
	DeniedURL string
	// DirectURLs are base URLs under which a sandbox with a route out would
	// reach the upstream without the proxy (the host's address as a sandbox
	// sees it, a node IP). The suite requests them with the proxy disabled
	// and expects every one to fail.
	DirectURLs []string
	// Credential is the reference the suite puts in a policy. The driver's
	// CredentialSource must resolve it to a HostCredential for AllowedURL's
	// host with the header Header, a value that contains Secret, and
	// Placeholder.
	Credential sandbox.CredentialRef
	// Header is the header the credential is injected in: Authorization.
	Header string
	// Placeholder is what the sandbox may see instead of the secret.
	Placeholder string
	// Secret is the secret part of the header value. The upstream must
	// receive it; nothing inside the sandbox may contain it.
	Secret string
	// Received returns the value of Header in the request the upstream got
	// for path, and false when no request for path arrived.
	Received func(path string) (value string, ok bool)
	// ScanPaths are the directories the suite greps for Secret inside the
	// sandbox, next to the workspace and every process environment.
	// Default: /etc, /tmp, /run, /root, /home.
	ScanPaths []string
}

Egress describes a proxy setup to the suite. The upstream behind AllowedURL and DeniedURL is one server that records, per request path, the credential header it received.

type Harness

type Harness struct {
	// NewDriver returns a new driver instance on the same backend. The suite
	// calls it several times: a second instance stands for kojo after a
	// restart and must find the sandboxes the first one created.
	NewDriver func(t *testing.T) sandbox.Driver
	// Image is the image of every sandbox the suite creates. Drivers
	// without images (fake) leave it empty.
	Image string
	// Capabilities say what the driver under test can do. The suite checks
	// that Driver.Health agrees with them.
	Capabilities Capabilities
	// Egress describes the proxy and the upstream the driver is wired to.
	// Nil skips the egress and credential cases.
	Egress *Egress
	// Reap triggers the driver's TTL cleanup, as the core does periodically.
	// It may return before the cleanup is done: the suite polls. Nil skips
	// the TTL case.
	Reap func(ctx context.Context, d sandbox.Driver) error
	// Timeout bounds one case, sandbox start included. Default 5 minutes.
	Timeout time.Duration
}

Harness is what a driver's test gives the suite.

type LocalEgress

type LocalEgress struct {
	// Proxy is the proxy the driver under test must be wired to.
	Proxy *proxy.Server
	// Credentials resolves Egress.Credential, and nothing else.
	Credentials sandbox.CredentialSource
	// Egress describes the setup to the suite: put it in Harness.Egress.
	Egress *Egress
	// contains filtered or unexported fields
}

LocalEgress is an in-process kojo-proxy with an upstream server behind it, for drivers whose sandboxes can reach the machine running the tests.

func NewLocalEgress

func NewLocalEgress(t *testing.T, o LocalEgressOptions) *LocalEgress

NewLocalEgress starts a proxy and an upstream on the test's machine and stops them when the test ends.

The upstream serves HTTPS for AllowedHost and DeniedHost with certificates from a throwaway CA that only the proxy trusts, and plain HTTP on a second port for the direct-egress case. The proxy resolves both hosts to the upstream and runs with AllowPrivate, since the upstream is on loopback.

func (*LocalEgress) Received

func (le *LocalEgress) Received(path string) (string, bool)

Received returns the credential header of the request the upstream got for path, and false when no such request arrived.

type LocalEgressOptions

type LocalEgressOptions struct {
	// Listen is the address the proxy and the upstream listen on, without a
	// port. Default 127.0.0.1. Use 0.0.0.0 when sandboxes reach the test's
	// machine over a bridge (Docker on Linux).
	Listen string
	// AdvertiseHost is the host sandboxes use for the proxy. Default
	// 127.0.0.1, which the docker driver maps to the host on its own.
	AdvertiseHost string
	// DirectHosts are the names or addresses under which a sandbox with a
	// route out would reach the test's machine: host.docker.internal, a
	// bridge gateway address. They become Egress.DirectURLs.
	DirectHosts []string
	// OnDecision receives the proxy's decisions. Optional.
	OnDecision func(proxy.Decision)
	// Logger receives the proxy's log. Optional.
	Logger *slog.Logger
}

LocalEgressOptions configure NewLocalEgress.

Jump to

Keyboard shortcuts

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