ADR-042: Security RVF

February 21, 2026 · View on GitHub

FieldValue
StatusAccepted
Date2025-02-21
Authorsruv
Supersedes
ImplementsADR-041 Tier 1 (Security Container)

Context

ADR-041 identified 15 npm packages suitable for RVF cognitive containers. This ADR specifies the ultimate security RVF — a single .rvf file that combines:

  1. AIDefence — 5-layer adversarial defense (prompt injection, jailbreak, PII, behavioral, policy)
  2. TEE attestation — Hardware-bound trust (SGX, SEV-SNP, TDX, ARM CCA)
  3. Hardened Linux microkernel — Minimal attack surface boot image + KernelBinding anti-tamper
  4. Coherence Gate — Anytime-valid permission authorization
  5. RBAC + Ed25519 signing — Role-based access with cryptographic proof
  6. Witness chain audit — Tamper-evident hash-chained event log
  7. Self-bootstrapping — Dual WASM (Interpreter + Microkernel) for standalone execution
  8. Dashboard — Embedded security monitoring UI (DASHBOARD_SEG)
  9. Quantization — Scalar (int8, 4x) + Binary (1-bit, 32x) compression
  10. Lifecycle — Filter deletion, compaction, and permanent freeze/seal

The result is a self-contained, bootable, cryptographically sealed security appliance with 30 verified capabilities, end-to-end from silicon to application layer.

Decision

Build security_hardened.rvf as a capstone example in examples/rvf/examples/ that exercises every security primitive in the RVF format.

Architecture

security_hardened.rvf
├── KERNEL_SEG (0x0E)     Hardened Linux 6.x + KernelBinding (128B anti-tamper)
├── EBPF_SEG (0x0F)       Packet filter + syscall policy enforcer
├── WASM_SEG #1 (0x10)    AIDefence engine (prompt injection, PII, jailbreak)
├── WASM_SEG #2 (0x10)    Interpreter runtime (self-bootstrapping)
├── DASHBOARD_SEG (0x11)  Security monitoring web UI
├── VEC_SEG (0x01)        Threat signature embeddings (512-dim)
├── INDEX_SEG (0x02)      HNSW index over threat vectors (m=32)
├── CRYPTO_SEG (0x0C)     Ed25519 keys + TEE-bound key records
├── WITNESS_SEG (0x0A)    30-entry security lifecycle chain
├── META_SEG (0x07)       Security policy + RBAC config + AIDefence rules
├── PROFILE_SEG (0x0B)    Domain profile: RVSecurity
├── PolicyKernel (0x31)   Gate thresholds + coherence config
├── MANIFEST_SEG (0x05)   Signed manifest with hardening fields
└── Signature Footer      Ed25519 over entire artifact

Segment Budget

SegmentPurposeSize Budget
KERNEL_SEGHardened Linux bzImage~1.6 MB
EBPF_SEGFirewall + syscall filter~8 KB
WASM_SEGAIDefence WASM engine~256 KB
VEC_SEGThreat embeddings (1000 x 512)~2 MB
INDEX_SEGHNSW graph~512 KB
CRYPTO_SEGKeys + TEE attestation records~4 KB
WITNESS_SEG30-entry audit chain~2 KB
META_SEGPolicy JSON + RBAC matrix~4 KB
PROFILE_SEGDomain profile~512 B
PolicyKernelGate config~1 KB
MANIFEST_SEGSigned directory~512 B
Total~4.4 MB

Security Layers

Layer 1: Hardware Root of Trust (TEE)

┌─────────────────────────────────────┐
│ AttestationHeader (112 bytes)       │
│ ├── platform: SGX/SEV-SNP/TDX/CCA  │
│ ├── measurement: MRENCLAVE          │
│ ├── signer_id: MRSIGNER            │
│ ├── nonce: anti-replay              │
│ ├── svn: security version           │
│ └── quote: opaque attestation blob  │
└─────────────────────────────────────┘
  • Hardware TEE attestation records in CRYPTO_SEG
  • TEE-bound key records: keys sealed to enclave measurement
  • Platform verification: correct TEE + measurement + validity window
  • Multi-platform: SGX, SEV-SNP, TDX, ARM CCA in single witness chain

Layer 2: Kernel Hardening

KernelHeader flags:
  KERNEL_FLAG_SIGNED           = 0x0001
  KERNEL_FLAG_COMPRESSED       = 0x0002
  KERNEL_FLAG_REQUIRES_TEE     = 0x0004
  KERNEL_FLAG_MEASURED         = 0x0008
  KERNEL_FLAG_REQUIRES_KVM     = 0x0010
  KERNEL_FLAG_ATTESTATION_READY = 0x0400

