CLI-based, env-configured, cache-less engines resolving SecretRef values through the existing Yaegi plugin surface. Fresh resolve per call, so values updated in the backend are picked up without daemon restart — closing the gap that motivated the remote secret-input epic (#504), whose value-entry web form duplicated the Bitwarden app for bws. - examples/secret-engines/: sops (SOPS_FILE), vault (VAULT_ADDR/TOKEN, key "path/field" or VAULT_SECRET_PATH prefix), age (AGE_FILE/ AGE_IDENTITY, key=value lines). //go:build ignore keeps them out of the Go toolchain; yaegi treats the tag as a comment and loads them. - enginehost: host-side Run helper registered as a Yaegi symbol. yaegi's interpreted os/exec cannot pass env to child processes, so plugins shell out through host code; bounded by a 30s timeout like the bws engine. - secret.LoadDir seeds the interpreter with the host environment: yaegi's interpreted os package keeps a private env otherwise, and plugin os.Getenv would silently see nothing. - cmd/archied wires enginehost + unrestricted symbols into the engine plugin loader, matching skillscript's interpretation posture. - tests load the real shipped plugin files with fake CLIs on PATH; added CONTEXT.md glossary for the remote secret-input vocabulary.
55 lines
2.0 KiB
Go
55 lines
2.0 KiB
Go
// Package enginehost provides host-side helpers for interpreted secret
|
|
// engine plugins.
|
|
//
|
|
// Yaegi's interpreted os/exec is sandboxed: child processes cannot be
|
|
// given an environment, and env vars set or read in interpreted code do
|
|
// not reach the host or the child. Secret engines need real command
|
|
// execution with the daemon's environment (vault requires VAULT_ADDR and
|
|
// VAULT_TOKEN in the child env), so plugins shell out through Run instead
|
|
// of importing os/exec. This mirrors how the compiled-in bws engine runs
|
|
// the bws CLI, but host-side where env behaves.
|
|
package enginehost
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"os/exec"
|
|
"reflect"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
// runTimeout bounds a CLI invocation, mirroring the compiled-in bws
|
|
// engine's bwsTimeout: a hung engine binary must not block secret
|
|
// resolution forever.
|
|
const runTimeout = 30 * time.Second
|
|
|
|
// Run executes name with args in the host process, inheriting the full
|
|
// host environment, and returns the trimmed stdout. Stderr is discarded,
|
|
// matching the compiled-in bws engine. A non-zero exit is returned as an
|
|
// error. The engine Resolve contract carries no context, so the command
|
|
// runs with a bounded timeout rather than a caller-provided context.
|
|
func Run(name string, args []string) (string, error) {
|
|
ctx, cancel := context.WithTimeout(context.Background(), runTimeout)
|
|
defer cancel()
|
|
cmd := exec.CommandContext(ctx, name, args...)
|
|
cmd.Stderr = io.Discard
|
|
out, err := cmd.Output()
|
|
if err != nil {
|
|
return "", fmt.Errorf("run %s: %w", name, err)
|
|
}
|
|
return strings.TrimSpace(string(out)), nil
|
|
}
|
|
|
|
// Symbols is the hand-written Yaegi symbol table exposing Run to
|
|
// interpreted plugins. It is kept separate from the generated
|
|
// secretextract table because regenerating that table would not include
|
|
// this package. The key follows yaegi's convention of import path plus
|
|
// package name (see the generated secretextract file).
|
|
var Symbols = map[string]map[string]reflect.Value{
|
|
"github.com/samcharles93/archie-core/internal/secret/enginehost/enginehost": {
|
|
"Run": reflect.ValueOf(Run),
|
|
},
|
|
}
|