release

package
v0.1.29 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: AGPL-3.0 Imports: 15 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 (
	// 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"
	// MaxManifestBytes bounds what a parser will read (the panel sends it inside a command).
	MaxManifestBytes = 64 << 10
)

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")
	// 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").

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 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 ParseBinaryName

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

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

func Sign

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

Sign returns the detached signature of the manifest bytes.

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 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.

Types

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 (*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, 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