permissions

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 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 permissions defines golder's approval modes and the live, mutable state that tracks the active one. It is a leaf package: standard library only, no imports from judge/trust/runtime, so every layer (the risk gate, the bash tool, the slash command) can read the mode without an import cycle.

The four modes are the whole authorization policy. Risk review is an input to the mode, not a second permission system:

  • read-only: only in-workspace reads. Writes, network and escaping the sandbox are refused outright.
  • ask: the reviewer filters routine calls; anything left, and every capability expansion (outside path, network, unconfined), is one human question covering the whole call.
  • auto: the reviewer settles both risk and capability expansion. Allow/Confirm grant every capability the call asked for; Contain runs isolated; Deny blocks. No human prompt.
  • full-access: no review, no consent, no sandbox; only the static hard-deny floor remains.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsAgainst added in v1.2.15

func AbsAgainst(base, p string) (string, error)

AbsAgainst returns p as a cleaned absolute path: an absolute p is cleaned, a relative one is resolved against base (which defaults to the working directory when empty). "~" is deliberately NOT expanded here, because the file tools do not expand it either — the gate and the tools must agree on what a path names, or the gate would ask about a location the tool never visits. User-supplied grants (NormalizeReadRoot) expand it, since there the spelling comes from a person rather than from a call argument.

func AddReadRoot added in v1.2.15

func AddReadRoot(raw string) (string, error)

AddReadRoot grants one directory for reading, for this session. It returns the normalized path so callers can echo it back. The same directory granted twice is stored once.

func BoundaryCandidate added in v1.3.0

func BoundaryCandidate(target string) string

BoundaryCandidate returns the directory a boundary question may offer to grant for the session, given the path a call named. The answer is as narrow as the read that asked the question:

  • a directory — an `ls`, `grep` or `find` operand, or a shell command's directory argument — is offered as itself, so `ls /outside/proj` offers /outside/proj rather than the tree above it;
  • a file is offered as the directory holding it, the narrowest grant that covers a read of that file;
  • a path that does not exist is treated as a file, because there is nothing there yet for a grant to name.

"" means no directory should be offered (the answer is then "this one file" or nothing), which happens when the directory that would be offered is too broad to hand over — a file sitting directly in the home directory, say.

func BroadReadRoot added in v1.2.15

func BroadReadRoot(p string) (string, bool)

BroadReadRoot reports whether p is too wide to grant. The filesystem root, the home directory itself and the directory holding it are refused: a grant there is indistinguishable from "no boundary", and a dialog that offers it would turn one keystroke into access to everything — the exact rubber stamp the boundary exists to prevent. A parent of the workspace is NOT broad: a monorepo above the current directory is a real thing to grant.

func Canonical added in v1.3.0

func Canonical(p string) string

Canonical resolves p the way the kernel will, so two spellings of one place compare equal.

Why it exists: Inside compares cleaned paths, and cleaning does not follow symlinks. On macOS "/tmp" is a symlink to "/private/tmp", so a whitelist entry for "/private/tmp" does not cover the literal "/tmp/x" a person actually types — and the boundary then asks about a path it already admits, which is how a prompt becomes noise people dismiss without reading. The same applies to "/var" and to any home directory reached through a link.

The path need not exist: resolution goes as deep as the filesystem allows and the remaining components are re-appended, so a target that will be created ("/tmp/new-file") is canonicalized by its existing parent. A path with no existing ancestor is returned cleaned, which is the old behavior and the conservative one: it can only fail to match, never match too much.

func Inside added in v1.2.15

func Inside(root, p string) bool

Inside reports whether p is root itself or lives under it. Both paths are compared as cleaned absolute paths, so a trailing separator does not change the answer.

