Documentation
¶
Overview ¶
Package execverb mounts exec-shaped verbs from a KDL Guardfile: the exec dialect of the spec-driven design. See docs/execverb.md.
Index ¶
- Constants
- func Build(cfg Config) (*cli.Command, error)
- func BuildReplacement(cfg Config) (*cli.Command, error)
- func Identify(w *os.File, gf *Guardfile, version string)
- func InstallFallback(root *cli.Command, gf *Guardfile, fb *Fallback)
- func InstallRefusal(root *cli.Command, gf *Guardfile)
- func Mount(root *cli.Command, cfg Config) error
- func NegativeControls(ctx context.Context, gf *Guardfile) ([]negcontrol.Control, error)
- func Occluded(bin string) (string, []string, error)
- func RefuseRootFlag(gf *Guardfile, err error) error
- func RefuseUngranted(gf *Guardfile, name string) error
- func ResolveReal(bin string) (string, error)
- func ResolveRealExcluding(bin, excludeDir string) (string, error)
- func RootFlagFallback(ctx context.Context, gf *Guardfile, fb *Fallback, err error) error
- type CaptureRunner
- type Config
- type DefaultAllow
- type EmbeddedArg
- type EnvVar
- type Fallback
- type FlagPin
- type GateSpec
- type Grant
- type GrantInfo
- type Guardfile
- type HostResolver
- type NeverRule
- type Runner
- type Surface
- type WhenClause
- type WithheldStub
Constants ¶
const IdentifyEnv = "UMBRA_IDENTIFY"
IdentifyEnv asks a replacement to state what it is and exit. It cannot be a flag: every flag belongs to the tool being occluded.
Variables ¶
This section is empty.
Functions ¶
func Build ¶
Build assembles the guarded command tree and returns the Guardfile group's leaf command (e.g. `git`). Fails closed: a malformed grant is an error.
func BuildReplacement ¶
BuildReplacement builds the guarded tree rooted at the wrapped tool, so a grant is a top-level verb. Refuses a guardfile declaring no `replace`.
func Identify ¶
Identify writes what stands in the wrapped tool's place, the only surface that says umbra is here.
func InstallFallback ¶
InstallFallback sets what happens to an unmounted name: forwarded under default-allow, refused otherwise. Every group, not just the root.
func InstallRefusal ¶
InstallRefusal sets the refusal on root and every group under it: urfave resolves a subcommand against the group that owns it.
func Mount ¶
Mount builds the guarded group and grafts it onto root, generating the intermediate path groups the Guardfile names, mirroring specverb.Mount.
func NegativeControls ¶
NegativeControls invokes every `never run` and `withhold` in gf, spawning nothing, then again with each removed. See docs/negative-controls.md.
func Occluded ¶
Occluded is occlude for a caller outside the runner, such as the audit writer's git lookup: the real bin and the env entries to run it under.
func RefuseRootFlag ¶
RefuseRootFlag answers a flag the root does not define. A replacement registers none of its own, and `--version` is the flag that finds this first.
func RefuseUngranted ¶
RefuseUngranted refuses a verb the guardfile does not grant. It cannot tell a denied verb from a misspelt one, so it says only that the name is not granted.
func ResolveReal ¶
ResolveReal resolves bin to the real binary a replacement stands in front of, skipping the wrapper itself. Fails closed: no survivor means no command runs.
func ResolveRealExcluding ¶
ResolveRealExcluding answers the doctor's question from outside the wrapper: given this shim directory, which binary would the shim reach?
Types ¶
type CaptureRunner ¶
type CaptureRunner func(ctx context.Context, bin string, argv, env []string) (stdout, stderr []byte, exitCode int, err error)
CaptureRunner fires a step command and captures its output (unlike Runner, which streams). err is a spawn failure; a non-zero exit returns exitCode.
type Config ¶
type Config struct {
// Guardfile is the parsed exec-dialect policy.
Guardfile *Guardfile
// Wrap adapts a verb.Spec into a guarded cli.ActionFunc (the audit + argv
// pipeline). nil mounts the bare action, for doc rendering only.
Wrap func(verb.Spec) cli.ActionFunc
// Providers registers the value resolvers a guardfile `env` source names;
// umbra merges its built-ins (env, file, literal). Resolved at exec time.
Providers map[string]valuesource.Provider
// EmbeddedFiles maps each build-time `embed` source to the absolute runtime
// path materialized by umbra. Missing or relative entries fail closed.
EmbeddedFiles map[string]string
// Run fires the command. nil execs for real.
Run Runner
// RunCapture fires an action step and captures its output (the streamed Run
// seam cannot feed step data-flow). nil execs for real. Injected for tests.
RunCapture CaptureRunner
// Host resolves `shell <cmd>` selectors for wrap-level guards. nil execs for
// real (cli/exec). Injected for tests.
Host HostResolver
}
Config is everything the engine needs to build a command tree.
type DefaultAllow ¶
DefaultAllow is the parsed `default-allow` declaration: an unnamed verb is forwarded to the real binary rather than refused. Reason is required.
type EmbeddedArg ¶
EmbeddedArg is one build-time file reference and its fixed position in a grant's argv. Source is relative to the declaring guardfile.
type EnvVar ¶
type EnvVar struct {
Name string
Provider string // value-source provider name (env|file|literal|consumer-registered)
Address string // provider-specific address (SSM path, env var name, literal value)
}
EnvVar is one `env` injection: an environment variable set on the wrapped process, its value resolved at exec time through a provider. See docs/execverb.md.
type Fallback ¶
type Fallback struct {
// contains filtered or unexported fields
}
Fallback forwards an unmatched call to the real binary. Not a hole: the wrap-level guards and env injections a granted leaf faces apply here too.
func NewFallback ¶
NewFallback builds the forwarder. A guardfile declaring no default-allow yields a closed one, which refuses.
type FlagPin ¶
FlagPin fixes one flag's value for a grant: umbra supplies it, and a caller passing a different value is refused. See docs/execverb.md.
type GateSpec ¶
type GateSpec struct {
Name string // registry key; consumers register their own gates
Patterns []string // gate-specific deny globs; empty = gate defaults
Allow []string // explicit allow globs
// Options holds every other `<key> "<value>"` child. The gate's builder
// rejects a key it does not know, so an unknown node still fails closed.
Options map[string][]string
}
GateSpec names a registered preflight gate plus its declarative config.
type Grant ¶
type Grant struct {
Subcommand []string // e.g. ["admin", "user", "list"]
Wildcard bool // `can run *`: the whole binary passes through
AllowFlags []string // non-empty -> strict flag allowlist
DenyFlags []string // default-allow minus these
ValueFlags []string // long flags whose value is a separate argv token
// ResolveFlags are long flags whose caller value umbra resolves through
// pkg/valuesource and spills to a file. See docs/execverb.md.
ResolveFlags []string
// Pins fix a flag's value: umbra supplies it and refuses a caller who
// passes a different one. See docs/execverb.md.
Pins []FlagPin
Gates []GateSpec
Whens []WhenClause
Describe string
// Argv is the per-grant `argv` override: tokens appended after argv-prefix
// in place of Subcommand. ArgvSet marks an explicit (maybe empty) override.
Argv []string
ArgvSet bool
// EmbeddedArgs identifies symbolic argv slots compiled into the binary.
// Runtime mounting resolves each slot to an absolute path before execution.
EmbeddedArgs []EmbeddedArg
// Sealed forbids trailing caller args: the pinned `argv` forwards exactly,
// with no caller-supplied tokens appended. Requires ArgvSet (parse-enforced).
Sealed bool
// Bin overrides the wrap binary for this grant only (multi-binary pipelines),
// still fixed at parse: the caller can never substitute it. See docs/.
Bin string
// contains filtered or unexported fields
}
Grant is one `can run <subcommand>` sentence plus its flag policy.
type GrantInfo ¶
type GrantInfo struct {
Name string `json:"name"` // dotted audit name, e.g. <cli>.ops.<tool>.<sub>.<verb>
Subcommand []string `json:"subcommand,omitempty"` // e.g. ["s3","ls"]; empty for the wildcard
Bin string `json:"bin,omitempty"` // the funnel's own binary, set only for an inspect-list (`allow`) leaf
Exec []string `json:"exec,omitempty"` // tokens appended after the binary: the argv override when set, else the subcommand
Wildcard bool `json:"wildcard"` // `can run *`: the whole binary passes through
Sealed bool `json:"sealed,omitempty"` // `sealed`: pinned argv forwards exactly, no trailing caller args
Describe string `json:"describe,omitempty"` // Guardfile describe note
AllowFlags []string `json:"allow_flags,omitempty"` // non-empty: strict flag allowlist
DenyFlags []string `json:"deny_flags,omitempty"` // default-allow minus these
Gates []string `json:"gates,omitempty"` // registered preflight gate names
Guards []string `json:"guards,omitempty"` // rendered when/deny-when guards
}
GrantInfo is one mounted grant: its CLI placement, the real invocation it authorizes, its flag policy, and any gates/guards that can still refuse it.
type Guardfile ¶
type Guardfile struct {
// Description is the optional top-level `description "..."` prose (sibling of
// `wrap`): standing context in describe + the ref doc. See docs/value-providers.md.
Description string
Group []string // command path, e.g. ["<cli>", "git"]
Bin string // the real binary, fixed at parse; bare names stay the default, absolute paths only when intentionally pinned
ArgvPrefix []string // unoverridable leading argv (remote-exec transport)
Env []EnvVar // environment vars set on the wrapped process
Grants []Grant // mounted leaves
Whens []WhenClause // wrap-level passthrough guards (never pass/only pass), enforced on every leaf - the host gate
// Allow lists bare binaries that each mount as an independent open-passthrough
// funnel: inspect-list sugar, mutually exclusive with exec/can run (docs/execverb.md).
Allow []string
// WrapWhens are wrap-level when/deny-when guards applied to every `allow`
// funnel - the read-only floor over the whole inspect list (allow only).
WrapWhens []WhenClause
// Replace installs the generated binary under the wrapped tool's own name,
// ahead of it on PATH. See docs/execverb-replacement.md.
Replace bool
// Occlude is the name a replacement is installed under, resolved at parse.
// Empty unless Replace is set.
Occlude string
// Withheld are `withhold` stubs: verbs stated as refused so a caller can
// tell policy from an unimplemented feature. See docs/execverb.md.
Withheld []WithheldStub
// NeverRules are `never run` paths, refused ahead of every grant.
NeverRules []NeverRule
// DefaultAllow inverts the default: an unnamed verb is forwarded to the
// wrapped binary rather than refused. See docs/execverb-default-allow.md.
DefaultAllow DefaultAllow
// Actions are declared ordered call sequences over granted exec leaves. See
// docs/execverb.md.
Actions []guardfile.Action
// ProviderDecls are consumer-declared value resolvers shared with the spec
// dialect: `provider <name> { exec ... }`. See docs/value-providers.md.
ProviderDecls []guardfile.ProviderDecl
// contains filtered or unexported fields
}
Guardfile is the parsed form of one exec-dialect wrap block.
func Parse ¶
Parse turns exec-dialect Guardfile source into a Guardfile. It fails closed: an unknown node, missing exec block, or malformed sentence is an error.
func (*Guardfile) EmbedPaths ¶
EmbedPaths returns distinct build-time file references in declaration order.
func (*Guardfile) OccludedName ¶
OccludedName is the binary name a replacement stands in front of, empty when the guardfile declares no `replace`.
type HostResolver ¶
HostResolver resolves a `shell <cmd>` selector: it execs cmd and returns the trimmed stdout. Injected for tests; nil execs for real. An error fails closed.
type NeverRule ¶
type NeverRule struct {
Subcommand []string
}
NeverRule is one `never run <subcommand...>` line: a path refused ahead of every grant, including a grant that covers it. See docs/execverb.md.
type Runner ¶
Runner fires the resolved command; env is the `NAME=VALUE` overrides to layer over the inherited environment. Injected for tests; nil execs for real.
type Surface ¶
type Surface struct {
Group []string `json:"group"` // command path, e.g. ["<cli>","ops","<tool>"]
Description string `json:"description,omitempty"` // the guardfile's top-level `description` prose, "" when none
Bin string `json:"bin"` // the wrapped binary, fixed at parse; empty for an inspect list
ArgvPrefix []string `json:"argv_prefix,omitempty"` // unoverridable leading argv
Env []string `json:"env,omitempty"` // env injections as "NAME = provider address" (source, never the resolved value)
Inspect bool `json:"inspect,omitempty"` // the `allow` inspect-list shape: each grant funnels its own binary, no single Bin
Guards []string `json:"guards,omitempty"` // wrap-level guards (the passthrough host gate), applied to every leaf
Grants []GrantInfo `json:"grants"` // every mounted leaf, in mount order
// DefaultAllow is the `default-allow` reason, empty when the wrap is closed.
// Without it a reader reads the grants as the whole surface.
DefaultAllow string `json:"default_allow,omitempty"`
}
Surface is the in-engine model of a mounted exec surface: the wrapped binary, the fixed argv prefix, and every granted subcommand leaf.
type WhenClause ¶
type WhenClause struct {
// Selector names the argv slot: flag name, `any-arg`, or `argN`. Empty when
// SourceCmd is set (the value comes from a shell fact, not argv).
Selector string
// SourceCmd is the ambient `shell <cmd>` selector source: exec'd once, its
// trimmed stdout is the value. nil means the value comes from argv (Selector).
SourceCmd []string
// Patterns are globs matched case-insensitively against the value(s).
Patterns []string
// Deny is true for `deny-when` / `never pass` (refuse on match), false for
// `when` / `only pass` (refuse on no match).
Deny bool
// Describe is the optional teaching note rendered in the describe surface.
Describe string
}
WhenClause is a `when`/`deny-when` argv guard, or a wrap-level `never pass`/ `only pass` passthrough guard. Grammar and selectors: docs/execverb.md.
type WithheldStub ¶
WithheldStub is one deliberately-omitted verb, stated so it can be seen. See docs/execverb.md.
func (WithheldStub) Label ¶
func (w WithheldStub) Label() string
Label renders the withheld verb's path for help and error text.