release

package
v0.1.90-dev.3 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 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 release is the format of a signed release bundle and the checks on it. The owner signs manifest.json offline (`mistgate release sign`); the panel shows the bundle and relays it; the node agent is the one that verifies it before it replaces its own binary. One package for all three so they cannot disagree.

Trust is a single ed25519 key: the public half is compiled into both binaries (buildinfo.ReleaseKey), the private half never leaves the owner. The signature covers the exact bytes of manifest.json, so nothing is ever re-serialised before it is verified.

Index

Constants

View Source
const (
	// EdgeBundleName, EdgeManifestName and EdgeSignatureName are the three files of a release that belong to the edge.
	EdgeBundleName    = "mistgate-edge.tar.gz"
	EdgeManifestName  = "edge-manifest.json"
	EdgeSignatureName = "edge-manifest.sig"
	// EdgeConfigName is the description of the scripts inside the tarball.
	EdgeConfigName = "edge.json"
	// EdgeSchema is the only edge.json schema this code writes and understands. Schema 1 was the single Worker plus the
	// Provisioner; no install of it exists, so nothing reads it any more (ParseEdgeConfig says so).
	EdgeSchema = 2
	// MaxEdgeBundle bounds the tarball a consumer will read (the wasm is about 50 MB; Cloudflare allows 64 MiB per script).
	MaxEdgeBundle = 256 << 20
)

The edge bundle is the Cloudflare edition of the panel: six Worker scripts (the FRONT router and five roles of the panel, each role with its own WebAssembly) and the admin SPA, in one tarball (mistgate-edge.tar.gz) that `mistgate edge deploy` uploads. It has its own manifest and its own signature context, so the one release key signs it without a panel or node signature ever being mistaken for it. The format is the contract of rounds E4 (producer) and E5 (consumer): a change needs both sides.

View Source
const (
	RoleFront     = "front"
	RoleLink      = "link"
	RolePublic    = "public"
	RoleAdmin     = "admin"
	RoleJobs      = "jobs"
	RoleProvision = "provision"
)

The roles of the scripts of a bundle. FRONT is the router and owns the Limiter and NodeLink objects; the five others are the panel built in a role (cmd/mistgate-edge-<role>) with the TypeScript shell around it (edge/worker/src/roles).

View Source
const (
	// Schema is the only manifest schema this code understands; a different one is refused, not guessed at.
	Schema = 1
	// MaxFileSize bounds a listed file (a node binary is about 30 MB).
	MaxFileSize = 256 << 20

	// ManifestName and SignatureName are the file names inside the bundle directory.
	ManifestName  = "manifest.json"
	SignatureName = "manifest.sig"
	// PanelManifestName and PanelSignatureName are the panel's own signed release (the mistgate-linux-* binaries),
	// uploaded to the GitHub release next to the node bundle. Same format, signed in its own context (SignPanel).
	PanelManifestName    = "panel-manifest.json"
	PanelSignatureName   = "panel-manifest.sig"
	PanelSSHSIGName      = "panel-manifest.sshsig"
	PanelSSHSIGNamespace = "mistgate-panel-manifest-v1"
	// MaxManifestBytes bounds what a parser will read (the panel sends it inside a command).
	MaxManifestBytes = 64 << 10
)
View Source
const MaxBuiltSkew = 24 * time.Hour

MaxBuiltSkew is how far ahead of the clock a manifest's Built may be. Built is a commit time, so it normally lies in the past; a day covers a commit made on a machine with a wrong clock or time zone and a node clock that is slow.

View Source
const WranglerD1Placeholder = "replace-with-your-d1-database-id"

WranglerD1Placeholder stands in the rendered configs for the id of the deployer's D1 database.

Variables

