hashicorp

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 24 Imported by: 2 modules, 1 package

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.

README

HashiCorp plugin backend

github.com/webong/ext/pkg/ext-go/hashicorp is the HashiCorp go-plugin backend of the shared plugin library. It owns the native go-plugin launch handshake and the net/rpc or gRPC client/server bridge.

The shared engine/plugin.Endpoint and engine/plugin.Backend contracts are transport-independent; Go guests and sessions are implementations of those contracts. This backend supplies one transport implementation. It is a separate Go module so consumers that do not need go-plugin never download it.

Guest

Create a plugin.Guest with your descriptor and domain handler, then register it in a native go-plugin server:

guest, err := plugin.NewGuest(descriptor, plugin.GuestOptions{
    Handler: authorizeAndHandle,
})
if err != nil {
    return err
}
goplugin.Serve(&goplugin.ServeConfig{
    HandshakeConfig: hashicorp.HandshakeConfig(),
    Plugins: goplugin.PluginSet{
        hashicorp.PluginName: &hashicorp.Plugin{Guest: guest},
    },
    GRPCServer: hashicorp.GRPCServer,
})

Omit GRPCServer to serve net/rpc. The handler checks domain authorization, honors its context, and supports concurrent calls. Both transports share the same Ext descriptor and request/response validation.

Host

Use plugin.Open with the consumer's trust verifier and per-call authorizer. Inside its Connect callback, create a dedicated goplugin.Client with the same native handshake and hashicorp.Plugin{} in its Plugins map, then call hashicorp.Connect(ctx, client). The supplied runnable example shows the full configuration, including executable checksums and automatic TLS.

Set AllowedProtocols explicitly to ProtocolGRPC or ProtocolNetRPC, and bound StartTimeout to the remaining connection deadline. Configure process environment and logging deliberately: go-plugin's defaults are not Ext's domain policy. The native magic cookie is not an authorization credential.

Connect owns the client lifecycle. Close it when the endpoint closes so the child process is reaped.

Relationship to other modules

Route resolution across backends lives in engine/plugin/interop. The relay between this backend and JSON-line transports remains in engine/plugin/transport/bridge.

See the plugin contract decision record and the interoperability guide.

Source boundaries

The root library imports shared engine/plugin contracts and engine/plugin/interop route metadata; it has no transitive dependency on the engine implementation. JSONLineBridge uses the shared JSON-line capability profile without linking the JSON-line client. Its return type is identical to engine/plugin/interop.Bridge.

The module still requires engine for its example command, guest helpers and test oracles. The ext dispense name, handshake cookie, deadlines and process cleanup behavior are unchanged. This module is a plugin backend for guest execution, not a driver for accessing Ext's canonical C libraries.

Documentation

Overview

Package hashicorp binds Ext's shared plugin endpoint to HashiCorp go-plugin. This library backend owns go-plugin's handshake, RPC bindings, dispensing, and client cleanup. Domain semantics remain in the consumer's plugin.Guest.

Index

Constants

View Source
const PluginName = "ext"

PluginName is the Ext backend dispense key.

Variables

This section is empty.

Functions

func Connect

func Connect(ctx context.Context, client *hc.Client) (plugin.Backend, error)

Connect starts/connects a dedicated go-plugin client and dispenses the Ext interface. Call it inside plugin.Options.Connect, after trust verification. Ownership transfers here: failures kill the client, and the returned backend kills it on Close. Never also supervise that child with the ledger supervisor (pkg/ext-go/cengine/ledger/supervisor). Configure ClientConfig.StartTimeout: cancellation returns promptly, but cleanup of a pending native startup waits for go-plugin's startup to return.

func ConnectCommand

func ConnectCommand(ctx context.Context, command *exec.Cmd, protocol string) (plugin.Backend, error)

ConnectCommand binds an explicitly supplied command to the selected transport. The caller has already verified selection and command/wrapper artifacts. This permits lifecycle wrappers without adding product behavior to the library. Cmd and its streams become go-plugin owned. Never share it across sessions.

