interplane.Get Omega
Read in your language

synapse

A component of the AienOS ecosystem.

Brought by drakestapleton

branch main Branches Tags History

synapse / docs / F1_CAPABILITY_CHAINS.md

63 lines · 7109 bytes Raw Blame History Rendered
1# F1: Attenuated Capability Chains
2
3ADR 0003 section 9 step F1 (issue aien-spark/synapse#25). Section 5.8 "Agent identity and capabilities": grants become delegation chains issued from a repository authority, where each derived link may only narrow operations, path prefixes, reference scope, change scope, quotas, and validity window, and where request rate, storage, and footprint quotas are partitioned across children.
4
5Code: `crates/synapse-auth/src/chain.rs`, `crates/synapse-core/src/lib.rs` (`ChangeId` and chain refusal codes). Tests: `crates/synapse-auth/tests/f1_capability_chains.rs`. Evidence: `evidence/f1-capability-chains/`.
6
7## 1. Model and invariants
8
9| Concept | Meaning | Rule |
10| :--- | :--- | :--- |
11| `Capability` | `Read` (1), `Propose` (2), `Evaluate` (3), `Review` (4), `Publish` (5), `Undo` (6) | Bitmask in `OperationSet`; child bits must be a subset of parent bits |
12| `PathScope` | Canonical sorted set of repository-relative path prefixes (empty string means whole repository) | Prefix match on path segment boundaries (`""`, exact match, or followed by `/`); child prefixes must each be covered by a parent prefix |
13| `ReferenceScope` | Bitmask over `ReferenceKind::OwnDrafts` (1) and `ReferenceKind::CanonicalViaPromotionQueue` (2) | Child bits must be a subset of parent bits |
14| `ChangeScope` | `any` (`None`) or a strictly ascending list of `ChangeId`s (`Some(Vec<ChangeId>)`) | `any` narrows to `any` or `only(...)`; `only(P)` narrows only to `only(C)` with `C` a subset of `P` |
15| `ChainQuotas` | `max_ops_per_window`, `window_duration_ms`, `storage_bytes`, `footprint_paths`, `max_bytes_per_op` | `window_duration_ms` must equal parent's; `max_bytes_per_op` may only narrow; `max_ops_per_window`, `storage_bytes`, and `footprint_paths` are partitioned across granted children so child sums never exceed the parent's grant, and the parent keeps only its unallocated remainder |
16| `CapabilityLink` | One signed delegation link (`version`, `nonce`, `parent`, `repo_id`, `issuer_key`, `audience_key`, `caveats`, `signature`) | Root link has `parent = [0u8; 32]` and issuer in `trusted_authorities[repo_id]`; child link has `parent = parent_link.digest()` and `issuer_key = parent_link.audience_key` |
17| `CapabilityChain` | Root-first sequence of 1 to 16 `CapabilityLink`s | Every link must be granted at or before the request's `WalSeq`, unrevoked at `request_seq`, unexpired at `now_ms`, bound to `expected_repo_id`, and signed with strict Ed25519 verification |
18
19## 2. Operations and lifecycle
20
21* **Granting (`PolicyEnforcer::grant_link`)**: records the leaf link of a verified chain as granted at `seq`. Every ancestor link must already be granted at or before `seq` and unrevoked at `seq`. If the leaf has a parent link, its `max_ops_per_window`, `storage_bytes`, and `footprint_paths` are added to the parent's allocated totals; if any dimension would exceed the parent's quota, granting fails with `RefusalCode::QuotaPartitionExceeded` and state is unchanged.
22* **Revocation (`PolicyEnforcer::revoke_link`)**: marks a granted link revoked at `seq` (keeping the earliest revocation sequence if called more than once). Revocation is monotone and cannot be undone. Any chain containing a link with `revoked_at <= request_seq` is refused with `RefusalCode::AuthGrantRevoked`.
23* **Unallocated quota (`PolicyEnforcer::unallocated_quota`)**: returns a granted link's remaining `max_ops_per_window`, `storage_bytes`, and `footprint_paths` after subtracting what it has partitioned to granted children.
24* **Request authorization (`PolicyEnforcer::authorize_chain`)**: checks audit capacity first; if full, refuses with `BackpressureOverCapacity` before signature work or nonce/rate state changes. Otherwise verifies the chain, grant sequence/revocation, leaf audience and canonical request signature (`DOMAIN_CHAIN_REQUEST_V1`), capability and scope, payload size, rate window and nonce replay, then appends the admitted or refused decision to the hash-chained audit log. See `THREAT_MODEL.md` section 4 for the bounded in-memory log and its lack of automatic persistence.
25
26## 3. Canonical binary layout (principle P5)
27
28All integers are little-endian. Counts and byte lengths are bounds-checked against caps and remaining buffer bytes before allocation. Any malformed byte sequence, unknown bit, non-canonical path or `ChangeId` ordering, or trailing byte fails closed with `RefusalCode::AuthChainMalformed`.
29
30`CapabilityLink` body:
31* `version`: `u16` (`1`)
32* `nonce`: `[u8; 32]`
33* `parent`: `[u8; 32]` (`LinkDigest`, zero for root)
34* `repo_id`: `u32` byte length + UTF-8 bytes (at most 128 bytes)
35* `issuer_key`: `[u8; 32]`
36* `audience_key`: `[u8; 32]`
37* `operations`: `u8` bitmask (bits 0..5)
38* `references`: `u8` bitmask (bits 0..1)
39* `paths`: `u32` count (at most 256) + each prefix as `u32` byte length + UTF-8 bytes in canonical order
40* `changes`: `u8` tag (`0` = any, `1` = `u32` count at most 1024 + strictly ascending 16-byte `ChangeId`s)
41* `quotas`: `max_ops_per_window: u32`, `window_duration_ms: u64`, `storage_bytes: u64`, `footprint_paths: u64`, `max_bytes_per_op: u64`
42* `issued_at_ms`: `u64`
43* `expires_at_ms`: `u64`
44
45Link signature: Ed25519 signature over `SYNAPSE_CAPABILITY_LINK_SIGN_V1\0 || body`.
46Encoded link: `body || signature` (64 bytes).
47Link digest (`LinkDigest`): `SHA-256(SYNAPSE_CAPABILITY_LINK_ID_V1\0 || encode())`.
48Encoded chain (`CapabilityChain`): `version: u16 (1) || count: u8 (1..=16) || (link_len: u32 || link_bytes)*`.
49
50## 4. Acceptance
51
52| Acceptance (ADR 0003 section 9, row 5) | Test | Result |
53| :--- | :--- | :--- |
54| Property test: no derived grant exceeds its parent in operations, paths, references, change scope, quotas, or expiry | `f1_property_no_derived_grant_exceeds_its_parent` (seeded SplitMix64 `0xF1F1_0003_0025_5EED`, 256 cases, 843 narrowed links accepted, widened links refused across all 6 dimensions) | pass |
55| Property test: child quotas never sum above the parent's | `f1_property_child_quotas_never_sum_above_the_parent` (256 cases, 1799 children accepted, 2297 refused with `QuotaPartitionExceeded`) | pass |
56| Forged, stripped, and reordered chains refused | `f1_forged_chains_are_refused`, `f1_stripped_chains_are_refused`, `f1_reordered_chains_are_refused` | pass |
57| Link bound to another repository or audience refused | `f1_link_bound_to_another_repository_is_refused`, `f1_link_bound_to_another_audience_is_refused` | pass |
58| Out-of-scope path refused | `f1_out_of_scope_path_is_refused` (plus reference and change scope checks and path traversal refusal) | pass |
59| Chain with an ancestor revoked at the request's `WalSeq` refused | `f1_chain_with_an_ancestor_revoked_at_the_request_walseq_is_refused` | pass |
60
61Additional tests: `f1_partitioned_rate_parent_keeps_only_what_it_has_not_handed_down`, `f1_link_and_chain_binary_encoding_is_canonical_and_malformed_bytes_are_refused`.
62
63Red then green logs: `evidence/f1-capability-chains/red-green/red.txt` (all 11 acceptance tests fail on assertion against stubs at commit `f377f41`) and `evidence/f1-capability-chains/red-green/green.txt` (all 11 pass).