security

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: MIT Imports: 13 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 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

func EndpointHost(rawurl string) string

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

func Redact(s string) string

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 NewAudit

func NewAudit(db *sql.DB) *Audit

NewAudit wraps a DB.

func (*Audit) Entries

func (a *Audit) Entries(ctx context.Context) ([]AuditRow, error)

Entries returns all audit rows, oldest first.

func (*Audit) Record

func (a *Audit) Record(ctx context.Context, e Entry) error

Record writes one entry, linking it to the global audit hash chain (A3).

func (*Audit) VerifyChain

func (a *Audit) VerifyChain(ctx context.Context) error

VerifyChain verifies the global audit hash chain. It returns nil if intact, or an error describing the first break.

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. localhost/127.0.0.1 is exempt from the https requirement (plaintext is fine for a local dev model), but is still subject to the host allowlist — so a guard pinned to a remote endpoint (D7) rejects localhost 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 NewSandbox

func NewSandbox(dir string) *Sandbox

NewSandbox builds a sandbox rooted at dir.

func (*Sandbox) Apply

func (s *Sandbox) Apply(cmd *exec.Cmd, extra ...string)

Apply configures cmd with the sandboxed working directory and environment.

func (*Sandbox) Env

func (s *Sandbox) Env(extra ...string) []string

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.

Jump to

Keyboard shortcuts

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