Linux tinyconfig + hardening options:

  • CONFIG_SECURITY_LOCKDOWN_LSM=y — Kernel lockdown
  • CONFIG_SECURITY_LANDLOCK=y — Landlock sandboxing
  • CONFIG_SECCOMP=y — Syscall filtering
  • CONFIG_STATIC_USERMODEHELPER=y — No dynamic module loading
  • CONFIG_STRICT_KERNEL_RWX=y — W^X enforcement
  • CONFIG_INIT_ON_ALLOC_DEFAULT_ON=y — Memory init on alloc
  • CONFIG_BLK_DEV_INITRD=y — Initramfs support
  • No loadable modules, no debugfs, no procfs write, no sysfs write

Layer 3: eBPF Enforcement

Two eBPF programs embedded:

  1. XDP Packet Filter — Drop all traffic except allowed ports

    • Allow: TCP 8443 (HTTPS API), TCP 9090 (metrics)
    • Drop everything else at XDP layer (before kernel stack)
  2. Seccomp Syscall Filter — Allowlist-only syscalls

    • Allow: read, write, mmap, munmap, close, exit, futex, epoll_*
    • Deny: execve, fork, clone3, ptrace, mount, umount, ioctl(TIOCSTI)

Layer 4: AIDefence (WASM Engine)

The WASM segment contains a compiled AIDefence engine with:

DetectorLatencyDescription
Prompt Injection<5ms30+ regex patterns + semantic similarity
Jailbreak<5msDAN, role manipulation, system prompt extraction
PII Detection<5msEmail, phone, SSN, credit card, API keys, IP
Control Characters<1msUnicode homoglyphs, null bytes, escape sequences
Behavioral Analysis<100msEMA baseline deviation per user
Policy Verification<500msCustom pattern matching + domain allowlists

Threat levels: nonelowmediumhighcritical

Default block threshold: medium (configurable via META_SEG policy)

Layer 5: Cryptographic Integrity

  • Ed25519 signing (RFC 8032): Every segment signed individually
  • Witness chain: HMAC-SHA256 hash-chained audit entries
  • Content hashing: SHAKE-256 truncated hashes in HardeningFields
  • SecurityPolicy::Paranoid: Full chain verification on mount
  • Key rotation: Witness entry records rotation event

Layer 6: Access Control (RBAC + Coherence Gate)

Role Matrix:
┌──────────┬───────┬──────┬────────┬───────┬──────────┐
│ Role     │ Write │ Read │ Derive │ Audit │ Gate     │
├──────────┼───────┼──────┼────────┼───────┼──────────┤
│ Admin    │ ✓     │ ✓    │ ✓      │ ✓     │ permit   │
│ Operator │ ✓     │ ✓    │ ✗      │ ✓     │ permit   │
│ Analyst  │ ✗     │ ✓    │ ✗      │ ✓     │ defer    │
│ Reader   │ ✗     │ ✓    │ ✗      │ ✗     │ defer    │
│ Auditor  │ ✗     │ ✓    │ ✗      │ ✓     │ permit   │
│ Guest    │ ✗     │ ✗    │ ✗      │ ✗     │ deny     │
└──────────┴───────┴──────┴────────┴───────┴──────────┘

Coherence Gate thresholds (PolicyKernel segment):

  • permit_threshold: 0.85
  • defer_threshold: 0.50
  • deny_threshold: 0.0
  • escalation_window_ns: 300_000_000_000 (5 min)
  • max_deferred_queue: 100

Capabilities Confirmed

#CapabilitySegmentVerification
1TEE attestation (SGX, SEV-SNP, TDX, ARM CCA)CRYPTO_SEGQuote validation + binding check
2TEE-bound key recordsCRYPTO_SEGPlatform + measurement + validity
3Hardened kernel bootKERNEL_SEGFlags: SIGNED, REQUIRES_TEE, MEASURED
4KernelBinding anti-tamperKERNEL_SEGmanifest_root_hash + policy_hash binding
5eBPF packet filterEBPF_SEGXDP drop except allowlisted ports
6eBPF syscall filterEBPF_SEGSeccomp allowlist enforcement
7AIDefence prompt injectionWASM_SEG12 pattern detection
8AIDefence jailbreak detectWASM_SEGDAN, role manipulation, 8 patterns
9AIDefence PII scanningWASM_SEGEmail, SSN, credit card, API keys
10AIDefence code/encoding attackWASM_SEGXSS, eval, base64, unicode tricks
11Self-bootstrappingWASM_SEG x2Interpreter + Microkernel dual WASM
12Security monitoring dashboardDASHBOARD_SEGEmbedded security UI
13Ed25519 segment signingCRYPTO_SEGPer-segment cryptographic proof
14Witness chain audit trailWITNESS_SEG30-entry HMAC-SHA256 chain
15Content hash hardeningMANIFEST_SEGSHAKE-256 content verification
16Security policy (Paranoid)MANIFEST_SEGFull chain verification on mount
17RBAC access controlMETA_SEG6 roles with permission matrix
18Coherence Gate authorizationPolicyKernelAnytime-valid decision with witness receipts
19Key rotationCRYPTO_SEG + WITNESSOld key rejected, new key active
20Tamper detectionWITNESS_SEG3/3 attacks rejected
21Multi-tenant isolationStore derivationLineage-linked derived stores
22COW branchingStore branchingForensic-grade immutable snapshots
23Audited k-NN queriesWITNESS_SEGWitness entry on every search
24Threat vector similarityVEC_SEG + INDEXk-NN over 1000 threat embeddings
25Data exfiltration detectionWASM_SEGcurl/wget/fetch/webhook patterns
26Scalar quantization (int8)rvf-quant4x compression, L2 distance preserved
27Binary quantization (1-bit)rvf-quant32x compression, Hamming distance
28Filter deletion + compactionStore lifecyclePurge + reclaim dead space
29QEMU requirements checkrvf-launchBootability proof (dry-run)
30Freeze/sealStore freezePermanent read-only immutability

