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
- Variables
- func Code(err error) string
- func DecodePrivateKey(s string) (ed25519.PrivateKey, error)
- func EncodePrivateKey(priv ed25519.PrivateKey) string
- func EncodePublicKey(pub ed25519.PublicKey) string
- func GenerateKey() (ed25519.PublicKey, ed25519.PrivateKey, error)
- func ParseBinaryName(name string) (base, goos, goarch string, err error)
- func Sign(priv ed25519.PrivateKey, manifest []byte) []byte
- func VerifyFile(f File, r io.Reader) error
- type File
- type Manifest
Constants ¶
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" // MaxManifestBytes bounds what a parser will read (the panel sends it inside a command). MaxManifestBytes = 64 << 10 )
Variables ¶
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 ¶
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 ¶
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 ¶
ParseBinaryName splits "mistgate-node-linux-amd64" into ("mistgate-node", "linux", "amd64").
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 ¶
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 ¶
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 ¶
Verify checks the signature over the exact manifest bytes and then parses them. A manifest whose signature fails is never parsed.
func (*Manifest) Check ¶
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) FindName ¶
FindName returns the listed file with this exact name (the panel uses it to serve downloads).