Documentation
¶
Overview ¶
Package wasm provides WebAssembly runtime infrastructure for Reglet plugins. It manages plugin loading, execution, and capability-based sandboxing using wazero.
Index ¶
- type Config
- type ConfigSchema
- type Evidence
- type FieldDef
- type Plugin
- func (p *Plugin) Close() error
- func (p *Plugin) Describe(ctx context.Context) (*PluginInfo, error)
- func (p *Plugin) Name() string
- func (p *Plugin) Observe(ctx context.Context, cfg Config) (*PluginObservationResult, error)
- func (p *Plugin) Schema(ctx context.Context) (*ConfigSchema, error)
- func (p *Plugin) WarmPool(ctx context.Context, count int) (int, error)
- type PluginError
- type PluginInfo
- type PluginObservationResult
- type Runtime
- type RuntimeOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Values map[string]interface{}
}
Config represents plugin configuration Maps to the WIT config record
type ConfigSchema ¶
ConfigSchema represents the JSON Schema for plugin configuration Maps to the WIT config-schema record
type Evidence ¶
Evidence is re-exported from domain for backward compatibility in this package. Use execution.Evidence from domain layer.
type FieldDef ¶
FieldDef represents a configuration field definition Maps to the WIT field-def record
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin manages the lifecycle and execution of a compiled WASM module.
func (*Plugin) Describe ¶
func (p *Plugin) Describe(ctx context.Context) (*PluginInfo, error)
Describe executes the plugin's 'describe' function to retrieve metadata.
func (*Plugin) Schema ¶
func (p *Plugin) Schema(ctx context.Context) (*ConfigSchema, error)
Schema executes the plugin's 'schema' function to retrieve configuration definitions.
type PluginError ¶
type PluginError = execution.PluginError
PluginError is re-exported from domain for backward compatibility in this package. Use execution.PluginError from domain layer.
type PluginInfo ¶
type PluginInfo struct {
Capabilities *entities.GrantSet
Name string
Version string
Description string
}
PluginInfo contains metadata about a plugin Maps to the WIT plugin-info record
type PluginObservationResult ¶
type PluginObservationResult struct {
Evidence *execution.Evidence
Error *execution.PluginError
}
PluginObservationResult is the result of running an observation through a WASM plugin. This is a low-level boundary type.
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime manages WASM execution.
func NewRuntime ¶
NewRuntime creates a runtime with optional configuration. By default, creates a runtime with no capabilities, no redaction, 256MB memory limit, and shared compilation cache.
Example usage:
// Simple case (defaults)
runtime, err := NewRuntime(ctx, version)
// With capabilities and redaction
runtime, err := NewRuntime(ctx, version,
WithCapabilities(caps),
WithRedactor(redactor),
WithMemoryLimit(512),
)
// Test isolation (separate cache)
runtime, err := NewRuntime(ctx, version,
WithCompilationCache(wazero.NewCompilationCache()),
)
func (*Runtime) GetPluginSchema ¶
GetPluginSchema implements config.PluginSchemaProvider. It loads the plugin (if not already loaded) and retrieves its JSON Schema.
func (*Runtime) LoadPlugin ¶
LoadPlugin compiles and caches a plugin, and is safe for concurrent use.
The first call for a given plugin name compiles the provided WASM bytes, creates a Plugin, and stores it in an internal cache keyed by name. Subsequent calls with the same name return the previously cached Plugin instance; the WASM module is not recompiled.
To reduce contention while remaining thread-safe, LoadPlugin uses a double-checked locking pattern around the plugin cache: it first checks the cache under a read lock, and only acquires a write lock if the plugin is not yet present, re-checking the cache under the write lock before compiling. Callers do not need to provide additional synchronization when calling LoadPlugin from multiple goroutines.
type RuntimeOption ¶
type RuntimeOption func(*runtimeConfig)
RuntimeOption configures a Runtime.
func WithCapabilities ¶
func WithCapabilities(caps map[string]*entities.GrantSet) RuntimeOption
WithCapabilities sets the granted capabilities using the SDK GrantSet format.
func WithCompilationCache ¶
func WithCompilationCache(cache wazero.CompilationCache) RuntimeOption
WithCompilationCache provides a custom compilation cache for this runtime. This is useful for:
- Tests: Isolate cache between tests to prevent interference
- Servers: Multiple isolated runtime pools with separate caches
- Advanced use cases: Custom cache lifecycle management
If not provided, uses the default shared cache for the process.
func WithMemoryLimit ¶
func WithMemoryLimit(mb int) RuntimeOption
WithMemoryLimit sets the WASM memory limit in MB. 0 = default (256MB), -1 = unlimited, >0 = explicit limit.
func WithRedactor ¶
func WithRedactor(redactor *sensitivedata.Redactor) RuntimeOption
WithRedactor enables secret redaction for plugin output.