MCP Tools (Security Container)

When served via MCP, the security RVF exposes these tools:

#ToolDescription
1aidefence_scanAnalyze input for all threat types
2aidefence_sanitizeRemove/mask dangerous content
3aidefence_validate_responseCheck LLM output safety
4aidefence_audit_logGet audit trail entries
5gate_permitRequest action authorization
6gate_receiptRetrieve witness receipt by sequence
7gate_replayDeterministic decision replay
8tee_attestGenerate TEE attestation record
9tee_verifyVerify attestation quote
10tee_bind_keyCreate TEE-bound key record
11rbac_checkVerify role permissions
12rbac_assignAssign role to principal
13threat_searchk-NN over threat embeddings
14threat_ingestAdd new threat signatures
15witness_chainGet/verify witness chain
16policy_getRead security policy config

HTTP API Endpoints

Port 8443 (TLS required in production)

POST   /api/v1/scan              AIDefence threat analysis
POST   /api/v1/sanitize          Input sanitization
POST   /api/v1/validate          Response validation
GET    /api/v1/audit             Audit log (paginated)
POST   /api/v1/gate/permit       Gate authorization request
GET    /api/v1/gate/receipt/:seq Receipt by sequence
POST   /api/v1/tee/attest        Generate attestation
POST   /api/v1/tee/verify        Verify quote
POST   /api/v1/rbac/check        Permission check
POST   /api/v1/threats/search    Threat similarity search
GET    /api/v1/status             System health
GET    /api/v1/policy             Security policy config

Implementation

Files Created

#PathDescription
1examples/rvf/examples/security_hardened.rsCapstone security RVF example
2docs/adr/ADR-042-Security-RVF-AIDefence-TEE.mdThis ADR

Files Modified

#PathChanges
1examples/rvf/Cargo.tomlAdd security_hardened example entry

Verification

# Build the example
cd examples/rvf && cargo build --example security_hardened

# Run the example (creates + verifies the security RVF)
cargo run --example security_hardened

# Expected output (v3.0 — 30 capabilities):
#   Phase 1:  Threat vector knowledge base (1000 embeddings)
#   Phase 2:  Hardened kernel + KernelBinding (KERNEL_SEG)
#   Phase 3:  eBPF packet + syscall filters (EBPF_SEG)
#   Phase 4:  AIDefence WASM #1 Microkernel (WASM_SEG)
#   Phase 4b: WASM #2 Interpreter (self-bootstrapping)
#   Phase 5:  Security monitoring dashboard (DASHBOARD_SEG)
#   Phase 6:  TEE attestation (SGX, SEV-SNP, TDX, ARM CCA)
#   Phase 7:  TEE-bound key records
#   Phase 8:  RBAC access control (6 roles)
#   Phase 9:  Coherence Gate policy (PolicyKernel)
#   Phase 10: Scalar + Binary quantization
#   Phase 11: 30-entry witness chain
#   Phase 12: Ed25519 signing + Paranoid verification
#   Phase 13: Tamper detection (3 tests)
#   Phase 14: Filter deletion + compaction
#   Phase 15: Multi-tenant isolation + COW
#   Phase 16: AIDefence live tests (10 threat types)
#   Phase 17: QEMU requirements check
#   Phase 18: Component verification
#   Phase 19: Freeze — permanent immutability seal
#   All 30 capabilities verified.

References

  • ADR-033: Mandatory manifest signatures + HardeningFields
  • ADR-041: RVF Cognitive Container identification
  • ADR-041a: Detailed container implementations
  • rvf-types/src/attestation.rs: AttestationHeader, TeePlatform
  • rvf-types/src/security.rs: SecurityPolicy, HardeningFields
  • rvf-crypto: Ed25519, witness chains, TEE attestation
  • ruvbot/src/security/AIDefenceGuard.ts: AIDefence implementation