extension

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: AGPL-3.0 Imports: 19 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 extension reads, verifies, packs and signs node extension packages (format edgeweir-node-extension-v1). The console checks the same rules before it installs a package (apps/console/src/server/lib/extension-package.ts and packages/contract/src/extensions.ts); the node repeats them before it unpacks anything, so that a package never runs on the console's word alone.

Index

Constants

View Source
const (
	ScopeSite = "site"
	ScopeNode = "node"
)
View Source
const (
	MaxArchiveBytes  = 4 << 20
	MaxUnpackedBytes = 16 << 20
	MaxEntries       = 512
	MaxFileBytes     = 4 << 20
	MaxManifestBytes = 64 << 10
	MaxPathBytes     = 200
	// Packages with a sidecar (extension version 1.1).
	MaxSidecarArchiveBytes  = 64 << 20
	MaxSidecarUnpackedBytes = 192 << 20
	MaxSidecarFileBytes     = 96 << 20
)

Limits of a package (docs/reference/extensions.md).

View Source
const Format = "edgeweir-node-extension-v1"

Format is the only package format this node reads.

View Source
const LuaAPI = 2

LuaAPI is the Lua API version the node provides.

Variables

View Source
var (
	Hooks        = []string{"init", "access", "access_late", "header_filter", "body_filter", "log", "endpoint", "listen"}
	Capabilities = []string{"verdicts", "request_headers", "request_body", "response_headers", "html_inject", "body_rewrite", "http_client", "timers", "sidecar", "early_hints"}
)

Hooks and capabilities (sidecar: Lua API 2).

View Source
var SidecarArchs = []string{"linux-amd64", "linux-arm64"}

SidecarArchs are the architectures a sidecar binary may be shipped for (sidecar/<arch>/<binary>).

Functions

func Compare

func Compare(a, b Version) int

Compare orders versions by Semantic Versioning 2.0.0 precedence.

func Pack

func Pack(files []File) ([]byte, error)

Pack writes a reproducible package of the files below dir's allowed entries: sorted, mtime 0, uid/gid 0, mode 0644 (directories 0755).

func SidecarBinary

func SidecarBinary(m *Manifest, goarch string) string

SidecarBinary returns the path of the sidecar binary for this machine's architecture inside an unpacked package ("" without one).

func Sign

func Sign(archive []byte, key JWK, iat int64) (string, error)

Sign returns the compact JWS of a package for a private JWK.

func Thumbprint

func Thumbprint(x string) string

Thumbprint is the RFC 7638 JWK thumbprint (the kid).

func ValidListenerMethods added in v1.8.0

func ValidListenerMethods(methods []string) bool

ValidListenerMethods checks the non-empty method set shared by declarations and bindings.

func ValidListenerPort added in v1.8.0

func ValidListenerPort(port int) bool

ValidListenerPort excludes privileged ports and the console's port.

Types

type DataLimits

type DataLimits struct {
	MaxBytes      int64 `json:"max_bytes"`
	MaxItems      int   `json:"max_items"`
	MaxTotalBytes int64 `json:"max_total_bytes"`
}

DataLimits bounds an extension's per-site data items.

type Endpoint

type Endpoint struct {
	Path    string   `json:"path"`
	Methods []string `json:"methods"`
	MaxBody *int     `json:"max_body,omitempty"`
}

Endpoint is served at /.edgeweir/ext/<id>/<path>.

type Field

type Field struct {
	Name        string          `json:"name"`
	Type        string          `json:"type"`
	Description json.RawMessage `json:"description,omitempty"`
}

Field is a rule field ext.<id>.<name>.

type File

type File struct {
	Path string
	Data []byte
}

File is one regular file of a package.

func ReadArchive

func ReadArchive(archive []byte) ([]File, error)

ReadArchive parses a package: gzip, then a ustar stream of regular files and directories only.

type JWK

type JWK struct {
	Kty string `json:"kty"`
	Crv string `json:"crv"`
	X   string `json:"x"`
	D   string `json:"d,omitempty"`
}

JWK is an OKP / Ed25519 key; D is set only for private keys.

func (JWK) PublicKey

func (k JWK) PublicKey() (ed25519.PublicKey, error)

PublicKey decodes the key's x.

type Listener added in v1.8.0

type Listener struct {
	Name        string   `json:"name"`
	DefaultPort int      `json:"default_port"`
	Methods     []string `json:"methods"`
	MaxBody     *int     `json:"max_body,omitempty"`
}

Listener is a signed declaration; DefaultPort never opens a listener.

func (Listener) BodyLimit added in v1.8.0

func (l Listener) BodyLimit() int

