synapse
A component of the AienOS ecosystem.
Brought by drakestapleton
synapse / docs / THREAT_MODEL.md
| 1 | # Synapse Threat Model and Capability Enforcement Contract |
| 2 | |
| 3 | Tracking Issue: [aien-spark/aien-sovereign-core#515](https://github.com/aien-spark/aien-sovereign-core/issues/515) |
| 4 | |
| 5 | ## 1. Trust Boundaries |
| 6 | |
| 7 | 1. **Agent Client Boundary**: |
| 8 | Autonomous builder, reviewer, verifier, and benchmark agents are untrusted callers until authenticated by an Ed25519 signature over the canonical request/changeset payload and authorized by an unexpired, repository-scoped `AgentCapabilityGrant`. |
| 9 | 2. **Storage Engine Boundary (`synapse-store`)**: |
| 10 | The single-writer WAL and content-addressed blob store treat disk files and incoming payloads as potentially corrupted or adversarial. Every blob digest and WAL frame CRC32C + SHA-256 chain link is recomputed and verified on ingest and recovery. |
| 11 | 3. **Human Forge Projection Boundary (`synapse-git` / GitHub)**: |
| 12 | GitHub pull requests and review comments are human-facing projections. A merged GitHub pull request or remote branch update is never trusted as proof of canonical promotion unless accompanied by verified Radicle delegate threshold signatures. |
| 13 | 4. **Canonical Authority Boundary (`synapse-radicle`)**: |
| 14 | Only a `RadicleCanonicalHead` receipt backed by a verified `refs/rad/id` identity document (`xyz.radicle.project`) and at least `threshold` valid Ed25519 signatures over `refs/namespaces/<nid>/refs/rad/sigrefs` for the target `GitOid` can mark a lineage as canonical. |
| 15 | |
| 16 | ## 2. Capability Permission Matrix |
| 17 | |
| 18 | Each `AgentCapabilityGrant` is signed by a repository authority Ed25519 key and binds `(repo_id, agent_did, capabilities, max_bytes_per_op, max_ops_per_window, issued_at_ms, expires_at_ms, grant_nonce)`. |
| 19 | |
| 20 | | Operation | Required Capability | Additional Invariants Checked | Refusal Code on Violation | |
| 21 | | :--- | :--- | :--- | :--- | |
| 22 | | `get`, `tree`, `diff`, `history`, `provenance`, `conflicts`, `status`, `watch` | `Read` | `grant.repo_id == request.repo_id`, `now_ms <= grant.expires_at_ms`, changeset lookups (including ancestors and explicit conflict IDs) belong to the authorized repository, `page_size <= max_page_size` | `AuthCapabilityDenied`, `AuthCrossRepoDenied`, `ChangesetNotFound`, `AuthGrantExpired`, `PaginationLimitExceeded` | |
| 23 | | `submit` (propose changeset) | `Propose` | Valid agent Ed25519 signature over `ChangesetEnvelope`, payload within `max_bytes_per_op`, rate quota available, base tree known | `AuthSignatureInvalid`, `AuthCapabilityDenied`, `QuotaPayloadTooLarge`, `QuotaRateLimitExceeded` | |
| 24 | | `attach_evaluation` (test/benchmark receipt) | `Evaluate` | Target `ChangesetId` exists in `repo_id`, signed evaluation receipt digest valid, single-use request nonce not replayed | `AuthCapabilityDenied`, `AuthReplayDetected`, `ChangesetNotFound` | |
| 25 | | `record_review` (review verdict) | `Review` | Reviewer `agent_did != changeset.author_did` (no self-approval), valid signature, non-replayed nonce | `AuthCapabilityDenied`, `AuthSelfReviewRefused`, `AuthReplayDetected` | |
| 26 | | `project_git` / `promote_canonical` | `Publish` | For canonical promotion: verified `RadicleCanonicalHead` (`refs/rad/id` + `sigrefs` quorum >= `threshold`) and `base_git_oid == current_canonical_head` | `AuthCapabilityDenied`, `RadicleQuorumInsufficient`, `RadicleSignatureInvalid`, `StaleBaseHead`, `SplitBrainDivergence` | |
| 27 | |
| 28 | ## 3. Adversarial Threat Catalog and Mitigations |
| 29 | |
| 30 | | Threat ID | Adversarial Scenario | Mitigation and Deterministic Refusal | |
| 31 | | :--- | :--- | :--- | |
| 32 | | **T1: Forged Agent Identity** | Attacker submits a changeset claiming `author_did = did:key:z6Mk...` with a forged or mismatched Ed25519 signature. | `synapse-auth` extracts the 32-byte Ed25519 public key directly from `did:key:z6Mk...` (multicodec `0xed01`) and verifies the 64-byte signature over the domain-separated canonical envelope before any store admission. Refuses with `AuthSignatureInvalid`. | |
| 33 | | **T2: Cross-Repository Token or Object Reuse** | Agent holding a valid `Read`, `Propose` or `Publish` grant for `repo-A` requests a known `repo-B` changeset ID from a mixed store, or targets `repo-B` directly. | Grants and requests are bound to `RepoId` (`AuthCrossRepoDenied`), and repository-scoped lookups refuse a foreign changeset as `ChangesetNotFound`, including provenance, virtual-tree ancestry, explicit conflict IDs and GitHub PR projection. Own-repository snapshot visibility errors retain their established diagnostic; foreign IDs never reveal their commit sequence. | |
| 34 | | **T3: Expired or Replayed Mutation** | Attacker replays a captured mutation token or uses an expired `AgentCapabilityGrant`. | Grants enforce `now_ms <= expires_at_ms` (`AuthGrantExpired`). Mutation requests carry a monotonic or unique `request_nonce` tracked per `(repo_id, agent_did)` window; duplicates fail closed with `AuthReplayDetected`. | |
| 35 | | **T4: Unbounded Memory / Disk Exhaustion** | Flood of large blobs, deep directory trees, uncollected speculative changesets, or unauthenticated wire submissions. | Blob, path, pending-operation and page limits apply. The audit log retains at most 4,096 decisions; when full, new authorization fails with `BackpressureOverCapacity` before signature verification or nonce/quota mutation. The wire server closes a connection after 64 refusals or on audit exhaustion. This is backpressure, not an audit drain: without an operator-provided durable export/restart, the enforcer remains closed to new decisions. | |
| 36 | | **T5: Split-Brain CanonicalSpoofing** | GitHub PR is merged or fast ingest `WalSeq` advances, and an agent attempts to mark the changeset canonical without Radicle delegate quorum. | `synapse-radicle` refuses canonical promotion unless `refs/rad/id` and `refs/namespaces/<nid>/refs/rad/sigrefs` verify at least `threshold` distinct delegate signatures on the target `GitOid` (`RadicleQuorumInsufficient`, `SplitBrainDivergence`). | |
| 37 | | **T6: Crash or Torn Write Corruption** | Process dies mid-blob write or mid-WAL frame append. | Blobs are written and synced before the WAL frame is appended. Recovery verifies `SWAL` header magic, sequence continuity, CRC32C, and `prev_frame_sha256` hash chain; uncommitted blobs remain unindexed and torn tail frames are refused/quarantined without phantom visibility. | |
| 38 | |
| 39 | ## 4. Tamper-Evident Security Audit Log |
| 40 | |
| 41 | Every decision actually evaluated by `PolicyEnforcer::authorize` or `authorize_chain` appends a hash-chained `AuditEntry` (admitted or refused) containing sequence, time, repository, actor, capability, operation, outcome and previous/current SHA-256 hashes. The log is in memory; it is not independently signed or automatically persisted. `AuditLog::verify_chain()` detects a changed entry or broken chain within the retained log. Entries retain at most 1,024 bytes per attacker-controlled string field; longer fields are replaced explicitly by their original byte length and SHA-256 digest, not silently truncated. At the fixed 4,096-entry capacity, authorization refuses *before* evaluating the next request; that backpressure refusal cannot itself be appended without exceeding the cap. Operators must durably preserve and inspect the full log before starting a fresh enforcer; discarding it is audit loss, not successful draining. |