Merkle Hash-Chain Audit Trail
OpenFang maintains a tamper-evident audit log of all agent actions using a Merkle hash-chain structure. Every audit entry includes a cryptographic hash of the previous entry, making it impossible to modify past events without detection.Why Merkle Hash-Chains?
Traditional logs can be silently modified by attackers with file system access. Merkle hash-chains make tampering detectable:- Each entry contains:
hash(prev_hash + current_data) - Modifying any entry breaks the chain
- Verification is fast (O(n) single pass)
- No trusted third party required
Example Chain
Audit Log Structure
Each audit entry is a JSON object stored in SQLite:Event Types
Hash Calculation
The hash is calculated using SHA-256:Genesis Hash
The first entry in the chain uses a well-known genesis hash:Audit Log Format
Example: Agent Spawned
Example: Tool Invoked
Example: Sandbox Violation
Example: Capability Granted
Querying the Audit Trail
REST API Endpoints
Get All Audit Entries
Filter by Agent
Filter by Event Type
Filter by Time Range
Combined Filters
Pagination
Tamper Detection
Verify Chain Integrity
Verification Algorithm
Export for Compliance
Export as JSON
Export as CSV
Export with Verification Proof
Compliance Use Cases
1. SOC 2 Compliance
Requirement: “Maintain audit logs of all access to customer data.” OpenFang Solution:- All
MemoryReadandMemoryWriteevents logged - Tamper-evident chain prevents retroactive log modification
- Export logs for external auditor review
2. GDPR Right to Audit
Requirement: “Provide users with a record of all processing activities involving their data.” OpenFang Solution:- Filter audit trail by
agent_idor customuser_idtag - Export user-specific audit history
3. HIPAA Audit Controls
Requirement: “Implement hardware, software, and/or procedural mechanisms that record and examine activity in information systems that contain or use electronic protected health information.” OpenFang Solution:- All tool invocations logged with parameters (sanitized)
- Network requests logged with destinations
- Authentication events logged
4. ISO 27001 Monitoring
Requirement: “Audit logs shall be produced, kept and regularly reviewed.” OpenFang Solution:- Continuous audit logging (no gaps)
- Integrity verification via hash chain
- Automated weekly exports
Performance Considerations
Write Performance
- Audit writes are asynchronous (non-blocking)
- Buffered in memory, flushed to SQLite every 100ms
- Minimal impact on agent loop latency (<1ms)
Query Performance
- SQLite indexes on
timestamp,agent_id,event_type - Queries with filters use index scans (O(log n))
- Full chain verification is O(n) but cached (1hr TTL)
Storage Growth
- Typical entry size: ~500 bytes
- 1M events ≈ 500 MB
- Automatic rotation after 10M entries (configurable)
Audit Configuration
Monitoring Audit Health
Check Audit Status
Alerts
Set up monitoring alerts for:chain_valid: false→ CRITICAL: Tamper detected- High rate of
SandboxViolationevents → Potential attack - High rate of
AuthFailureevents → Brute force attempt - Storage approaching rotation threshold → Plan archival
Best Practices
1. Verify Regularly
Run verification weekly (or daily for high-security environments):2. Archive Before Rotation
Before audit rotation, export and archive:3. Monitor for Anomalies
Track baseline event rates:4. Restrict Export Access
Audit exports may contain sensitive data. Require authentication:Related Security Systems
Overview
All 16 security systems
Capabilities
Capability-based access control
Sandbox
WASM and subprocess isolation
Architecture
How audit integrates across subsystems
