config

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: GPL-3.0 Imports: 14 Imported by: 0 modules, 0 packages

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.

Documentation

Overview

Package config loads and validates agentgate.yaml.

Index

Constants

View Source
const (
	DefaultPrefixSeparator = "__"
	DefaultCallTimeout     = 120 * time.Second
	DefaultApprovalTimeout = 60 * time.Second
	DefaultRetention       = 30 * 24 * time.Hour
	DefaultMaxResultBytes  = 256 * 1024
	DefaultAuditPath       = "~/.agentgate/audit.db"
	DefaultUIAddr          = "127.0.0.1:7777"
)

Defaults that apply when the config file leaves a field out.

View Source
const (
	EventDeny     = "deny"
	EventAsk      = "ask"
	EventHoneypot = "honeypot"
	EventFreeze   = "freeze"
	EventError    = "error"
	EventShadow   = "shadow"
	// EventDrift fires when a server changes a pinned tool, offers a new one,
	// or ships a definition the scan flags.
	EventDrift = "drift"
	// EventExfiltration fires when a canary token shows up in a call.
	EventExfiltration = "exfiltration"
	// EventInjection fires when a tool result carries hidden text or
	// instructions addressed to the model.
	EventInjection = "injection"
)

Event names a webhook can subscribe to.

View Source
const DefaultAnchorEvery = time.Hour

DefaultAnchorEvery is how often the chain head goes out.

Variables

DefaultWebhookEvents are sent when a webhook does not say which it wants.

Functions

func BuiltinRedactionPatterns

func BuiltinRedactionPatterns() []string

BuiltinRedactionPatterns returns the source of the built-in patterns, for documentation and for the web UI.

func BuiltinRedactors

func BuiltinRedactors() []*regexp.Regexp

BuiltinRedactors returns the patterns agentgate redacts out of the box.

func ExpandEnv

func ExpandEnv(s string) string

ExpandEnv replaces ${VAR} and $VAR with the value from the environment. Unset variables expand to the empty string, matching how MCP host configs behave.

func ExpandPath

func ExpandPath(p string) (string, error)

ExpandPath expands ${ENV} and a leading ~ in a filesystem path.

func ExpandPathClean added in v0.4.0

func ExpandPathClean(p string) (string, error)

ExpandPathClean expands ~ and ${ENV} in a path and cleans it, so that "/home/me/repo/" and "/home/me/repo" compare the same.

func ParseDuration

func ParseDuration(s string) (time.Duration, error)

ParseDuration parses "30d", "2w", "90m", "1h30m" and everything else time.ParseDuration accepts.

Types

type Anchor added in v0.5.0

type Anchor struct {
	// To lists destinations: an https:// webhook (an ntfy topic URL works),
	// ots:<dir> for an OpenTimestamps proof, or file:<path> (a bare path too)
	// to append to a file.
	To []string `yaml:"to"`
	// Every is how often, when the chain has grown. It defaults to 1h; the
	// last head is also sent when the gateway stops.
	Every Duration `yaml:"every"`
}

Anchor sends the chain head out on a schedule while the gateway runs.

type Approval

type Approval struct {
	// Mode is auto, tty, ui, ntfy, telegram, slack or deny.
	//
	//	auto  ask on every channel that is available — the web UI when it is
	//	      running, the terminal, the phone when ntfy is configured — and
	//	      take the first answer; deny when there is none
	//	tty   prompt on the agentgate terminal only
	//	ui    wait for an approval in the web UI only
	//	ntfy  ask on the phone only
	//	telegram, slack  ask in that chat only
	//	deny  never ask, deny every "ask" decision
	Mode    string   `yaml:"mode"`
	Timeout Duration `yaml:"timeout"`
	// Ntfy puts approvals on your phone through an ntfy server, with
	// Allow / Allow for session / Deny buttons on the notification.
	Ntfy *Ntfy `yaml:"ntfy"`
	// Telegram puts approvals in a Telegram chat, with the same buttons.
	Telegram *Telegram `yaml:"telegram"`
	// Slack puts approvals in a Slack channel, with the same buttons.
	Slack *Slack `yaml:"slack"`
}

Approval configures what happens to calls a rule marked "ask".

type Audit

type Audit struct {
	// Enabled defaults to true; set it to false to run without an audit trail.
	Enabled   *bool    `yaml:"enabled"`
	Path      string   `yaml:"path"`
	Retention Duration `yaml:"retention"`
	// Redact holds regexes applied to arguments and results before they are
	// written. They are added to the built-in patterns unless BuiltinRedaction
	// is false.
	Redact           []string `yaml:"redact"`
	BuiltinRedaction *bool    `yaml:"builtin_redaction"`
	// MaxResultBytes caps how much of a result is stored. Larger results are
	// truncated and flagged.
	MaxResultBytes int `yaml:"max_result_bytes"`
	// Anchor writes the head of the hash chain somewhere this machine cannot
	// rewrite, so a cut-off end of the log shows too.
	Anchor Anchor `yaml:"anchor"`
	// contains filtered or unexported fields
}

