guard

package
v0.14.21 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package guard reviews a workflow body for safety violations before publish. Rule-based pre-flight (cheap, deterministic) per §17 of the design doc; the AI ephemeral-reviewer hook is left for callers to plug in via a custom Rule that spawns an agent.

Index

Constants

View Source
const (
	ModeOff   = "off"
	ModeWarn  = "warn"
	ModeBlock = "block"
)

Mode controls how violations are surfaced.

View Source
const (
	SevLow      = "low"
	SevMedium   = "medium"
	SevHigh     = "high"
	SevCritical = "critical"
)

Severity levels.

Variables

This section is empty.

Functions

func ContentHash

func ContentHash(w workflow.Workflow) string

ContentHash produces a deterministic hash of the workflow's governance-relevant payload (graph + triggers + env schema).

Types

type Config

type Config struct {
	Mode             string   `wick:"mode,dropdown=off|warn|block,default=warn,desc=Guard verdict policy"`
	NetworkAllowlist []string // host substrings; only checked when set
}

Config is the runtime knob.

type DestructiveShellRule

type DestructiveShellRule struct{}

DestructiveShellRule flags rm -rf, dd, mkfs, etc.

func (*DestructiveShellRule) Check

func (*DestructiveShellRule) Name

func (r *DestructiveShellRule) Name() string

type Guard

type Guard struct {
	Rules  []Rule
	Config Config
}

Guard wires a set of rules.

func New

func New(cfg Config) *Guard

New returns a guard preloaded with the default rule set per §17.

func (*Guard) Apply

func (g *Guard) Apply(report Report, override *workflow.Override) error

Apply enforces the configured mode. Returns nil if the workflow can publish; otherwise an error describing the block.

func (*Guard) Review

func (g *Guard) Review(ctx context.Context, w workflow.Workflow) Report

Review runs every rule.

type NetworkAllowlistRule

type NetworkAllowlistRule struct {
	AllowedHosts []string
}

NetworkAllowlistRule flags HTTP nodes hitting non-allowlisted hosts.

func (*NetworkAllowlistRule) Check

func (*NetworkAllowlistRule) Name

func (r *NetworkAllowlistRule) Name() string

type PlaintextSecretRule

type PlaintextSecretRule struct{}

PlaintextSecretRule flags `password:` / `token:` / `api_key:` strings in node bodies.

func (*PlaintextSecretRule) Check

func (*PlaintextSecretRule) Name

func (r *PlaintextSecretRule) Name() string

type PromptInjectionRule

type PromptInjectionRule struct{}

PromptInjectionRule flags raw `{{.Event.X}}` interpolation into shell command args without sanitization.

func (*PromptInjectionRule) Check

func (*PromptInjectionRule) Name

func (r *PromptInjectionRule) Name() string

type Report

type Report struct {
	OK          bool        `json:"ok"`
	Violations  []Violation `json:"violations,omitempty"`
	ContentHash string      `json:"content_hash"`
}

Report is the aggregate verdict.

type Rule

type Rule interface {
	Name() string
	Check(w workflow.Workflow) []Violation
}

Rule is one inspection function. Returning empty slice means "nothing to flag for this rule". Implementations should be cheap and pure — they receive a defensive copy of the workflow.

type UnparameterizedSQLRule

type UnparameterizedSQLRule struct{}

UnparameterizedSQLRule flags db_query bodies that string-concatenate template refs into SQL.

func (*UnparameterizedSQLRule) Check

func (*UnparameterizedSQLRule) Name

func (r *UnparameterizedSQLRule) Name() string

type Violation

type Violation struct {
	Rule     string `json:"rule"`
	Node     string `json:"node,omitempty"`
	Severity string `json:"severity"`
	Message  string `json:"message"`
}

Violation is one problem the guard found.

Jump to

Keyboard shortcuts

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