BodyLimit preserves an explicit zero while defaulting an omitted limit.

type Manifest

type Manifest struct {
	Format       string            `json:"format"`
	ID           string            `json:"id"`
	Version      string            `json:"version"`
	Publisher    string            `json:"publisher"`
	Name         map[string]string `json:"name"`
	Description  map[string]string `json:"description,omitempty"`
	License      string            `json:"license,omitempty"`
	Homepage     string            `json:"homepage,omitempty"`
	Requires     Requires          `json:"requires"`
	Scope        string            `json:"scope,omitempty"`
	Hooks        []string          `json:"hooks"`
	Capabilities []string          `json:"capabilities,omitempty"`
	Config       json.RawMessage   `json:"config,omitempty"`
	Fields       []Field           `json:"fields,omitempty"`
	LogFields    []string          `json:"log_fields,omitempty"`
	Counters     []string          `json:"counters,omitempty"`
	Endpoints    []Endpoint        `json:"endpoints,omitempty"`
	Listeners    []Listener        `json:"listeners,omitempty"`
	SharedDicts  []SharedDict      `json:"shared_dicts,omitempty"`
	// Extension version 1.1 (Lua API 2).
	Secret  bool        `json:"secret,omitempty"`
	Sidecar *Sidecar    `json:"sidecar,omitempty"`
	Data    *DataLimits `json:"data,omitempty"`
}

Manifest is manifest.json. Config schemas stay raw: the console validates them; the node only passes configuration through.

func ParseManifest

func ParseManifest(data []byte) (*Manifest, error)

ParseManifest decodes and validates manifest.json strictly (unknown members are errors).

func ReadManifest

func ReadManifest(files []File) (*Manifest, error)

ReadManifest validates the files of a package and returns its manifest.

func (*Manifest) Has

func (m *Manifest) Has(capability string) bool

Has reports whether the manifest declares a capability.

type Package

type Package struct {
	Manifest *Manifest
	SHA256   string
	Size     int
	KID      string
	Files    []File
}

Package is a verified package.

func Verify

func Verify(archive []byte, jws string, key JWK, publisher string) (*Package, error)

Verify checks a package against its signature and the signing key: signature, digest, size and identity, then the archive and manifest. publisher, when set, must be the key's publisher.

type Payload

type Payload struct {
	Format    string `json:"format"`
	ID        string `json:"id"`
	Version   string `json:"version"`
	Publisher string `json:"publisher"`
	SHA256    string `json:"sha256"`
	Size      int    `json:"size"`
	IAT       int64  `json:"iat"`
}

Payload is the JWS payload of a package signature.

func ParseSignature

func ParseSignature(jws string) (kid string, payload Payload, signingInput string, sig []byte, err error)

ParseSignature splits the JWS and checks its header and payload shape.

type Range

type Range []comparator

Range is a set of comparators that all have to hold.

func ParseRange

func ParseRange(s string) (Range, error)

ParseRange parses space-separated comparators (">=1.7.0 <2.0.0").

func (Range) Contains

func (r Range) Contains(v Version) bool

Contains reports whether v satisfies every comparator.

type Requires

type Requires struct {
	LuaAPI int    `json:"lua_api"`
	Node   string `json:"node,omitempty"`
}

Requires names the Lua API and, optionally, a node version range.

type SharedDict

type SharedDict struct {
	Name   string `json:"name"`
	SizeKB int    `json:"size_kb"`
}

SharedDict is a lua_shared_dict of the extension.

type Sidecar

type Sidecar struct {
	Binary           string            `json:"binary"`
	Args             []string          `json:"args,omitempty"`
	Env              map[string]string `json:"env,omitempty"`
	MemoryMB         int               `json:"memory_mb"`
	TasksMax         int               `json:"tasks_max,omitempty"`
	CPUPercent       int               `json:"cpu_percent,omitempty"`
	HealthPath       string            `json:"health_path,omitempty"`
	ConnectTimeoutMS int               `json:"connect_timeout_ms,omitempty"`
	TimeoutS         int               `json:"timeout_s,omitempty"`
	MaxBody          *int              `json:"max_body,omitempty"`
}

Sidecar is a native helper process the agent runs for the extension.

func (*Sidecar) Normalize

func (s *Sidecar) Normalize()

Defaults of a sidecar's optional fields.

type Version

type Version struct {
	Major, Minor, Patch int
	Pre                 []string
}

Version is a parsed semantic version.

func ParseVersion

func ParseVersion(s string) (Version, error)

ParseVersion parses a semantic version ("v" prefix allowed).

Jump to

Keyboard shortcuts

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