Audit configures the SQLite audit store.

func (*Audit) Redactors

func (a *Audit) Redactors() []*regexp.Regexp

Redactors returns the compiled redaction patterns.

type Canaries added in v0.4.0

type Canaries struct {
	// Action is what a canary leaving does beyond denying the call: deny
	// (the default) or freeze.
	Action string `yaml:"action"`
	// Path is the canary store. It defaults to canaries.json next to the
	// audit database, like the freeze marker.
	Path string `yaml:"path"`
	// Resource advertises a decoy MCP resource under this URI whose content
	// is the canaries' decoy files, e.g. "file:///home/me/.aws/credentials".
	// Reading it is recorded; empty means no decoy resource.
	Resource string `yaml:"resource"`
}

Canaries are fake credentials planted where an agent could read them (see `agentgate canary new`). Nothing legitimate ever sends one anywhere, so a call that carries one out — plain, base64, hex or URL-encoded — is an exfiltration attempt: it is denied and reported, and with action: freeze the whole gateway stops.

type Config

type Config struct {
	Version int `yaml:"version"`
	// PrefixSeparator joins the upstream name and the tool name. It defaults to
	// "__" because some MCP hosts reject dots in tool names; policy rules may
	// still be written with a dot either way.
	PrefixSeparator string        `yaml:"prefix_separator"`
	CallTimeout     Duration      `yaml:"call_timeout"`
	Approval        Approval      `yaml:"approval"`
	Audit           Audit         `yaml:"audit"`
	Upstreams       []Upstream    `yaml:"upstreams"`
	Policy          policy.Policy `yaml:"policy"`
	Honeypots       Honeypots     `yaml:"honeypots"`
	Notify          Notify        `yaml:"notify"`
	Pinning         Pinning       `yaml:"pinning"`
	Canaries        Canaries      `yaml:"canaries"`
	Taint           Taint         `yaml:"taint"`
	Telemetry       Telemetry     `yaml:"telemetry"`

	// Path is the file the config was read from. It is not part of the file.
	Path string `yaml:"-"`
}

Config is the whole of agentgate.yaml.

func Load

func Load(path string) (*Config, error)

Load reads, expands and validates a config file.

func Parse

func Parse(raw []byte) (*Config, error)

Parse decodes and validates config bytes. Unknown fields are an error, so a misspelled key is caught by "agentgate policy validate" rather than silently ignored at run time.

func (*Config) AuditEnabled

func (c *Config) AuditEnabled() bool

AuditEnabled reports whether calls should be recorded.

func (*Config) FreezeFile

func (c *Config) FreezeFile() string

FreezeFile is the path of the kill-switch marker. It sits next to the audit database so that every agentgate process reading the same config agrees on it, and so that `agentgate freeze` works with no proxy running at all.

func (*Config) Prefixed

func (c *Config) Prefixed(u *Upstream, tool string) string

Prefixed returns the name a tool of upstream u is exposed under.

func (*Config) ResolveTool added in v0.4.0

func (c *Config) ResolveTool(name string) (exposed, upstream, tool string)

ResolveTool reads a tool name the way a person writes one — as the host sees it (fs__write_file) or as upstream.tool (fs.write_file) — and returns the exposed name, the upstream and the upstream's own name for the tool.

func (*Config) SplitTool

func (c *Config) SplitTool(exposed string) (upstream string, tool string, ok bool)

SplitTool resolves an exposed tool name back to an upstream and the name the upstream uses. It reports false when no configured upstream can own the name.

func (*Config) Timeout

func (c *Config) Timeout(u *Upstream) time.Duration

Timeout returns the per-call timeout for an upstream.

func (*Config) Upstream added in v0.4.0

func (c *Config) Upstream(name string) *Upstream

Upstream returns the configured upstream with this name, or nil.

type Duration

type Duration time.Duration

Duration is a time.Duration that also understands the day and week suffixes used in the config file ("30d", "2w"), which time.ParseDuration rejects.

func (Duration) Duration

func (d Duration) Duration() time.Duration

Duration returns the value as a time.Duration.

func (Duration) Or

func (d Duration) Or(fallback time.Duration) time.Duration

Or returns d, or fallback when d is zero.

func (Duration) String

func (d Duration) String() string

String prints whole days and weeks the way they were written in the config, so "retention 30d" does not read back as "720h0m0s".

func (*Duration) UnmarshalYAML

func (d *Duration) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML accepts both "30d" and a plain number of seconds.

type Honeypot