View Source
var (
	ErrBadSignature = errors.New("release: signature does not verify")
	ErrBadManifest  = errors.New("release: bad manifest")
	// ErrUnsupportedSchema is an ErrBadManifest whose only fault is the schema number (a newer release format).
	ErrUnsupportedSchema = fmt.Errorf("%w: unsupported schema", ErrBadManifest)
	ErrExpired           = errors.New("release: manifest expired")
	ErrDowngrade         = errors.New("release: manifest is older than the running build")
	// ErrFutureBuilt is an ErrBadManifest: Built orders releases, so a Built far ahead of the clock would make every
	// later honest release a downgrade.
	ErrFutureBuilt = fmt.Errorf("%w: built lies in the future", ErrBadManifest)
	// ErrUpToDate is not a failure: the manifest is exactly as new as the running build.
	ErrUpToDate     = errors.New("release: already current")
	ErrNoFile       = errors.New("release: no file for this platform")
	ErrSizeMismatch = errors.New("release: file size differs from the manifest")
	ErrHashMismatch = errors.New("release: file sha256 differs from the manifest")
)

Sentinel errors. Code maps them to the command error vocabulary of agent.proto ("UPDATE").

EdgeRoles are all roles of a schema 2 bundle, in the order a deployer uploads them: what a script binds is uploaded before the script that binds it, and FRONT, the one entry from outside, is last (design/cloudflare-edition, "Deploy order").

View Source
var ErrEdgeSchema = errors.New("release: unsupported edge.json schema")

ErrEdgeSchema is a bundle whose edge.json this code does not read.

Functions

func Code

func Code(err error) string

Code is the stable error code of agent.proto for one of this package's errors ("" for anything else).

func DecodePrivateKey

func DecodePrivateKey(s string) (ed25519.PrivateKey, error)

DecodePrivateKey reads what EncodePrivateKey wrote (surrounding whitespace allowed).

func EdgeScriptName added in v0.1.41

func EdgeScriptName(name, role string) string

EdgeScriptName is the name of the Worker of a role under the deployer's base name: FRONT keeps the base name (the domain, the Durable Object data and the agents' address belong to it), a role is `<name>-<role>`.

func EncodePrivateKey

func EncodePrivateKey(priv ed25519.PrivateKey) string

EncodePrivateKey is the key file content: the 32-byte seed in base64 (the public half is derived from it).

func EncodePublicKey

func EncodePublicKey(pub ed25519.PublicKey) string

EncodePublicKey is the base64 form that goes into buildinfo.ReleaseKey.

func GenerateKey

func GenerateKey() (ed25519.PublicKey, ed25519.PrivateKey, error)

GenerateKey makes a release key pair.

func HashFile added in v0.1.36

func HashFile(path string) (int64, string, error)

HashFile returns the size and the lowercase hex SHA-256 of a file.

func LatestTagForChannel added in v0.1.80

func LatestTagForChannel(tags []string, channel Channel) (string, bool)

LatestTagForChannel picks the highest semver tag the channel may see. Invalid tags are ignored.

func ParseBinaryName

func ParseBinaryName(name string) (base, goos, goarch string, err error)

ParseBinaryName splits "mistgate-node-linux-amd64" into ("mistgate-node", "linux", "amd64").

func ReadEdgeBundle added in v0.1.36

func ReadEdgeBundle(r io.Reader) (map[string][]byte, error)

ReadEdgeBundle returns the regular files of a tarball by path (directories are skipped), refusing a path that is absolute, has "..", or is listed twice. It is for tests and for a consumer that has verified the manifest.

func SanitizeSourceFailures

func SanitizeSourceFailures(raw string) string

SanitizeSourceFailures keeps bounded source failure entries with short, non-sensitive codes. It drops malformed entries individually so one bad item does not hide valid failure details.

func Sign

func Sign(priv ed25519.PrivateKey, manifest []byte) []byte

Sign returns the detached signature of the manifest bytes.

func SignEdge added in v0.1.36

func SignEdge(priv ed25519.PrivateKey, manifest []byte) []byte

SignEdge returns the detached signature of an edge manifest.

func SignPanel added in v0.1.15

func SignPanel(priv ed25519.PrivateKey, manifest []byte) []byte

SignPanel returns the detached signature of a panel manifest.

func SignPanelSSHSIG added in v0.1.34

func SignPanelSSHSIG(priv ed25519.PrivateKey, manifest []byte) ([]byte, error)

SignPanelSSHSIG returns an OpenSSH SSHSIG signature of a panel manifest.

func ValidChannelTag added in v0.1.80

func ValidChannelTag(tag string) bool

ValidChannelTag reports whether tag is a supported canonical release tag.

func ValidVersion added in v0.1.15

func ValidVersion(v string) bool

