Capability-Based Security
OpenFang uses a capability-based security model where every agent operation is subject to explicit permission checks. Capabilities are declared in the agent manifest and enforced at runtime by theCapabilityManager.
Why Capability-Based Security?
Traditional agent frameworks use coarse-grained permissions (“can this agent use tools?”). OpenFang uses fine-grained capabilities where each tool, memory scope, network target, and operation is individually gated.Benefits
- Least Privilege: Agents only access resources explicitly granted
- Privilege Escalation Prevention: Child agents cannot exceed parent capabilities
- Auditability: Every capability grant is logged to the Merkle audit trail
- Defense-in-Depth: Works alongside other security layers
Capability Types
Capabilities are defined as an enum inopenfang-types/src/capability.rs:
Wildcard Patterns
Capabilities support glob-style patterns:"*"— Matches everything"self.*"— Matches anything starting with “self.”"file_*"— Matchesfile_read,file_write,file_list, etc.
Manifest Declaration
Capabilities are declared in the agent’smanifest.toml:
Example: Minimal Agent
An agent that only reads files and stores results in its own memory:Example: Research Agent
An agent that searches the web, fetches content, and stores results:Example: Orchestrator Agent
An agent that spawns and coordinates other agents:Grant and Revoke Flow
Capabilities are managed by theCapabilityManager in openfang-kernel.
Grant Flow (At Spawn Time)
Revoke Flow (At Kill Time)
Runtime Enforcement
Inheritance Validation
One of the most critical security features: child agents cannot exceed parent capabilities.How It Works
validate_capability_inheritance() is called at spawn time before any capabilities are granted:
Example: Valid Inheritance
Parent capabilities:Example: Invalid Inheritance (Blocked)
Parent capabilities:OpenFangError::PrivilegeEscalation at spawn time.
Enforcement Points
Capabilities are enforced at multiple points in the execution flow:1. Tool Invocation
Location:openfang-runtime/src/tool_runner.rs
2. Tool List Filter
Location:openfang-runtime/src/agent_loop.rs
Before the LLM sees the tool list, it’s filtered by capabilities:
3. Memory Operations
Location:openfang-memory/src/kv_store.rs
4. Network Access
Location:openfang-runtime/src/web_fetch.rs
5. Agent Operations
Location:openfang-kernel/src/agent_registry.rs
6. Shell Execution
Location:openfang-runtime/src/tools/bash.rs
7. OFP Operations
Location:openfang-wire/src/peer_node.rs
Dynamic Capability Updates (Future)
Currently, capabilities are static — they’re set at spawn time and cannot change. A future release will support dynamic capability updates:Debugging Capability Issues
Check Granted Capabilities
Query the API to see what capabilities an agent has:Check Audit Trail
All capability grants and revokes are logged:Common Errors
Error: “Permission denied: tool:web_fetch”
Cause: Agent does not haveToolInvoke("web_fetch") capability.
Fix: Add to manifest:
Error: “Privilege escalation: Child capability exceeds parent grant”
Cause: Child agent requested a capability not held by parent. Fix: Either:- Grant the capability to the parent first
- Remove the capability from the child manifest
Error: “Permission denied: memory:shared.secrets”
Cause: Agent does not haveMemoryWrite("shared.secrets") capability.
Fix: Add to manifest:
Best Practices
1. Start with Minimal Capabilities
Grant only what’s required. You can always expand later.2. Use Wildcards Carefully
Wildcards are convenient but can grant more than intended:3. Separate Network and Tool Access
A tool capability doesn’t imply network access. Both must be granted:4. Audit Regularly
Review the capability audit trail monthly:5. Test Inheritance Before Production
Verify that child agents can spawn successfully in a dev environment before deploying.Related Security Systems
Overview
All 16 security systems
Sandbox
WASM and subprocess isolation
Audit Trail
Merkle hash-chain logging
Architecture
How capabilities integrate across subsystems
