Documentation
¶
Index ¶
- Variables
- func Run(cfg Config, hooks Hooks) error
- func Serve(parent context.Context, cfg Config, hooks Hooks) error
- func UseFilesystem(ctx *Context, cap Capability, fn func(FilesystemBroker) error) error
- func UseNetwork(ctx *Context, fn func(NetworkBroker) error) error
- func UseSecrets(ctx *Context, fn func(SecretsBroker) error) error
- type Broker
- type Capability
- type CapabilityError
- type CapabilitySet
- type Config
- type Context
- type FakeAuditEntry
- type FakeBroker
- func (b *FakeBroker) AuditLog() []FakeAuditEntry
- func (b *FakeBroker) DenyFilesystem(path, reason string)
- func (b *FakeBroker) DenyNetwork(method, url, reason string)
- func (b *FakeBroker) DenySecret(name, reason string)
- func (b *FakeBroker) Filesystem() FilesystemBroker
- func (b *FakeBroker) Network() NetworkBroker
- func (b *FakeBroker) Requests() []HTTPRequest
- func (b *FakeBroker) Secrets() SecretsBroker
- func (b *FakeBroker) SetFile(path string, data []byte)
- func (b *FakeBroker) SetHTTPResponse(method, url string, res HTTPResult)
- func (b *FakeBroker) SetSecret(name, value string)
- type FilesystemBroker
- type Finding
- type HTTPPassiveEvent
- type HTTPPassiveHook
- type HTTPRequest
- type HTTPResponse
- type HTTPResult
- type Hooks
- type LocalRunConfig
- type LocalRunResult
- type NetworkBroker
- type OnStartHook
- type SecretsBroker
- type Severity
- type Subscription
Constants ¶
This section is empty.
Variables ¶
ErrBrokerUnavailable is returned when a broker endpoint is not configured.
var ErrNotFound = errors.New("resource not found")
ErrNotFound signals that the requested resource was not found by the broker.
Functions ¶
func Run ¶
Run is a convenience helper that handles system interrupts and blocks until Serve returns.
func Serve ¶
Serve launches the plugin runtime and blocks until the context is cancelled or an error occurs.
func UseFilesystem ¶
func UseFilesystem(ctx *Context, cap Capability, fn func(FilesystemBroker) error) error
UseFilesystem executes fn with the filesystem broker after verifying capability.
func UseNetwork ¶
func UseNetwork(ctx *Context, fn func(NetworkBroker) error) error
UseNetwork executes fn with the network broker after verifying CAP_NET_OUTBOUND.
func UseSecrets ¶
func UseSecrets(ctx *Context, fn func(SecretsBroker) error) error
UseSecrets executes fn with the secrets broker after verifying CAP_SECRETS_READ.
Types ¶
type Broker ¶
type Broker interface {
Filesystem() FilesystemBroker
Network() NetworkBroker
Secrets() SecretsBroker
}
Broker exposes sandbox-safe helpers implemented by the 0xgen broker.
type Capability ¶
type Capability string
Capability represents a permission that must be granted to the plugin by the host before certain operations are allowed.
const ( // CapabilityEmitFindings allows the plugin to report findings to the host. CapabilityEmitFindings Capability = "CAP_EMIT_FINDINGS" // CapabilityHTTPPassive allows the plugin to receive passive HTTP events. CapabilityHTTPPassive Capability = "CAP_HTTP_PASSIVE" // CapabilityAIAnalysis allows the plugin to access the AI-assisted analysis surface. CapabilityAIAnalysis Capability = "CAP_AI_ANALYSIS" // CapabilityFlowInspect grants access to sanitized HTTP flow events. CapabilityFlowInspect Capability = "CAP_FLOW_INSPECT" // CapabilityFlowInspectRaw grants access to raw HTTP flow events. CapabilityFlowInspectRaw Capability = "CAP_FLOW_INSPECT_RAW" // CapabilityWorkspaceRead allows the plugin to read from its allocated workspace. CapabilityWorkspaceRead Capability = "CAP_WORKSPACE_READ" // CapabilityWorkspaceWrite allows the plugin to write to its allocated workspace. CapabilityWorkspaceWrite Capability = "CAP_WORKSPACE_WRITE" // CapabilityNetOutbound allows the plugin to make outbound network requests via the broker. CapabilityNetOutbound Capability = "CAP_NET_OUTBOUND" // CapabilitySecretsRead allows the plugin to retrieve secrets from the broker. CapabilitySecretsRead Capability = "CAP_SECRETS_READ" )
type CapabilityError ¶
type CapabilityError struct {
Capability Capability
}
CapabilityError indicates a capability is missing for the requested action.
func (CapabilityError) Error ¶
func (e CapabilityError) Error() string
type CapabilitySet ¶
type CapabilitySet struct {
EmitFindings bool
HTTPPassive bool
AIAnalysis bool
FlowInspect bool
FlowInspectRaw bool
WorkspaceRead bool
WorkspaceWrite bool
NetOutbound bool
SecretsRead bool
}
CapabilitySet centralises capability declarations for plugin scaffolds.
func (CapabilitySet) Enabled ¶
func (s CapabilitySet) Enabled(cap Capability) bool
Enabled reports whether the provided capability is present in the set.
func (CapabilitySet) List ¶
func (s CapabilitySet) List() []Capability
List returns the enabled capabilities as a slice suitable for manifests or configs.
type Config ¶
type Config struct {
// PluginName is the name reported to the host. It should match the manifest.
PluginName string
// Host is the host:port combination to dial the 0xgen core.
Host string
// AuthToken is the shared secret required by the host.
AuthToken string
// CapabilityToken binds this invocation to the capabilities granted by the host.
CapabilityToken string
// SecretsToken authorises this invocation to retrieve secrets from the broker.
SecretsToken string
// SecretsScope binds the secrets token to the specific plugin run scope. If left blank
// the capability token is used as a fallback.
SecretsScope string
// Capabilities is the set of capabilities granted by the manifest.
Capabilities []Capability
// Subscriptions lists the host events the plugin wants to receive.
Subscriptions []Subscription
// Logger allows callers to customise logging output. A sensible default is used otherwise.
Logger *slog.Logger
// Broker injects broker helpers for filesystem, network, and secrets access.
Broker Broker
}
Config encapsulates the runtime configuration for a plugin instance.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
func (*Context) CapabilityGranted ¶
func (c *Context) CapabilityGranted(cap Capability) bool
CapabilityGranted reports whether the capability is present on the context.
func (*Context) EmitFinding ¶
EmitFinding reports a finding to the host if the plugin has the required capability.
func (*Context) WithCapability ¶
func (c *Context) WithCapability(cap Capability, fn func(Broker) error) error
WithCapability ensures the provided capability is available before invoking fn.
type FakeAuditEntry ¶
FakeAuditEntry captures a broker operation and whether it was allowed.
type FakeBroker ¶
type FakeBroker struct {
// contains filtered or unexported fields
}
FakeBroker implements Broker for tests and local development.
func NewFakeBroker ¶
func NewFakeBroker() *FakeBroker
NewFakeBroker creates a FakeBroker with empty storage.
func (*FakeBroker) AuditLog ¶
func (b *FakeBroker) AuditLog() []FakeAuditEntry
AuditLog returns the recorded broker interactions.
func (*FakeBroker) DenyFilesystem ¶
func (b *FakeBroker) DenyFilesystem(path, reason string)
DenyFilesystem configures a denial for a specific path. Provide an empty path to reject all filesystem operations.
func (*FakeBroker) DenyNetwork ¶
func (b *FakeBroker) DenyNetwork(method, url, reason string)
DenyNetwork configures a denial for a given method and URL.
func (*FakeBroker) DenySecret ¶
func (b *FakeBroker) DenySecret(name, reason string)
DenySecret configures a denial for a named secret.
func (*FakeBroker) Filesystem ¶
func (b *FakeBroker) Filesystem() FilesystemBroker
Filesystem implements Broker.
func (*FakeBroker) Network ¶
func (b *FakeBroker) Network() NetworkBroker
Network implements Broker.
func (*FakeBroker) Requests ¶
func (b *FakeBroker) Requests() []HTTPRequest
Requests returns a snapshot of recorded HTTP requests.
func (*FakeBroker) Secrets ¶
func (b *FakeBroker) Secrets() SecretsBroker
Secrets implements Broker.
func (*FakeBroker) SetFile ¶
func (b *FakeBroker) SetFile(path string, data []byte)
SetFile seeds the fake filesystem.
func (*FakeBroker) SetHTTPResponse ¶
func (b *FakeBroker) SetHTTPResponse(method, url string, res HTTPResult)
SetHTTPResponse configures a canned response for the given URL and method.
func (*FakeBroker) SetSecret ¶
func (b *FakeBroker) SetSecret(name, value string)
SetSecret seeds the fake secret store.
type FilesystemBroker ¶
type FilesystemBroker interface {
ReadFile(ctx context.Context, path string) ([]byte, error)
WriteFile(ctx context.Context, path string, data []byte) error
Remove(ctx context.Context, path string) error
}
FilesystemBroker offers workspace-scoped filesystem helpers.
type Finding ¶
type Finding struct {
ID string
Type string
Message string
Target string
Evidence string
Severity Severity
Metadata map[string]string
DetectedAt time.Time
}
Finding captures the structured data that will be sent back to the host when the plugin observes an issue.
type HTTPPassiveEvent ¶
type HTTPPassiveEvent struct {
Raw []byte
Response *HTTPResponse
}
HTTPPassiveEvent wraps a passive HTTP response observed by the plugin.
type HTTPPassiveHook ¶
type HTTPPassiveHook func(ctx *Context, event HTTPPassiveEvent) error
HTTPPassiveHook handles passive HTTP response events streamed from the host.
type HTTPRequest ¶
HTTPRequest models an outbound HTTP request performed by the broker.
type HTTPResponse ¶
HTTPResponse summarises an HTTP response derived from a passive flow event.
type HTTPResult ¶
HTTPResult captures the result of a broker-mediated HTTP request.
type Hooks ¶
type Hooks struct {
OnStart OnStartHook
OnHTTPPassive HTTPPassiveHook
}
Hooks contains the callbacks provided by a plugin implementation.
type LocalRunConfig ¶
type LocalRunConfig struct {
PluginName string
Capabilities []Capability
Broker Broker
Logger *slog.Logger
Hooks Hooks
PassiveEvents []HTTPPassiveEvent
}
LocalRunConfig configures the local integration test harness.
type LocalRunResult ¶
type LocalRunResult struct {
Findings []Finding
}
LocalRunResult captures the results emitted by the plugin during a local run.
func RunLocal ¶
func RunLocal(ctx context.Context, cfg LocalRunConfig) (*LocalRunResult, error)
RunLocal executes the plugin hooks without connecting to a real 0xgen host.
type NetworkBroker ¶
type NetworkBroker interface {
Do(ctx context.Context, req HTTPRequest) (HTTPResult, error)
}
NetworkBroker mediates outbound HTTP requests through the broker.
type OnStartHook ¶
OnStartHook is invoked once after the plugin successfully connects to the host.
type SecretsBroker ¶
SecretsBroker retrieves secret material from the broker.
type Severity ¶
Severity describes how serious a finding is considered by the plugin.
const ( SeverityInfo Severity = Severity(pb.Severity_INFO) SeverityLow Severity = Severity(pb.Severity_LOW) SeverityMedium Severity = Severity(pb.Severity_MEDIUM) SeverityHigh Severity = Severity(pb.Severity_HIGH) SeverityCritical Severity = Severity(pb.Severity_CRITICAL) )
type Subscription ¶
type Subscription string
Subscription identifies the type of host events a plugin is interested in.
const ( // SubscriptionFlowResponse subscribes to HTTP response flow events from the host. SubscriptionFlowResponse Subscription = "FLOW_RESPONSE" // SubscriptionFlowRequest subscribes to sanitized HTTP request flow events from the host. SubscriptionFlowRequest Subscription = "FLOW_REQUEST" // SubscriptionFlowResponseRaw subscribes to raw HTTP response flow events. SubscriptionFlowResponseRaw Subscription = "FLOW_RESPONSE_RAW" // SubscriptionFlowRequestRaw subscribes to raw HTTP request flow events. SubscriptionFlowRequestRaw Subscription = "FLOW_REQUEST_RAW" )