ValidVersion reports whether v may be a manifest's version.

func VerifyFile

func VerifyFile(f File, r io.Reader) error

VerifyFile reads r to the end and compares size and SHA-256 with the manifest entry.

func WranglerDevName added in v0.1.41

func WranglerDevName(role string) string

func WranglerExampleName added in v0.1.41

func WranglerExampleName(role string) string

WranglerExampleName and WranglerDevName are the file names of a role's config in edge/worker: the committed one with the placeholder id, and the git-ignored copy a local run makes from it.

func WriteEdgeBundle added in v0.1.36

func WriteEdgeBundle(w io.Writer, in EdgeInputs) error

WriteEdgeBundle writes the deterministic tarball: entries sorted by path, mode 0644 (directories 0755), uid and gid 0 with no names, mtime 0, gzip with no name and mtime 0. The same inputs give the same bytes on every machine and run.

Types

type Channel added in v0.1.80

type Channel string

Channel is the release cadence represented by a release tag.

const (
	ChannelStable  Channel = "stable"
	ChannelTesting Channel = "testing"
	ChannelDev     Channel = "dev"
)

func ChannelOf added in v0.1.80

func ChannelOf(tag string) (Channel, bool)

ChannelOf returns the channel encoded by a canonical Mistgate release tag. Only vX.Y.Z, vX.Y.Z-testing.N and vX.Y.Z-dev.N are release tags; N starts at 1 and build metadata is not accepted.

func ParseChannel added in v0.1.80

func ParseChannel(value string) (Channel, bool)

ParseChannel parses a channel name used in settings and API requests.

func (Channel) Allows added in v0.1.80

func (c Channel) Allows(releaseChannel Channel) bool

Allows reports whether a panel on c may see releases from releaseChannel. A channel sees itself and every more stable channel: stable < testing < dev.

func (Channel) Valid added in v0.1.80

func (c Channel) Valid() bool

Valid reports whether c is one of the supported release channels.

type EdgeAssets added in v0.1.36

type EdgeAssets struct {
	Directory string `json:"directory"`
	Binding   string `json:"binding"`
}

EdgeAssets is the static assets binding of a script; Directory is a folder of the tarball. The public and the admin role point at the same folder.

type EdgeBinding added in v0.1.36

type EdgeBinding struct {
	Binding string `json:"binding"`
}