type Honeypot struct {
	// Name is the exact name the host sees. Give it a prefix that matches a
	// real upstream if you want it to blend in ("fs__delete_everything").
	Name        string `yaml:"name"`
	Description string `yaml:"description"`
}

Honeypot is one decoy tool.

type Honeypots

type Honeypots struct {
	// Action is what tripping a honeypot does beyond denying the call:
	// "deny" (the default) or "freeze", which also throws the kill switch.
	Action string `yaml:"action"`
	// Tools are the decoys. Each needs a name; a description makes it more
	// convincing, and the whole point is to be convincing.
	Tools []Honeypot `yaml:"tools"`
}

Honeypots are tools that do not exist. They are advertised to the host like any other tool, and a call to one is proof that the agent is acting on instructions you did not give it — a prompt injection, a hallucinated capability, or a model that has decided to be creative. Nothing is ever forwarded; the call is denied, recorded and, if you say so, freezes the gateway.

type Notify

type Notify struct {
	Webhooks []Webhook `yaml:"webhooks"`
}

Notify sends events to the outside world.

type Ntfy added in v0.4.0

type Ntfy struct {
	// Server defaults to https://ntfy.sh.
	Server string `yaml:"server"`
	// Topic is where questions go; answers come back on <topic>-answers. On
	// a public server the topic name is the password, so it must be long
	// and random unless a token protects it.
	Topic string `yaml:"topic"`
	// Token is an access token for a server with access control.
	Token string `yaml:"token"`
}

Ntfy is an ntfy server and topic to put approvals on.

type Pinning added in v0.4.0

type Pinning struct {
	// Mode is what a change to a pinned tool does:
	//
	//	warn     report it (log, webhook "drift", web UI) and let it through
	//	enforce  also hide the changed tool, and any new one, from the host
	//	         until you trust it with `agentgate lock --trust`
	//	off      keep no lockfile
	//
	// The default is warn.
	Mode string `yaml:"mode"`
	// Lockfile is where the pins are kept. It defaults to the config file's
	// name with .lock instead of .yaml, next to it, and is meant to be
	// reviewed and committed like any other lockfile.
	Lockfile string `yaml:"lockfile"`
	// Scan is what a definition with the marks of tool poisoning does —
	// hidden characters, instructions to the model, pointers at credentials,
	// talk about another server's tools: warn (the default), quarantine (hide
	// the tool until it is trusted) or off.
	Scan string `yaml:"scan"`
	// Registry is a directory or base URL of definitions other people
	// trusted, one file per server version (agentgate lock --publish writes
	// them). A definition seen for the first time is then pinned only when
	// it is what the registry has; one that differs is reported, and held
	// back when pinning is enforced. A server the registry does not have is
	// pinned on first use as usual.
	Registry string `yaml:"registry"`
}

Pinning records every tool definition in a lockfile the first time it is seen and watches for changes. A server that changes what its tools say after you installed it — a rug pull — is caught the moment it does, and a definition with instructions hidden in it is caught before the model reads it.

func (*Pinning) Enabled added in v0.4.0

func (p *Pinning) Enabled() bool

Enabled reports whether a lockfile is kept.

func (*Pinning) Enforced added in v0.4.0

func (p *Pinning) Enforced() bool

Enforced reports whether changed and new tools are held back.

func (*Pinning) Normalize added in v0.5.0

func (p *Pinning) Normalize(configPath string) error

Normalize checks and completes the pinning settings, for a caller that changed them after the config was loaded.

func (*Pinning) Quarantines added in v0.4.0

func (p *Pinning) Quarantines() bool

Quarantines reports whether flagged definitions are held back.

func (*Pinning) Scans added in v0.4.0

func (p *Pinning) Scans() bool

Scans reports whether definitions are scanned at all.

type Slack added in v0.5.0

type Slack struct {
	// BotToken (xoxb-…) posts and updates the question.
	BotToken string `yaml:"bot_token"`
	// AppToken (xapp-…, with connections:write) opens the Socket Mode
	// connection the answers arrive on.
	AppToken string `yaml:"app_token"`
	// Channel is the channel id the questions go to.
	Channel string `yaml:"channel"`
	// Approvers, if set, are the user ids whose presses count.
	Approvers []string `yaml:"approvers"`
	// API defaults to https://slack.com/api.
	API string `yaml:"api"`
}

Slack is a Slack app that asks in a channel. Button presses arrive over Socket Mode, a connection agentgate opens, so nothing has to reach it from outside.

type Taint added in v0.5.0

