policy

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2026 License: MIT Imports: 6 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

This section is empty.

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) Read

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

Read enforces the jail for a read; reads are not glob-gated.

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).

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) 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