func ConnectInterface

func ConnectInterface(ctx context.Context, client *hc.Client, name string, bind func(interface{}) (plugin.Backend, error)) (plugin.Backend, error)

ConnectInterface supports an existing go-plugin interface with a consumer-supplied translation to Backend. The translation owns its domain contract and must honor Backend cancellation and handshake requirements. It shares Connect's dedicated-client ownership and cleanup behavior.

func ConnectProcess

func ConnectProcess(ctx context.Context, p Process) (plugin.Backend, error)

ConnectProcess verifies pinned executable content immediately before starting. The application still verifies provenance and protects immutable paths against replacement. Connect owns cleanup; it is not a process-tree supervisor.

func GRPCProfile

func GRPCProfile() plugin.BackendProfile

func GRPCServer

func GRPCServer(options []grpc.ServerOption) *grpc.Server

GRPCServer is a go-plugin ServeConfig.GRPCServer factory with explicit wire limits. It preserves upstream TLS options. JSON inside BytesValue remains bounded separately to MaxFrameBytes on both sides.

func HandshakeConfig

func HandshakeConfig() hc.HandshakeConfig

HandshakeConfig returns a copy of the backend's native handshake. The cookie identifies a compatible launch convention; it provides no authentication.

func JSONLineBridge

func JSONLineBridge(protocol string) (interop.Bridge, error)

JSONLineBridge declares the mechanics of the supplied stdio bridge. Native streaming/callbacks do not cross it; declared unary/pull-stream contracts do.

func NetRPCProfile

func NetRPCProfile() plugin.BackendProfile

func Serve

func Serve(guest plugin.Endpoint, protocol string) error

Serve serves guest as a go-plugin plugin on this process's stdio and returns when the host disconnects. protocol is "grpc" or "netrpc" and must match what the host allows. Call it once from the plugin's main.

go-plugin owns the handshake and the connection. Its logger is silenced: stdout carries the handshake and stderr is the diagnostic channel, so the guest writes there itself. A plugin author needs no go-plugin or go-hclog import; a program that wants other go-plugin options builds its own hc.ServeConfig from HandshakeConfig, PluginName, Plugin and GRPCServer.

Types

type Plugin

type Plugin struct{ Guest plugin.Endpoint }

Plugin implements both go-plugin bindings. Hosts leave Guest nil; plugins supply a shared Endpoint (a Guest or a verified bridge Relay). Configure AllowedProtocols explicitly on the host and use GRPCServer on the guest to select gRPC. Each dispensed object is a Backend.

func (*Plugin) Client

func (*Plugin) Client(_ *hc.MuxBroker, client *rpc.Client) (interface{}, error)

func (*Plugin) GRPCClient

func (*Plugin) GRPCClient(ctx context.Context, _ *hc.GRPCBroker, conn *grpc.ClientConn) (interface{}, error)

func (*Plugin) GRPCServer

func (p *Plugin) GRPCServer(_ *hc.GRPCBroker, server *grpc.Server) error

func (*Plugin) Server

func (p *Plugin) Server(*hc.MuxBroker) (interface{}, error)

type Process

type Process struct {
	Executable  string   `json:"executable"`
	SHA256      string   `json:"sha256"`
	Protocol    string   `json:"protocol"`
	Arguments   []string `json:"arguments,omitempty"`
	Environment []string `json:"environment,omitempty"`
}

Process is a reviewed launch selection. SHA256 pins bytes, not publisher identity; the application must authenticate this configuration separately. Environment is explicit: the parent environment is not inherited.

func (Process) Validate

func (p Process) Validate() error

func (Process) Verify

func (p Process) Verify() error

Directories

Path Synopsis
cmd
ext-plugin command
ext-plugin inspects portable packages without loading or executing plugins.
ext-plugin inspects portable packages without loading or executing plugins.

Jump to

Keyboard shortcuts

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