type Taint struct {
	// Mode is what a call carrying a tainted value out does: off, warn (the
	// default: it is logged and reported, and goes through), ask or deny.
	Mode string `yaml:"mode"`
	// Labels make a result private when the call that returned it earned
	// one of them. The default is private-data, which the secrets and
	// lethal-trifecta packs attach to reading .env files and the like.
	Labels []string `yaml:"labels"`
	// Tools make a result private by the tool that returned it: globs over
	// upstream.tool or the name the host sees, e.g. "vault.*".
	Tools []string `yaml:"tools"`
	// MinLength is the shortest value remembered; shorter ones match too
	// much ordinary text. The default is 12.
	MinLength int `yaml:"min_length"`
	// contains filtered or unexported fields
}

Taint remembers the values that look like secrets in tool results a session should keep to itself, and notices them on their way out.

func (*Taint) Enabled added in v0.5.0

func (t *Taint) Enabled() bool

Enabled reports whether taint tracking is on.

func (*Taint) Private added in v0.5.0

func (t *Taint) Private(names, labels []string) bool

Private reports whether a result is private: its call earned one of the labels, or came from one of the tools.

type Telegram added in v0.5.0

type Telegram struct {
	// Token is the bot token from @BotFather.
	Token string `yaml:"token"`
	// ChatID is the chat the questions go to; only presses in that chat
	// count.
	ChatID int64 `yaml:"chat_id"`
	// Approvers, if set, are the user ids whose presses count.
	Approvers []int64 `yaml:"approvers"`
	// API defaults to https://api.telegram.org.
	API string `yaml:"api"`
}

Telegram is a bot that asks in a chat. agentgate reads the button presses over long polling, so nothing has to reach it from outside; the bot must not have a webhook set, and is best used for nothing else.

type Telemetry added in v0.4.0

type Telemetry struct {
	// OTLP sends a span per tool call over OTLP/HTTP (JSON). The standard
	// OTEL_EXPORTER_OTLP_* and OTEL_SERVICE_NAME variables are honoured, and
	// setting OTEL_EXPORTER_OTLP_ENDPOINT is enough to switch it on.
	OTLP telemetry.Config `yaml:"otlp"`
}

Telemetry exports agentgate's view of every call to an observability backend.

type Upstream

type Upstream struct {
	Name string `yaml:"name"`
	// Stdio is the command and arguments to run, for a stdio server.
	Stdio []string `yaml:"stdio"`
	// HTTP is the endpoint of a Streamable HTTP server.
	HTTP string `yaml:"http"`
	// Env is added to the environment of a stdio server. Values may reference
	// the agentgate process environment with ${VAR}.
	Env map[string]string `yaml:"env"`
	// Cwd is the working directory of a stdio server.
	Cwd string `yaml:"cwd"`
	// Headers are sent with every request to an HTTP server.
	Headers map[string]string `yaml:"headers"`
	// Prefix controls whether this upstream's tools are exposed with a
	// "<name><sep>" prefix. It defaults to true when more than one upstream is
	// configured and to false for a single upstream.
	Prefix  *bool    `yaml:"prefix"`
	Timeout Duration `yaml:"timeout"`
	// Tools limits what this upstream offers to the tools whose names, as
	// the server gives them, match one of these globs; a pattern that starts
	// with ! hides what it matches instead. A tool that is not offered cannot
	// be called, and its description, which the model reads as
	// instructions, never reaches the model. Empty offers every tool.
	Tools []string `yaml:"tools"`
	// contains filtered or unexported fields
}

Upstream is one real MCP server agentgate connects to.

func (*Upstream) Offers added in v0.4.0

func (u *Upstream) Offers(tool string) bool

Offers reports whether the upstream's tool of this name, as the server names it, is offered to the agent: it matches a pattern, or there are only ! patterns, and it matches no ! pattern.

func (*Upstream) Transport

func (u *Upstream) Transport() string

Transport reports how the upstream is reached.

func (Upstream) Unfiltered added in v0.4.0

func (u Upstream) Unfiltered() Upstream

Unfiltered is the upstream with every tool offered.

func (*Upstream) UnmatchedTools added in v0.4.0

func (u *Upstream) UnmatchedTools(names []string) []string

UnmatchedTools returns the Tools patterns that match none of names, the tools the server offers: most likely, a misspelt tool.

type Webhook

type Webhook struct {
	URL string `yaml:"url"`
	// Events is the subset to send: deny, ask, honeypot, freeze, drift,
	// exfiltration, injection, error, shadow. Empty means all but error and
	// shadow.
	Events []string `yaml:"events"`
	// Format shapes the body: "json" (the default, agentgate's own event
	// object), "slack", "discord" or "ntfy". The named ones post a message
	// the service renders as-is, so a webhook URL from any of them works
	// with no glue in between.
	Format  string            `yaml:"format"`
	Headers map[string]string `yaml:"headers"`
}

Webhook is one HTTP endpoint that wants to hear about events.

func (*Webhook) Wants

func (w *Webhook) Wants(event string) bool

Wants reports whether the webhook subscribed to an event.

Jump to

Keyboard shortcuts

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