policy

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: Apache-2.0 Imports: 10 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 policy decides which tools an agent may call. It implements docs/SPEC.md section 4: allow and deny lists of tool-name patterns and the groups "readonly" and "destructive", deny by default, and deny wins.

Index

Constants

View Source
const (
	GroupReadOnly    = "readonly"
	GroupDestructive = "destructive"
)

Group names a rule can use in place of a tool-name pattern.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decision

type Decision struct {
	Allowed bool
	// Rule is the rule that decided, as "allow <rule>" or "deny <rule>",
	// e.g. "deny cancel_*" or "allow readonly". When no rule matches it is
	// "default deny".
	Rule string
}

Decision is the result of checking one tool. Rule is written to the audit log, so a reader can see why a call was allowed or denied.

type Policy

type Policy struct {
	Allow []string
	Deny  []string
	// Digest identifies the policy in the audit log: "sha256:<hex>" of the
	// file it was parsed from, or "default" for the built-in policy.
	Digest string
}

Policy is a parsed writgate.yaml.

func Default

func Default() *Policy

Default is the policy used when no --policy file is given: only readonly tools are allowed.

func Load

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

Load reads and parses a policy file.

func Parse

func Parse(data []byte) (*Policy, error)

Parse parses a policy from YAML. It rejects unknown keys, empty rules, and rules with characters a tool name can't contain, so a typo fails at startup instead of silently allowing or denying.

A policy must have an "allow" list, even an empty one: without it every tool would be denied, which is more likely a mistake (a deny-only file written as if the default were allow) than the intent.

func (*Policy) Decide

func (p *Policy) Decide(t Tool) Decision

Decide checks one tool. Deny wins over allow whatever the order, and a tool no allow rule matches is denied. The rule reported is the first match in list order, deny rules before allow rules.

type Tool

type Tool interface {
	Name() string
	ReadOnly() bool    // in the group "readonly"
	Destructive() bool // in the group "destructive"
}

Tool is what the policy needs to know about a tool. *tools.Tool satisfies it.

Jump to

Keyboard shortcuts

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