EdgeBinding is a binding that is only a name (the D1 database it points at is the deployer's).

type EdgeConfig added in v0.1.36

type EdgeConfig struct {
	Schema             int          `json:"schema"`
	Version            string       `json:"version"`
	CompatibilityDate  string       `json:"compatibility_date"`
	CompatibilityFlags []string     `json:"compatibility_flags"`
	Scripts            []EdgeScript `json:"scripts"`
}

EdgeConfig is edge.json, the first entry of the tarball: what a deployer needs to upload the scripts without reading the wrangler configs. Scripts is in EdgeRoles order. The wrangler dev configs are generated from NewEdgeConfig, so this is the one description of the bindings.

func NewEdgeConfig added in v0.1.36

func NewEdgeConfig(version string) EdgeConfig

NewEdgeConfig is edge.json for a version. TestEdgeConfigBindings holds it to the TypeScript side: the bindings each script reads (edge/worker/src/env.ts, roles/*.ts, front.ts).

func ParseEdgeConfig added in v0.1.41

func ParseEdgeConfig(b []byte) (*EdgeConfig, error)

ParseEdgeConfig decodes edge.json strictly and validates it. A schema other than EdgeSchema is ErrEdgeSchema with a message that says what to do: schema 1 is the single-Worker bundle, which no install runs on and nothing reads any more.

func (EdgeConfig) CheckFiles added in v0.1.41

func (c EdgeConfig) CheckFiles(files map[string][]byte) error

CheckFiles compares the files ReadEdgeBundle returned with the config: every module of every script is there and not empty, and nothing else is but edge.json and the assets (a file the config does not name is never uploaded, so it must not be signed in).

func (EdgeConfig) Marshal added in v0.1.36

func (c EdgeConfig) Marshal() ([]byte, error)

Marshal encodes edge.json.

func (EdgeConfig) Script added in v0.1.41

func (c EdgeConfig) Script(role string) *EdgeScript

Script returns the script of a role, or nil.

func (EdgeConfig) Validate added in v0.1.41

func (c EdgeConfig) Validate() error

Validate checks that edge.json describes a bundle that can be deployed: every role once and in upload order, no binding to a role or a class that does not exist, no two bindings of one name in a script, a migration for every class a script owns and for nothing else, and modules named after the role. It checks the references, not the values (the tests hold NewEdgeConfig to those).

func (EdgeConfig) WranglerConfig added in v0.1.41

func (c EdgeConfig) WranglerConfig(role string) string

WranglerConfig renders the wrangler.toml of one role, with the D1 placeholder. Paths are relative to edge/worker; the assets directory is web/dist (build it first).

func (EdgeConfig) WranglerFiles added in v0.1.41

func (c EdgeConfig) WranglerFiles() map[string]string

WranglerFiles renders the committed config of every role, by file name.

type EdgeDO added in v0.1.36

type EdgeDO struct {
	Binding    string `json:"binding"`
	ClassName  string `json:"class_name"`
	ScriptRole string `json:"script_role,omitempty"`
}

EdgeDO is a Durable Object binding. ScriptRole is set on an object that belongs to the other script.

type EdgeInputs added in v0.1.36

type EdgeInputs struct {
	Version    string
	ModulesDir string
	AssetsDir  string
}

EdgeInputs are the built parts of a bundle. ModulesDir holds every module file the config names (front.js, link.js, link.wasm ... directly in it); AssetsDir is web/dist.

type EdgeManifest added in v0.1.36

type EdgeManifest struct {
	Version string `json:"version"`
	Built   int64  `json:"built"`   // Unix time of the source commit
	Expires int64  `json:"expires"` // Unix seconds; bounds how long a captured manifest stays usable
	File    string `json:"file"`    // always EdgeBundleName
	Size    int64  `json:"size"`
	SHA256  string `json:"sha256"` // lowercase hex of the tarball
}

EdgeManifest is what the owner signs for the edge bundle. Built and Expires follow the panel manifest's conventions.

func EdgeManifestFor added in v0.1.36

func EdgeManifestFor(path, version string, built, expires int64) (*EdgeManifest, error)

EdgeManifestFor hashes the tarball at path and builds its manifest.

func ParseEdge added in v0.1.36

func ParseEdge(b []byte) (*EdgeManifest, error)

ParseEdge decodes and validates edge manifest bytes. It is strict (an unknown field or trailing data is ErrBadManifest). Verify the signature first (or use VerifyEdge): ParseEdge alone trusts nothing.

func VerifyEdge added in v0.1.36

func VerifyEdge(pub ed25519.PublicKey, manifest, sig []byte) (*EdgeManifest, error)

VerifyEdge checks the signature over the exact manifest bytes and then parses them. A panel or node signature of the same bytes does not verify here, and an edge signature does not verify as theirs.

func (*EdgeManifest) Check added in v0.1.36

func (m *EdgeManifest) Check(now time.Time) error

Check is ErrExpired once the manifest's lifetime is over. Ordering by Built is the caller's business: a deploy of an older edge is an operator's choice, not an attack on a node.

func (*EdgeManifest) Marshal added in v0.1.36

func (m *EdgeManifest) Marshal() ([]byte, error)

Marshal validates and encodes the manifest: the bytes that get signed and written to edge-manifest.json.

func (*EdgeManifest) Validate added in v0.1.36

func (m *EdgeManifest) Validate() error

Validate checks the manifest is well formed. It says nothing about time (see Check).

func (*EdgeManifest) VerifyFile added in v0.1.36

func (m *EdgeManifest) VerifyFile(r io.Reader) error

VerifyFile reads r (the tarball) to the end and compares size and SHA-256 with the manifest.

type EdgeMigrate added in v0.1.36

type EdgeMigrate struct {
	Tag              string   `json:"tag"`
	NewSqliteClasses []string `json:"new_sqlite_classes"`
}

EdgeMigrate is one [[migrations]] step.

type EdgeModule added in v0.1.36

type EdgeModule struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

EdgeModule is a file of the tarball uploaded as a module of the script. Type is "esm" or "compiled_wasm".

type EdgeScript added in v0.1.36

type EdgeScript struct {
	Role            string        `json:"role"` // one of EdgeRoles
	DefaultName     string        `json:"default_name"`
	MainModule      string        `json:"main_module"`
	Modules         []EdgeModule  `json:"modules"`
	DurableObjects  []EdgeDO      `json:"durable_objects,omitempty"`          // classes this script owns
	ExternalObjects []EdgeDO      `json:"durable_objects_external,omitempty"` // classes of another script (script_role)
	Migrations      []EdgeMigrate `json:"migrations,omitempty"`
	D1              []EdgeBinding `json:"d1"`
	Services        []EdgeService `json:"services,omitempty"`
	Assets          *EdgeAssets   `json:"assets,omitempty"`
	Secrets         []string      `json:"secrets,omitempty"`
	Vars            []string      `json:"vars,omitempty"`
	Cron            []string      `json:"cron,omitempty"`
	Routes          bool          `json:"routes"` // takes the routes or the custom domain of the install
}

EdgeScript is one Worker script of the bundle.

type EdgeService added in v0.1.41

type EdgeService struct {
	Binding     string `json:"binding"`
	ServiceRole string `json:"service_role"`
	Entrypoint  string `json:"entrypoint,omitempty"`
}

EdgeService is a service binding to the Worker of another role; Entrypoint names a WorkerEntrypoint class of it.

type File

type File struct {
	OS     string `json:"os"`
	Arch   string `json:"arch"`
	Name   string `json:"name"`
	Size   int64  `json:"size"`
	SHA256 string `json:"sha256"` // lowercase hex
}

File is one binary of a release.

func FileFromPath

func FileFromPath(path string) (File, error)

FileFromPath hashes a binary and builds its manifest entry; os and arch come from the file name (ParseBinaryName), so the name must be "<name>-<os>-<arch>".

type Manifest

type Manifest struct {
	Schema  int    `json:"schema"`
	Version string `json:"version"`
	Built   int64  `json:"built"`
	Expires int64  `json:"expires"` // Unix seconds; bounds how long a captured manifest stays usable
	Files   []File `json:"files"`
}

Manifest is what the owner signs. Built (Unix time of the source commit), not Version, orders releases.

func Parse

func Parse(b []byte) (*Manifest, error)

Parse decodes and validates manifest bytes. It is strict: an unknown field, trailing data or a schema other than 1 is ErrBadManifest, because a signed manifest must be understood completely or not at all. Verify the signature first (or use Verify): Parse alone trusts nothing.

func Verify

func Verify(pub ed25519.PublicKey, manifest, sig []byte) (*Manifest, error)

Verify checks the signature over the exact manifest bytes and then parses them. A manifest whose signature fails is never parsed.

func VerifyPanel added in v0.1.15

func VerifyPanel(pub ed25519.PublicKey, manifest, sig []byte) (*Manifest, error)

VerifyPanel is Verify for a panel manifest.

func VerifyPanelSSHSIG added in v0.1.34

func VerifyPanelSSHSIG(pub ed25519.PublicKey, manifest, armored []byte) (*Manifest, error)

VerifyPanelSSHSIG verifies an armored SSHSIG signature and parses its panel manifest.

func (*Manifest) Check

func (m *Manifest) Check(now time.Time, ownBuilt int64) error

Check decides whether a manifest may be installed by a build whose Built is ownBuilt, at time now: ErrExpired, ErrFutureBuilt (Built more than MaxBuiltSkew ahead of now), ErrDowngrade (older), ErrUpToDate (same, a no-op that is not an error for the caller), else nil (newer).

func (*Manifest) FileFor

func (m *Manifest) FileFor(goos, goarch string) (File, error)

FileFor picks the file for a platform (runtime.GOOS, runtime.GOARCH).

func (*Manifest) FindName

func (m *Manifest) FindName(name string) (File, bool)

FindName returns the listed file with this exact name (the panel uses it to serve downloads).

func (*Manifest) Marshal

func (m *Manifest) Marshal() ([]byte, error)

Marshal validates and encodes the manifest: the bytes that get signed and written to manifest.json.

func (*Manifest) Validate

func (m *Manifest) Validate() error

Validate checks the manifest is well formed. It says nothing about time or about the running build (see Check).

Jump to

Keyboard shortcuts

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