Documentation
¶
Overview ¶
Package plugin discovers and runs out-of-tree Fendix plugins.
A plugin is a directory containing a plugin.yaml manifest and an executable entrypoint. The engine invokes the entrypoint with a JSON ScanRequest on stdin; the entrypoint emits zero or more newline-delimited Finding JSON objects on stdout, terminated by {"done": true, "total": N}. This is the same NDJSON contract the embedded Python engine speaks (ADR-002), so plugin authors writing a Python plugin can share most of the engine.py scaffolding.
Discovery walks two roots in order:
- <repo>/.fendix/plugins/ (repo-local; OPT-IN — see below)
- ~/.fendix/plugins/ (user-global; trusted)
On collision (same plugin name in both roots) the repo-local version wins, so a project can pin a specific plugin version without affecting the developer's other repos.
Repo-local plugins are NOT auto-discovered by default (F-H2): a repository under scan is attacker-controlled in the poisoned- pipeline threat model (a malicious PR can drop a `.fendix/plugins/` directory and get arbitrary code executed in CI). The repo-local root is therefore gated behind explicit opt-in (the AllowRepoLocalPlugins config flag, threaded into Roots). The user-global ~/.fendix/plugins root the operator populated by hand stays trusted and is always searched.
Index ¶
Constants ¶
const DefaultTimeout = 30 * time.Second
DefaultTimeout caps a single plugin invocation when the manifest does not specify a Timeout.
const MaxTimeout = 5 * time.Minute
MaxTimeout is the upper bound on plugin runtime regardless of what the manifest claims. A plugin that wants longer scans should run async and emit findings incrementally; the engine cannot wait forever on a single subprocess.
Variables ¶
This section is empty.
Functions ¶
func DefaultRoots ¶
DefaultRoots returns the canonical plugin search path. The user-global root (~/.fendix/plugins) is always included — the operator populated it by hand, so it's trusted. The repo-local root (<cwd>/.fendix/plugins) is included only when allowRepoLocal is true (F-H2): the scanned repo is attacker-controlled in the poisoned- pipeline threat model, so a `.fendix/plugins/` committed by a hostile PR must not auto-execute in CI. When repo-local is allowed, it's listed first so it shadows a same-named user-global plugin.
cwd is the working directory whose .fendix/plugins should be searched (typically the scan root). If cwd is empty, the repo-local root is omitted regardless of allowRepoLocal. On systems where os.UserHomeDir fails (very rare) the user-global root is silently omitted.
Types ¶
type Mode ¶
type Mode string
Mode declares whether a plugin sees blackbox (URL/spec/auth) or whitebox (code path) inputs. Plugins that need both can declare Mode="hybrid"; the orchestrator will run them once with all fields populated.
type Plugin ¶
type Plugin struct {
Spec
// Dir is the absolute path to the plugin directory. Entrypoint
// is resolved relative to Dir.
Dir string
}
Plugin is a discovered, validated plugin ready to run.
func Discover ¶
Discover walks the given roots in order, parses every plugin.yaml it finds, and returns the resulting Plugin list deduplicated by Name (earlier roots win — pass repo-local first, user-global second; see DefaultRoots). A malformed plugin.yaml in one directory does not stop discovery in others; the error for that directory is logged at WARN level and the plugin is skipped.
Symlinked plugin *directories* are skipped (F-H2): following a symlink lets a directory entry point outside the discovery root — a poisoned repo could symlink its `.fendix/plugins/x` at an attacker-staged tree, and an operator's `~/.fendix/plugins/y` could be redirected by a hostile package. Only real directories are discovered; copy (or `git clone`) a plugin into the root rather than symlinking it.
Discover is intentionally tolerant of missing roots: a fresh install with no plugin directories returns ([], nil), not an error.
func LoadPlugin ¶
LoadPlugin parses plugin.yaml under dir and validates the result. Exported wrapper around loadPlugin so the `fendix plugins install` subcommand (internal/pluginscmd, TASK-130) can validate a freshly- cloned tree without re-implementing the manifest parser.
func (Plugin) Run ¶
Run invokes the plugin entrypoint and returns the findings it emitted. A plugin that exits with non-zero status, takes longer than its timeout, or emits a {"error": ...} terminator returns an error; partial findings collected before the failure are preserved in the slice.
Findings emitted without a Source field are tagged with the plugin's Mode so downstream correlation/dedup treats them consistently with the embedded engines.
type ScanRequest ¶
type ScanRequest struct {
Mode Mode `json:"mode"`
URL string `json:"url,omitempty"`
Spec string `json:"spec,omitempty"`
CodePath string `json:"code_path,omitempty"`
Auth string `json:"auth,omitempty"`
AuthType string `json:"auth_type,omitempty"`
Categories []string `json:"categories,omitempty"`
Verbose bool `json:"verbose"`
}
ScanRequest is the JSON payload the engine sends to a plugin's stdin. It mirrors the embedded engine's ScanRequest plus a Categories field so plugins can filter to relevant work without re-walking the source tree. Field names are stable — adding new fields is fine, removing or renaming them is a breaking change.
type Spec ¶
type Spec struct {
Name string `yaml:"name"`
Version string `yaml:"version,omitempty"`
Description string `yaml:"description,omitempty"`
Entrypoint string `yaml:"entrypoint"`
Mode Mode `yaml:"mode"`
Categories []string `yaml:"categories,omitempty"`
Timeout time.Duration `yaml:"timeout,omitempty"`
// Env is an optional allowlist of extra environment variable names
// the plugin needs passed through from the operator's environment
// (F-I1). By default the runner inherits only a minimal fixed
// allowlist (PATH, HOME, LANG/LC_*, TMPDIR) plus the FENDIX_PLUGIN_*
// vars it sets; a plugin that needs, say, a corporate proxy var can
// name it here. This is the plugin author *requesting* a var — it
// does not grant access the operator hasn't already exported.
// Backwards-compatible: omitting it preserves the minimal default.
Env []string `yaml:"env,omitempty"`
}
Spec is the on-disk plugin.yaml schema. Unknown fields are rejected (yaml.Decoder.KnownFields(true)) so typos surface as errors rather than silently-ignored config — same posture as .fendix.yaml in policy.Load.