It compares SPELLINGS, not locations: cleaning does not follow symlinks, so a link inside root that points outside it reads as inside. That is correct for a comparison between two spellings the same person wrote (the sandbox's allow rules are built from the literal paths a user typed), and wrong for any decision about where a path actually lands — use InsideResolved for those.

func InsideResolved added in v1.3.0

func InsideResolved(root, p string) bool

InsideResolved reports whether p lands inside root, following symlinks on both sides. It is the answer a boundary decision needs: a link inside the workspace can point outside it, and a caller that compared spellings would call that in-workspace and never ask. Both spellings of one place (a workspace opened through a link, macOS's /tmp and /private/tmp) compare equal because both sides are resolved.

It costs a filesystem walk, so Inside stays available for the comparisons that are about text rather than location — see its comment.

func InsideSystemReadRoots added in v1.3.0

func InsideSystemReadRoots(p string) bool

InsideSystemReadRoots reports whether p is admitted by the always-readable system whitelist, tolerating a symlinked spelling on EITHER side.

The two-sided check is the point. The literal list must stay literal for the sandbox (its allow rules name the path the kernel walks, and resolving them away broke `cat /etc/hosts` under seatbelt — measured, not assumed), while a boundary comparison must treat "/tmp/x" and "/private/tmp/x" as one place or it asks about a path the sandbox already admits. So both are consulted, and the result is the union: a path admitted by either spelling is not a question.

This is a leaf-layer definition shared by the read-scope gate and the access gate, so the two cannot disagree about what "always readable" means.

func InsideSystemWriteRoots added in v1.3.8

func InsideSystemWriteRoots(p string) bool

InsideSystemWriteRoots reports whether p is a place every run may write without asking: the machine's temp root, which the sandbox already admits as writable. The project root is deliberately absent — it differs per run, and the boundary gate checks it separately.

Without this, classifying shell writes (rm/mv/redirects) as write questions would ask about `rm /tmp/build/x`, a write the sandbox allows anyway.

func NormalizePath added in v1.2.15

func NormalizePath(raw string) (string, error)

NormalizePath validates one user- or gate-supplied path and returns its cleaned absolute form. "~/..." expands against the real home directory; relative paths are rejected (they would resolve differently for every process). The path need not exist yet.

It is the one path-normalization policy the permission layer has: the sandbox's writable roots (seatbelt.NormalizeWritableRoot) delegate here, so "~/x" and a relative path mean the same thing to both registries.

func NormalizeReadRoot added in v1.2.15

func NormalizeReadRoot(raw string) (string, error)

NormalizeReadRoot normalizes one read grant and refuses the roots that would amount to removing the boundary.

func ReadRoots added in v1.2.15

func ReadRoots() []string

ReadRoots returns the current grant list (a copy, safe to retain).

func ReadableRootsFromEnv added in v1.2.15

func ReadableRootsFromEnv(getenv func(string) string) []string

ReadableRootsFromEnv parses GOLDER_READABLE_ROOTS: colon- or comma-separated directories the read-only tools may reach without asking, for a machine or a script where editing config.toml is not the right place. Entries follow the same rules as the config list ("~/..." expands, relative paths and roots too broad to be a boundary are dropped), so an entry that would not be accepted from the config file is not accepted here either.

It mirrors GOLDER_SANDBOX_READABLE (the sandbox's read whitelist) but is not the same knob: that one reaches the OS sandbox only, so a command could read a path the file tools still refused. This one is the read-only tools' own list, and a grant here also reaches the sandbox, because the read roots feed its whitelist too.

func SystemReadRoots added in v1.2.17

func SystemReadRoots() []string

SystemReadRoots returns the directories a run may always read: the system runtime, the package-manager trees, and the temp roots a shell needs. It is deliberately short — $HOME is NOT here, because the point of the whitelist is that credential material inside $HOME is excluded by construction rather than by an ever-growing blacklist. A user whose toolchain lives under $HOME (conda, pyenv, nvm) adds it via [sandbox] readable or GOLDER_SANDBOX_READABLE.

Types

type Mode

type Mode int

Mode is one of the four approval modes.

const (
	// ReadOnly blocks mutating tools: the model may inspect but not change.
	ReadOnly Mode = iota
	// Ask grades each mutating call and asks the human about anything that is
	// not clearly low-risk. Without an interactive prompt the call is denied.
	Ask
	// Auto lets the reviewer decide without a human: reviewed calls run, risky
	// ones run sandboxed, dangerous ones are blocked, and each decision is
	// announced with its rationale.
	Auto
	// FullAccess disables review and sandboxing (the static floor remains).
	FullAccess
)

func FromEnv

func FromEnv(getenv func(string) string) (Mode, bool)

FromEnv resolves the default mode from GOLDER_PERMISSIONS. GOLDER_JUDGE=off is honored as a legacy alias for full-access. ok is false when the variable is unset or unparseable, leaving the caller's own default in place.

func Parse

func Parse(s string) (Mode, bool)

Parse resolves a user-supplied mode name. It accepts the canonical names plus a few common shorthands ("readonly", "ro", "full"), case-insensitively. ok is false for anything unrecognized so callers can report a usage error instead of silently picking a default.

func (Mode) Description

func (m Mode) Description(lang string) string

Description returns the one-line explanation shown next to the label.

func (Mode) Label

func (m Mode) Label(lang string) string

Label returns the human-facing name of the mode in the given language ("zh" for Simplified Chinese, anything else English). UI surfaces use it so the /permissions output matches the language of the conversation.

func (Mode) String

func (m Mode) String() string

String returns the canonical, lowercase mode name used by the CLI, the slash command, and the config/env layers.

type State

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

State is the process-wide, concurrency-safe holder of the active mode. The gate, the bash tool and the slash command all read it live, so a /permissions switch applies to the very next tool call (even mid-run).

func New

func New(mode Mode) *State

New returns a State seeded with mode.

func (*State) Mode

func (s *State) Mode() Mode

Mode returns the active mode.

func (*State) Set

func (s *State) Set(mode Mode)

Set replaces the active mode.

Jump to

Keyboard shortcuts

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