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 ¶
- Variables
- type Decision
- type Engine
- func (e *Engine) DeniedWrite(abs string) bool
- func (e *Engine) IsSecret(abs string) bool
- func (e *Engine) Read(path string) error
- func (e *Engine) Resolve(path string) (string, error)
- func (e *Engine) Run(command string) Decision
- func (e *Engine) SetWorkdir(dir string) (string, error)
- func (e *Engine) Workdir() string
- func (e *Engine) Write(path string) (Decision, error)
Constants ¶
This section is empty.
Variables ¶
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 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 ¶
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
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
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 ¶
Read enforces the jail for a read and refuses obvious secrets (credential files).
func (*Engine) Resolve ¶
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 ¶
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
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.