Documentation
¶
Overview ¶
Package security implements the execution-side hardening of design doc §16 and plan P3-29..P3-32: a reduced subprocess environment, network egress validation, secret scrubbing, a high-risk audit trail, and — when sandbox.mode is configured — OS-level confinement for every spawned subprocess (seatbelt on macOS, bubblewrap on Linux; see policy.go and the platform sandbox_* files). Everything here is deterministic — the "adversarial model review" layers (design §14.2 Layer 2/3) are a later, model-dependent phase.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Backend ¶ added in v0.0.10
func Backend() string
Backend names the OS confinement the platform implements: "seatbelt" on macOS (sandbox-exec), "bwrap" on Linux (bubblewrap), "" elsewhere or when the tool is absent — in which case a non-off mode is a no-op and callers should surface that rather than pretend isolation exists.
func EndpointHost ¶
EndpointHost returns the lowercased host (host:port) of a URL, or "" when the URL cannot be parsed or has no host. Callers use it to pin the guard to the configured model endpoint so the allowlist is never empty in production.
func Redact ¶
Redact scrubs the two secret shapes that can appear in adapter output: a credential-named KEY=value / key: value pair, and a Bearer token. It is a heuristic safety net, not a parser — the real guarantee is that secrets are injected via env and never persisted, so this only defends against a misbehaving adapter echoing them back into a result or log.
func SetBasePolicy ¶ added in v0.0.10
func SetBasePolicy(p Policy)
SetBasePolicy installs the deployer-level sandbox settings every ApplyPolicy call starts from. Called once during daemon wiring.
func SystemSecretPaths ¶ added in v0.0.10
func SystemSecretPaths() []string
SystemSecretPaths lists the home-relative locations where this platform family keeps reusable credentials. ModeStrict denies subprocesses read and write access to them; the list errs toward the well-known names rather than completeness.
Types ¶
type Audit ¶
type Audit struct {
// contains filtered or unexported fields
}
Audit appends high-risk operation records to the audit_log table. Callers pass a DB whose schema includes audit_log (see storage.Migrate).
Entries can carry the node's Ed25519 attestation (P2-9): the signature covers the entry's chain hash, so a row cannot be rewritten and re-hashed by a DB writer who lacks the private key. Signing is installed with SetSigner; a key-less Audit records the historical unsigned shape.
func (*Audit) Record ¶
Record writes one entry, linking it to the global audit hash chain (A3). The read of the chain head and the insert must live in one transaction: two concurrent Records that each read the same head would both link to it, forking the chain and failing VerifyChain on one of them (M2). The store's single connection serializes the tx bodies, so the second writer always sees the first writer's row as the head.
func (*Audit) SetSigner ¶ added in v0.0.10
func (a *Audit) SetSigner(pub ed25519.PublicKey, priv ed25519.PrivateKey)
SetSigner installs the node identity used to sign recorded entries and to bind verification to this node's key. priv may be nil for callers that only verify (`panda audit verify`, the panel's integrity endpoint): with no private key nothing is signed, but signatures that do exist must be by pub.
func (*Audit) VerifyChain ¶
VerifyChain verifies the global audit hash chain. It returns nil if intact, or an error describing the first break.
The signature rules mirror TaskStore.VerifyTaskEventChain (P2-9 hardening): when the Audit knows the node's key, a signature must be BY THAT KEY (verifying against whatever key a row names would let a DB writer re-sign the chain under a keypair of their own), and once a signed row exists no later row may be unsigned (tail stripping). Pre-signing rows form a legacy unsigned prefix — there is nothing to check them against.
type AuditRow ¶
type AuditRow struct {
ID int64
TS int64
Who string
What string
Target string
Result string
Detail string
PrevHash string
// Sig/SigPub are the P2-9 attestation: the Ed25519 signature over this
// row's chain hash and the public key that produced it (both hex). Empty
// on rows recorded before entry signing or by an Audit without a key.
Sig string
SigPub string
}
AuditRow is one audit_log row.
type Entry ¶
type Entry struct {
Who string // actor node id
What string // operation, e.g. "native:tier2", "circuit:open", "agent:spawn"
Target string // task id / agent / command
Result string // "authorized" / "denied" / "ok" / "failed" / "open"
Detail string // extra context, never secrets
}
Entry is one high-risk operation record (plan P3-32). High-risk means any Tier-2 execution or denial, any circuit trip, and any adapter spawn — the operations whose "who / what / result" must be reconstructable later.
type Mode ¶ added in v0.0.10
type Mode string
Mode selects how hard ApplyPolicy confines a subprocess. ModeOff keeps the historical behavior — environment filtering and cwd only. ModeStandard adds the platform's deny-default file-write confinement plus explicit deny lists. ModeStrict additionally denies reads of credential-shaped paths so a subprocess cannot exfiltrate secrets that standard mode still lets it read.
type NetworkGuard ¶
type NetworkGuard struct {
// contains filtered or unexported fields
}
NetworkGuard validates the endpoints an agent subprocess is pointed at (plan P3-30). The deterministic MVP enforces two things at spawn time: the model endpoint is HTTPS (so the API key never travels cleartext) and it is in an explicit allowlist. Hard Linux-level egress control (netns/iptables restricting what the subprocess can reach) is a deploy concern layered on top; this guards the one host PANDA itself hands to the adapter.
func NewNetworkGuard ¶
func NewNetworkGuard(hosts ...string) *NetworkGuard
NewNetworkGuard builds a guard allowing the given hostnames (bare or host:port). Matching is case-insensitive and treats a host:port entry as allowing the bare host too — the entry is stored verbatim (so an exact host:port match still works) plus its hostname leg (so a URL that names the host without a port, or on a different one, still matches the bare-host check).
func (*NetworkGuard) CheckURL ¶
func (g *NetworkGuard) CheckURL(rawurl string) error
CheckURL validates a URL against the guard: it must be https and its host must be in the allowlist. Loopback endpoints (localhost, 127.0.0.0/8, ::1) are exempt from the https requirement (plaintext is fine for a local dev model), but are still subject to the host allowlist — so a guard pinned to a remote endpoint (D7) rejects loopback too.
type Policy ¶ added in v0.0.10
type Policy struct {
Mode Mode
// AllowNetwork gates outbound networking as a whole; endpoint-level
// filtering stays with NetworkGuard.
AllowNetwork bool
// WorkDir is the subprocess's cwd and is always writable. Empty means
// "wherever the daemon would run it" — resolved to the daemon cwd.
WorkDir string
// WritablePaths get write access beyond WorkDir. Absolute paths are used
// as-is; relative paths and "~/…" resolve against the user's home —
// that convention lets config files and credential manifests name
// "~/.claude" without knowing the account name. Entries are directories:
// a missing one is created as a directory before bind-mounting.
WritablePaths []string
// WritableFiles are the file-shaped siblings of WritablePaths — the bare
// credential files that sit at $HOME root (".claude.json") rather than in
// a directory of their own. Splitting them out is what lets a missing
// entry be created with the right inode type: a dotfile basename is not
// a file signature (".claude" is a directory), and a guessed-wrong create
// both mounts the wrong thing and leaves a junk file on the host that
// blocks the real directory forever.
WritableFiles []string
// DenyReadPaths lose both read and write access under ModeStrict (and
// keep write-denied only under ModeStandard — reading is the baseline
// there). Home-relative spelling follows WritablePaths.
DenyReadPaths []string
// DenyWritePaths lose write access under every mode. The node's own
// state (database, memory, config) lands here so a subprocess cannot
// corrupt bookkeeping the drift detector relies on.
DenyWritePaths []string
}
Policy is the resolved confinement for one subprocess launch. The base policy (SetBasePolicy) carries the deployer's choices; per-callsite code derives the final policy from it (adapter credential dirs, extra deny lists).
func BasePolicy ¶ added in v0.0.10
func BasePolicy() Policy
BasePolicy returns a copy of the configured base policy.
func DefaultPolicy ¶ added in v0.0.10
DefaultPolicy derives the launch policy for a subprocess whose working directory is workDir — the shape every caller shares before adding its own writable/deny entries.
type Sandbox ¶
type Sandbox struct {
// contains filtered or unexported fields
}
Sandbox sets an adapter subprocess's working directory and replaces its inherited environment with a fixed allow-list (plan P3-29).
Apply stays the historical shape: environment filtering and cwd only, no OS boundary — the child can still read and write any path its uid can, starting with $HOME (deliberately forwarded because agent CLIs keep credentials and config there). ApplyPolicy layers the real confinement on top: a deny-default sandbox-exec profile on macOS or a bubblewrap bind-mount jail on Linux, driven by Policy (see policy.go). What both share: the child starts in the task directory instead of wherever the daemon happens to run, and it does not inherit the parent's arbitrary environment, so an unrelated secret in the daemon's env does not silently reach a third-party agent CLI.
func (*Sandbox) ApplyPolicy ¶ added in v0.0.10
ApplyPolicy is Apply plus the OS confinement layer: it installs the environment and cwd first, then wraps the command under the platform's sandbox mechanism when the policy's mode asks for one. With ModeOff — or on a platform with no backend installed — it degenerates to the plain Apply behavior, so callers need no fallback path.
func (*Sandbox) Env ¶
Env returns the subprocess environment: a fixed allow-list of the variables an adapter needs to function at all, plus any explicitly injected entries (e.g. model credentials). Everything else in the parent's environment is dropped. HOME is forwarded on purpose — agent CLIs read their own config and auth from it — so this is an environment filter, not a home-directory boundary.
Unset variables are omitted rather than forwarded empty: exporting HOME="" to a child is not the same as leaving it unset, and several CLIs treat the empty value as a configured-but-broken home and fail instead of falling back.