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 HashFile(path string) (int64, string, error)
- func ParseBinaryName(name string) (base, goos, goarch string, err error)
- func ReadEdgeBundle(r io.Reader) (map[string][]byte, error)
- func Sign(priv ed25519.PrivateKey, manifest []byte) []byte
- func SignEdge(priv ed25519.PrivateKey, manifest []byte) []byte
- func SignPanel(priv ed25519.PrivateKey, manifest []byte) []byte
- func SignPanelSSHSIG(priv ed25519.PrivateKey, manifest []byte) ([]byte, error)
- func ValidVersion(v string) bool
- func VerifyFile(f File, r io.Reader) error
- func WriteEdgeBundle(w io.Writer, in EdgeInputs) error
- type EdgeAssets
- type EdgeBinding
- type EdgeConfig
- type EdgeDO
- type EdgeInputs
- type EdgeManifest
- type EdgeMigrate
- type EdgeModule
- type EdgeScript
- type File
- type Manifest
Constants ¶
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. EdgeSchema = 1 // 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: two Worker scripts, the panel as 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.
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 )
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").
func ReadEdgeBundle ¶ added in v0.1.36
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 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 ValidVersion ¶ added in v0.1.15
ValidVersion reports whether v may be a manifest's version.
func VerifyFile ¶
VerifyFile reads r to the end and compares size and SHA-256 with the manifest entry.
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 EdgeAssets ¶ added in v0.1.36
EdgeAssets is the static assets binding of the main script; Directory is a folder of the tarball.
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 templates. The templates in edge/worker stay the source of truth (a test compares them with NewEdgeConfig).
func NewEdgeConfig ¶ added in v0.1.36
func NewEdgeConfig(version string) EdgeConfig
NewEdgeConfig is edge.json for a version. The values mirror edge/worker/wrangler.example.toml (main script) and wrangler.provision.example.toml (Provisioner); TestEdgeConfigMatchesWranglerTemplates fails when they drift apart.
func (EdgeConfig) Marshal ¶ added in v0.1.36
func (c EdgeConfig) Marshal() ([]byte, error)
Marshal encodes edge.json.
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
WorkerJS string
ProvisionJS string
Wasm string
AssetsDir string
}
EdgeInputs are the built parts of a bundle. WorkerJS, ProvisionJS and Wasm are files; 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
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"` // "provision" or "main"
DefaultName string `json:"default_name"`
MainModule string `json:"main_module"`
Modules []EdgeModule `json:"modules"`
DurableObjects []EdgeDO `json:"durable_objects"`
ExternalObjects []EdgeDO `json:"durable_objects_external"`
Migrations []EdgeMigrate `json:"migrations"`
D1 []EdgeBinding `json:"d1"`
Assets *EdgeAssets `json:"assets,omitempty"`
Secrets []string `json:"secrets"`
Vars []string `json:"vars,omitempty"`
Cron []string `json:"cron,omitempty"`
Routes bool `json:"routes"`
}
EdgeScript is one Worker script of the bundle.
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 VerifyPanel ¶ added in v0.1.15
VerifyPanel is Verify for a panel manifest.
func VerifyPanelSSHSIG ¶ added in v0.1.34
VerifyPanelSSHSIG verifies an armored SSHSIG signature and parses its panel manifest.
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).