policy

package
v0.75.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 11 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 is the workspace permission engine. It decides whether a shell command may run and whether a file may be written, using allow/deny globs from the workspace config, and it confines all file operations to an optional jail directory. The decision (Allow / Ask / Deny) is returned to the caller; the interactive "ask" prompt itself lives in the tool layer.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotShellExpanded = errors.New("file paths are not shell-expanded")

ErrNotShellExpanded is the refusal of a path opening with an environment reference (see unexpandedRef), for a caller to pass on as it is.

Functions

This section is empty.

Types

type Decision

type Decision int

Decision is the outcome of a policy check.

const (
	Allow Decision = iota // run/write without prompting
	Ask                   // prompt the user (interactive y/n)
	Deny                  // refuse; never execute
)

func (Decision) String

func (d Decision) String() string

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine resolves policy decisions for one workspace. Command globs are precompiled at construction. Allow globs match the whole command (anchored); deny globs match anywhere in the command, so a dangerous token is caught even when it's buried in `cd x && rm -rf /`.

func New

func New(c config.Config) (*Engine, error)

New builds an Engine from a Config, resolving the jail root (relative to the workspace, symlink-followed) and precompiling the command globs.

func (*Engine) DeniedWrite added in v0.42.40

func (e *Engine) DeniedWrite(abs string) bool

DeniedWrite reports whether an already-resolved absolute path is blocked by the DenyWrite floor (.env, *secret*, …). Write's own check above only covers the path as it resolved at that moment; a caller that waits on an (async, possibly slow) approval between Resolve calls must call this again against the freshly re-resolved path right before it actually opens the file, since the target could have been swapped to a symlink pointing at a denied file while approval was pending — Resolve alone only re-enforces the jail, not the deny-write glob.

func (*Engine) IsSecret added in v0.15.0

func (e *Engine) IsSecret(abs string) bool

IsSecret reports whether an absolute path matches the secret-read floor, so the search/find walkers can skip it (not just the direct read path).

func (*Engine) Read

func (e *Engine) Read(path string) error

Read enforces the jail for a read and refuses obvious secrets (credential files).

func (*Engine) Resolve

func (e *Engine) Resolve(path string) (string, error)

Resolve returns the absolute, symlink-resolved path for a (possibly relative) input and errors if it escapes the jail. Relative paths resolve against the jail root (or the workspace when no jail is set). A leading ~ is expanded to the home dir FIRST — otherwise "~/x" is treated as a relative path and joined under the workspace, silently creating a literal "~" directory. The jail check still runs after expansion, so ~ can't be used to escape it.

func (*Engine) Run

func (e *Engine) Run(command string) Decision

Run decides whether a shell command may execute:

  • the hard floor (dangerous base exe / rm -r…, plus configured deny globs) → Deny;
  • else EVERY chained segment must match an allow glob → Allow (so an allowed prefix like "git *" can't smuggle a second command after && / |);
  • else the default.

func (*Engine) SetWorkdir added in v0.9.2

func (e *Engine) SetWorkdir(dir string) (string, error)

SetWorkdir points relative paths at dir (must resolve inside the jail). dir may be absolute or relative to the current base; ~ should be expanded by the caller.

func (*Engine) Workdir added in v0.9.2

func (e *Engine) Workdir() string

Workdir reports the current relative-path base.

func (*Engine) Write

func (e *Engine) Write(path string) (Decision, error)

Write decides whether a file may be written: jail first (escape is an error), then deny/allow write globs, then the default.

Jump to

Keyboard shortcuts

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