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, and a high-risk audit trail. Everything here is deterministic — the "adversarial model review" layers (design §14.2 Layer 2/3) are a later, model-dependent phase. See Sandbox for what the execution hardening does and, importantly, does not confine.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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.
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).
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.
type AuditRow ¶
type AuditRow struct {
ID int64
TS int64
Who string
What string
Target string
Result string
Detail string
PrevHash 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 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.
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 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).
It is NOT an isolation boundary, and callers must not treat it as one. Naming what it does *not* do is the whole point of this comment: there is no filesystem confinement (the child can read and write any path its uid can, starting with $HOME, which is deliberately forwarded because agent CLIs keep their credentials and config there), no seccomp or namespaces, no rlimits, and no network restriction — egress policy lives in netguard, enforced by the caller, not here.
What it actually buys: 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. Real OS-level isolation (seccomp/namespaces on Linux, sandbox-exec on macOS, or a container) is a deploy concern layered on top; until it exists, the permission tiers in internal/defense are the only thing standing between a plan and a destructive command.
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.