Plugin provider extensions
Lua plugin providers let fnox connect its common secret interface to a custom backend without adding that backend to the built-in provider set. A plugin supplies Lua hooks for reading, storing, or encrypting values, while fnox manages provider selection, plugin loading, capability checks, and errors.
This page extends Secret provider integrations with the custom-provider path. See Cloud and vault providers and Local and hardware providers for the built-in provider families that plugins can complement.
Plugin provider model
The Lua provider is a provider adapter whose behavior comes from a plugin entry file. A plugin is a provider.lua file that returns a table of hooks. The required get hook reads one reference; optional hooks add batch reads, remote storage, encryption, and connection checks.
The provider receives a context table for each hook. It contains the configured provider name, the plugin directory, and resolved string options. This keeps backend-specific settings and local plugin resources separate from fnox's shared provider contract.
| Hook | Role | Provider effect |
|---|---|---|
get | Read one secret reference | Required for every plugin |
get_batch | Read unique references in one call | Speeds up multi-secret reads when supported |
put | Store a value and return its reference | Makes the provider a remote store |
encrypt | Return protected text | Makes the provider an encryption provider |
test | Check backend access | Supports provider connection tests |
The provider uses a clear capability rule. encrypt takes priority over put; if neither exists, the provider is read-only. This rule tells fnox whether set should write ciphertext, save to the backend, or reject the store operation rather than placing the secret in project configuration.
References: crates/…/mod.rs• L1-18 crates/…/mod.rs• L409-501 docs/…/lua.md• L91-111
Plugin discovery and registration
Plugin discovery starts with the plugin value in a Lua provider definition. fnox treats a value that looks like a file or directory path as a local plugin. Any other value is an installed plugin name. Local paths resolve from the configuration file that defines the provider, so the same provider works when invoked from a child directory.
Installed plugin names are resolved through the shared [plugins] declarations. A declaration supplies the source that fnox can use for first-use installation. The provider registry passes the declaration into the Lua provider, which then checks or installs the named plugin before it loads the entry file.
This diagram shows how provider configuration becomes a loaded plugin source.
flowchart TD
A[Lua provider configuration] --> B{plugin value is a path?}
B -->|Yes| C[Resolve path from defining config file]
B -->|No| D[Use installed plugin name]
D --> E{Plugin exists in shared plugin store?}
E -->|No| F[Install from matching plugins declaration]
E -->|Yes| G[Check installed source against declaration]
F --> H[Find provider.lua]
G --> H
C --> H
H --> I[Load Lua provider runtime]
The installed store is shared by projects on the machine. fnox records the source used for an installed plugin and refuses to use it when the current project declares a different source or ref. A linked plugin is the deliberate local override and takes precedence over the declaration.
References: crates/…/mod.rs• L38-77 crates/…/mod.rs• L140-171 crates/…/mod.rs• L497-511 crates/…/plugins.rs• L283-309 crates/…/plugins.rs• L508-544
Host API boundary
The host API is the controlled bridge between Lua code and fnox services. fnox registers the host modules before it runs the plugin, while the plugin can load its own Lua modules from the plugin directory and its lib directory.
| Module | Purpose |
|---|---|
fnox | Report an authentication failure and read the fnox version |
fnox.http | Send HTTP requests and receive status, headers, and body data |
| fnox.json | Encode and decode JSON values |
fnox.cmd | Run a command and either inspect or require a successful result |
| fnox.log | Write messages to fnox's log at standard log levels |
fnox.base64 | Encode and decode base64 data |
The boundary also gives plugins a standard error path. fnox.auth_error marks a backend login problem as an authentication failure, so fnox can present the provider's authentication help. Other Lua errors become provider or plugin errors with the hook name and message.
References: crates/…/host.rs• L1-8 crates/…/host.rs• L17-39 crates/…/host.rs• L77-147 crates/…/host.rs• L266-302 crates/…/host.rs• L397-430 crates/…/mod.rs• L267-284 docs/…/lua.md• L135-148
Loading and execution boundaries
fnox loads a plugin into a Lua runtime only when the provider needs it. The entry file must return a hook table with a function-valued get hook. fnox validates optional hook types during load, creates the shared context, and keeps the runtime with the hook table for later calls.
Each provider operation crosses a defined boundary:
- Secret reads call
get, or useget_batchwhen the plugin provides it. - Writes use
encryptfirst, thenput, and fail for a read-only plugin. - Connection tests call
testwhen it exists and otherwise succeed after load. - A missing value is represented by
niland becomes fnox's provider-not-found result.
This diagram shows the execution path from a fnox operation to a plugin result.
sequenceDiagram
participant F as fnox provider flow
participant L as Lua runtime
participant P as plugin hook
participant B as backend or CLI
F->>L: Load provider.lua and create ctx
L->>P: Validate and retain hook table
F->>P: Call get, get_batch, put, encrypt, or test
P->>B: Use fnox host API or plugin code
B-->>P: Backend result
P-->>F: Value, reference, ciphertext, or error
The runtime boundary protects fnox's provider flow from malformed plugin output. fnox rejects a missing get hook, invalid hook values, and return values of the wrong type. A load failure also prevents a write from silently falling back to plaintext configuration.
References: crates/…/mod.rs• L174-265 crates/…/mod.rs• L295-383 crates/…/mod.rs• L386-406 crates/…/mod.rs• L409-501 test/lua_plugin.bats• L276-291
Plugin lifecycle commands
The fnox plugin command manages the machine-wide plugin store and the local development override. It can use a Git source with an optional tag, branch, or commit ref. A two-part owner/repo source is shorthand for a GitHub repository.
| Command | Lifecycle role |
|---|---|
fnox plugin install | Install all declared plugins that are missing, or install one name from a declared or explicit source |
fnox plugin link | Point a plugin name at a local directory that contains provider.lua |
fnox plugin ls | Show installed and linked plugins, their source or target, and declared-but-missing plugins |
fnox plugin update | Move installed Git plugins to their declared source and ref, or to the current remote default when no declaration exists |
fnox plugin uninstall | Remove an installed or linked plugin from the shared store |
The lifecycle keeps incomplete changes out of the active store. Installation prepares a checkout before moving it into place, and failed replacement or update work restores the prior usable plugin. Updates skip linked plugins because a linked checkout is an active development source rather than a managed Git install.
This diagram shows the normal lifecycle from declaration to removal.
flowchart LR
A[[plugins] declaration] --> B[install]
B --> C[shared installed plugin]
C --> D[ls and provider use]
D --> E[update to declared source or ref]
D --> F[link local checkout]
F --> G[provider uses linked checkout]
C --> H[uninstall]
G --> H
Plugin commands can run without a project configuration. In that case, commands that need a declaration use an explicit source, while listing and removal still operate on the shared store.
References: src/…/plugin.rs• L7-29 src/…/plugin.rs• L31-78 src/…/plugin.rs• L93-111 src/…/plugin.rs• L113-239 crates/…/plugins.rs• L312-370 crates/…/plugins.rs• L373-427 crates/…/plugins.rs• L435-505
Trust and source boundaries
Plugins run with the user's permissions and can use network access or local commands through the host API. The plugin source is therefore part of the provider's trust boundary, not only a package download detail.
Project declarations should pin a trusted tag or commit when repeatable behavior matters. The source check prevents one project from using a plugin installed from a different source, while linking remains an explicit local development choice.
References: docs/…/lua.md• L57-89 crates/…/plugins.rs• L508-544 test/lua_plugin.bats• L245-274
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the
pluginpath-versus-name rule aligned with provider source resolution. A change can make a local file resolve as a shared plugin name or the reverse. - Keep
[plugins]source tracking aligned with install, first-use loading, and update behavior. A mismatch must not run a different plugin with project options. - Keep hook capability precedence aligned across capability reporting and
putexecution.encryptmust remain stronger thanput. - Keep host module names and error mapping aligned with the Lua contract. In particular, preserve the distinction between authentication errors and ordinary hook failures.
- Keep linked plugins outside update replacement. Developers must be able to edit a linked checkout without an update resetting it.
- Keep plugin validation before activation. A missing
provider.lua, malformed hook table, or failed load must not permit a write to fall back to plaintext.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
A plugin name has no installed copy and no [plugins] source | Provider use fails before Lua code runs | Install it explicitly or declare its Git source |
| The installed source or ref differs from the project's declaration | fnox refuses to load the plugin | Run fnox plugin update <name> |
provider.lua is missing or returns no valid get hook | Plugin loading fails | Keep provider.lua at the plugin root and return the required hook table |
A read-only plugin receives set | fnox rejects the write instead of storing through the backend | Add put or encrypt, or pass a reference intended for project storage |
| The plugin raises a normal Lua error | The provider operation fails with the hook error | Return valid values and handle backend errors in the plugin |
The plugin raises fnox.auth_error | fnox reports an authentication failure and may offer auth_command | Re-authenticate with the backend or configure the provider login command |
fnox plugin update targets a linked plugin | The update is skipped | Edit the linked checkout or unlink it before using managed updates |
| A plugin source is unavailable or Git cannot access it | Install or update fails and the current install remains in place | Check the source, ref, Git access, and network path |
Key files
| File | Why to read it |
|---|---|
| crates/…/mod.rs | Defines the Lua provider contract, runtime loading, hook calls, capability mapping, and provider errors. |
| crates/…/host.rs | Defines the host modules available to plugin code and the authentication error boundary. |
| crates/…/plugins.rs | Defines plugin sources, shared installation, linking, source checks, updates, and removal. |
| src/…/plugin.rs | Maps the CLI lifecycle commands to plugin management actions. |
| crates/…/mod.rs | Connects Lua provider configuration to path resolution, declarations, and provider creation. |
| docs/…/lua.md | Gives the plugin author contract, configuration model, and host API examples. |
test/lua_plugin.bats | Shows end-to-end guarantees for discovery, first-use installation, updates, links, errors, and safe failed writes. |