-
-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Overview
This task implements a cryptographically secure audit logging system based on a Certificate Transparency-style Merkle tree that provides tamper detection and forensic integrity for the DaemonEye project. The system uses BLAKE3 hashing with rs-merkle to create an immutable audit ledger with inclusion proofs and periodic checkpoints.
Problem Statement
Current security monitoring systems often lack cryptographic guarantees for audit log integrity. Without tamper-evident logging, malicious actors who gain access to systems can modify or delete audit trails to cover their tracks, compromising incident response and forensic investigations.
Proposed Solution
Architecture Overview
The audit ledger implements a Certificate Transparency-style Merkle log backed by redb with the following key components:
- Append-only sequence of canonical JSON leaf entries
- BLAKE3 leaf hashing for uniform cryptographic integrity
- Incremental Merkle root updates with O(log n) complexity per append
- Inclusion proofs (sibling hash paths) generated on demand
- Periodic checkpoints with optional Ed25519 signatures for trust anchoring
- Air-gap export capability for offline verification
Core Data Structures
AuditEntry (redb storage format):
#[derive(Serialize, Deserialize, Clone)]
pub struct AuditEntry {
pub id: u64, // Monotonic sequence number
pub ts_ms: i64, // Epoch milliseconds timestamp
pub actor: String, // Who performed the action
pub action: String, // What action was performed
pub payload: serde_json::Value, // Action payload data
pub leaf_hash: [u8; 32], // BLAKE3(canonical_leaf)
pub tree_size: u64, // Tree size AFTER insertion
pub root_hash: [u8; 32], // Merkle root at tree_size
pub inclusion_proof: Option<Vec<[u8; 32]>>, // Optional cached sibling path
pub checkpoint_sig: Option<Vec<u8>>, // Optional Ed25519 signature
}Checkpoint (periodic integrity snapshots):
#[derive(Serialize, Deserialize, Clone)]
pub struct Checkpoint {
pub tree_size: u64, // Number of leaves in tree
pub root_hash: [u8; 32], // Merkle root hash
pub created_at_ms: i64, // Checkpoint creation time
pub signature: Option<Vec<u8>>, // Ed25519(tree_size || root_hash)
}Cryptographic Implementation
BLAKE3 Hasher Integration:
use blake3;
use rs_merkle::{Hasher, MerkleProof, MerkleTree};
#[derive(Clone, Debug)]
struct Blake3Hasher;
impl Hasher for Blake3Hasher {
type Hash = [u8; 32];
fn hash(data: &[u8]) -> Self::Hash {
*blake3::hash(data).as_bytes()
}
}Canonical Leaf Serialization:
fn canonical_leaf(
actor: &str,
action: &str,
payload: &serde_json::Value,
ts_ms: i64
) -> Vec<u8> {
// Fixed key order for stability
serde_json::to_vec(&serde_json::json\!({
"a": actor,
"ac": action,
"p": payload,
"ts": ts_ms
})).unwrap()
}Storage Backend
redb Integration:
AUDIT_LEDGER (u64 -> AuditEntry)- Main audit entriesAUDIT_CHECKPOINTS (u64 tree_size -> Checkpoint)- Periodic snapshots- Write-only access for procmond component
- Atomic operations for consistency guarantees
Acceptance Criteria
- Certificate Transparency-style Merkle Tree: Implement using rs-merkle with BLAKE3
- Canonical JSON Serialization: Fixed key order for leaf stability
- Inclusion Proof Generation: On-demand sibling path computation
- Checkpoint System: Periodic root snapshots with optional Ed25519 signatures
- redb Storage Backend: Efficient append-only operations
- Verification Functions: Offline proof verification capabilities
- Air-gap Export: Signed checkpoints + sample proofs for external audit
- Recovery Mechanism: Checkpoint-based recovery with safe-mode fallback
Technical Requirements
- Language: Rust (matching project tech stack)
- Hash Function: BLAKE3 for cryptographic integrity
- Merkle Tree: rs-merkle library integration
- Storage: redb embedded database
- Performance: O(1) append, O(log n) proof generation
- Security: Inclusion proof verification, checkpoint signatures
Dependencies
rs-merkle- Certificate Transparency-style Merkle tree implementationblake3- Cryptographic hashing libraryredb- Embedded database backended25519-dalek- Digital signature library (optional)serdeandserde_json- Canonical serialization
Implementation Location
Suggested implementation in procmond/src/audit/ directory (procmond write-only access):
mod.rs- Public API and core typesledger.rs- Main AuditLedger implementationmerkle.rs- rs-merkle integration and BLAKE3 hashercheckpoint.rs- Checkpoint management and Ed25519 signaturesstorage.rs- redb backend operationsverification.rs- Inclusion proof verification logiccanonical.rs- Canonical JSON serialization
Security Invariants
- Single Linear History: No forks outside controlled maintenance rebuilds
- Canonical Serialization Stability: Format changes require full rebuild + lineage reset
- Uniform Hash Algorithm: BLAKE3 per lineage with potential domain separation
- Monotonic Root Sequence: Sequential tree size progression
- Checkpoint Verification: Safe-mode replay on verification failure
- Inclusion Proof Integrity: Verifiable with
(root, leaf_index, total_leaves, leaf_hash, siblings[])
Operational Features
- Append Path: canonicalize → hash → insert → commit → record root
- Checkpoint Creation: Every N appends or T seconds
- Recovery Process: Load max checkpoint, replay subsequent entries, validate root
- Proof Serving: Regenerate on demand if not cached (logarithmic complexity)
- Air-gap Export: Signed checkpoints + sampled proofs for offline verification
Testing Strategy
- Unit Tests: BLAKE3 hasher, canonical serialization, redb operations
- Integration Tests: Full Merkle tree operations with rs-merkle
- Property-Based Tests: Merkle tree invariants using
proptest - Cryptographic Tests: Inclusion proof verification, checkpoint signatures
- Security Tests: Tampering detection, canonical format stability
- Performance Tests: Large tree operations and proof generation benchmarks
Related Requirements
This issue implements tamper-evident audit logging for security compliance:
- Requirement 7: Record security-relevant events in a tamper-evident audit ledger
- Acceptance Criteria 7.1: Record security events in append-only audit ledger with monotonic sequence numbers
- Acceptance Criteria 7.2: Include timestamp, actor, action, payload hash, previous hash, and entry hash in audit entries
- Acceptance Criteria 7.3: Use BLAKE3 for fast, cryptographically secure hash computation
- Acceptance Criteria 7.4: Provide chain verification function to detect tampering attempts
- Acceptance Criteria 7.5: Maintain proper ordering and millisecond-precision timestamps
Definition of Done
✅ Certificate Transparency-style Merkle tree implementation complete
✅ rs-merkle integration with BLAKE3 hasher working
✅ Canonical JSON serialization stable and tested
✅ Inclusion proof generation and verification functional
✅ Checkpoint system with optional Ed25519 signatures
✅ redb storage backend integration complete
✅ Recovery and safe-mode fallback mechanisms tested
✅ Air-gap export capability for external audit
✅ Comprehensive test suite (unit, integration, security, performance)
✅ Code review passed with security focus
✅ Documentation updated with operational procedures
This issue implements the Certificate Transparency-style audit ledger specified in the DaemonEye design document, providing cryptographic guarantees for forensic integrity and compliance requirements.