@mago-foundation/mago-ski 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/README.md +54 -9
  2. package/action.yml +2 -2
  3. package/dist/hosts/github/run.d.ts +9 -1
  4. package/dist/hosts/github/run.js +64 -11
  5. package/dist/hosts/pi/index.d.ts +5 -3
  6. package/dist/hosts/pi/index.js +219 -14
  7. package/dist/src/admin.d.ts +140 -1
  8. package/dist/src/admin.js +328 -63
  9. package/dist/src/canonical-json.js +73 -28
  10. package/dist/src/certificate.js +23 -15
  11. package/dist/src/cli.js +590 -89
  12. package/dist/src/diff.d.ts +0 -4
  13. package/dist/src/diff.js +326 -70
  14. package/dist/src/dsse.d.ts +6 -4
  15. package/dist/src/dsse.js +22 -6
  16. package/dist/src/fs-safe.d.ts +32 -3
  17. package/dist/src/fs-safe.js +193 -31
  18. package/dist/src/gate/adapters/claude-code-hook.d.ts +1 -0
  19. package/dist/src/gate/adapters/claude-code-hook.js +4 -0
  20. package/dist/src/gate/adapters/claude-code-settings.d.ts +13 -0
  21. package/dist/src/gate/adapters/claude-code-settings.js +49 -0
  22. package/dist/src/gate/adapters/claude-code.d.ts +33 -0
  23. package/dist/src/gate/adapters/claude-code.js +193 -0
  24. package/dist/src/gate/adapters/client.d.ts +13 -0
  25. package/dist/src/gate/adapters/client.js +57 -0
  26. package/dist/src/gate/adapters/codex-hook.d.ts +1 -0
  27. package/dist/src/gate/adapters/codex-hook.js +5 -0
  28. package/dist/src/gate/adapters/codex-requirements.d.ts +19 -0
  29. package/dist/src/gate/adapters/codex-requirements.js +56 -0
  30. package/dist/src/gate/adapters/codex.d.ts +16 -0
  31. package/dist/src/gate/adapters/codex.js +574 -0
  32. package/dist/src/gate/adapters/hook-main.d.ts +7 -0
  33. package/dist/src/gate/adapters/hook-main.js +35 -0
  34. package/dist/src/gate/adapters/host-pid.d.ts +1 -0
  35. package/dist/src/gate/adapters/host-pid.js +20 -0
  36. package/dist/src/gate/admission.d.ts +54 -0
  37. package/dist/src/gate/admission.js +490 -0
  38. package/dist/src/gate/contract.d.ts +51 -0
  39. package/dist/src/gate/contract.js +94 -0
  40. package/dist/src/gate/decision-log.d.ts +38 -0
  41. package/dist/src/gate/decision-log.js +251 -0
  42. package/dist/src/gate/generations.d.ts +67 -0
  43. package/dist/src/gate/generations.js +518 -0
  44. package/dist/src/gate/proc.d.ts +31 -0
  45. package/dist/src/gate/proc.js +79 -0
  46. package/dist/src/gate/refresh.d.ts +11 -0
  47. package/dist/src/gate/refresh.js +30 -0
  48. package/dist/src/gate/run-verifier.d.ts +23 -0
  49. package/dist/src/gate/run-verifier.js +89 -0
  50. package/dist/src/gate/service.d.ts +80 -0
  51. package/dist/src/gate/service.js +722 -0
  52. package/dist/src/gate/strict-json.d.ts +11 -0
  53. package/dist/src/gate/strict-json.js +190 -0
  54. package/dist/src/gate/trust-store.d.ts +36 -0
  55. package/dist/src/gate/trust-store.js +251 -0
  56. package/dist/src/gate/verifier-worker.d.ts +8 -0
  57. package/dist/src/gate/verifier-worker.js +66 -0
  58. package/dist/src/index.d.ts +2 -0
  59. package/dist/src/index.js +2 -0
  60. package/dist/src/keys.d.ts +4 -0
  61. package/dist/src/keys.js +85 -30
  62. package/dist/src/main-module.js +1 -1
  63. package/dist/src/names.js +2 -4
  64. package/dist/src/policy.d.ts +173 -6
  65. package/dist/src/policy.js +685 -54
  66. package/dist/src/recovery-admin.d.ts +173 -0
  67. package/dist/src/recovery-admin.js +400 -0
  68. package/dist/src/revocations.js +3 -1
  69. package/dist/src/root-events.d.ts +107 -0
  70. package/dist/src/root-events.js +376 -0
  71. package/dist/src/time.d.ts +19 -3
  72. package/dist/src/time.js +50 -8
  73. package/dist/src/timestamp.d.ts +61 -0
  74. package/dist/src/timestamp.js +107 -0
  75. package/dist/src/tree-digest.d.ts +4 -0
  76. package/dist/src/tree-digest.js +41 -16
  77. package/dist/src/trust-root.d.ts +5 -0
  78. package/dist/src/trust-root.js +34 -13
  79. package/dist/src/verify.d.ts +69 -13
  80. package/dist/src/verify.js +309 -61
  81. package/docs/hosts/adapter-interface.md +8 -2
  82. package/docs/hosts/github-action.md +3 -3
  83. package/docs/hosts/pi.md +10 -3
  84. package/docs/spec/gui-admin-rack-v1.md +289 -0
  85. package/docs/spec/root-recovery-v1.md +451 -0
  86. package/docs/spec/skill-certificate-v1.md +1 -1
  87. package/docs/spec/skill-tree-v2.md +2 -2
  88. package/docs/spec/trust-documents-v1.md +12 -6
  89. package/docs/spec/verification.md +20 -3
  90. package/docs/threat-model.md +9 -6
  91. package/package.json +49 -44
@@ -0,0 +1,451 @@
1
+ # Root recovery v1
2
+
3
+ Status: **normative, implemented in mago-ski 0.3** (unreleased; `src/root-events.ts`, `src/timestamp.ts`, `src/policy.ts`, `src/recovery-admin.ts`). Hosts that read policy v2: the CLI, the Pi host and the GitHub Action. The E3 gate service keeps its own pinned root for now (see [Not covered yet](#not-covered-yet)).
4
+
5
+ In v1, every host trusts one pinned root key and nothing above it. If the root private key leaks, whoever holds the copy can sign trust roots and revocation lists that every host accepts, and the only remedy is to edit the policy on every host by hand ([threat model](../threat-model.md)).
6
+
7
+ This proposal adds a **recovery set**: a few keys, held by different people and kept offline, that hosts pin in advance. The recovery set cannot approve Skills or sign trust roots. It can do exactly two things, both recorded as signed, numbered **root events**:
8
+
9
+ - **revoke**: stop hosts trusting the current root key. A small number of recovery keys is enough (by default one), so any single trustee can stop the damage quickly. The worst a stolen recovery key can do with this is make hosts block everything until a rotation (an outage, never a takeover).
10
+ - **rotate**: replace the root key, and optionally the recovery set or the timestamp key. This needs a larger number of recovery keys (for example two of three), plus signatures from the new keys.
11
+
12
+ Two further rules make a revocation hard to escape:
13
+
14
+ - **A revoked root blocks in every mode**, shadow mode included, and is reported once per host rather than once per Skill. See [Revoked root](#revoked-root-blocked-in-every-mode).
15
+ - **Freshness (optional, recommended):** a separate, automated key re-signs a short-lived timestamp of the current documents. A host that is fed old files stops trusting anything within a day, instead of never noticing. See [Freshness](#freshness).
16
+
17
+ The design follows [TUF](https://theupdateframework.io/)'s root and timestamp roles. See [Rationale](#rationale-tuf-and-keri) for why this was chosen over a KERI-style pre-rotated successor.
18
+
19
+ ## Roles
20
+
21
+ | Key | Signs | Used | Hosts know it from |
22
+ |---|---|---|---|
23
+ | Recovery keys (1-16) | Root events only | Only in an incident or a planned rotation | Their fingerprints in the host policy |
24
+ | Root key | Trust root and revocation list | Every 30 days or so (revocation list refresh) | `root_fingerprint` in the policy, then rotate events |
25
+ | Timestamp key (optional) | Timestamps only | Automatically, every few hours | `freshness.key_id` in the policy, then rotate events |
26
+ | Approver keys | Skill certificates | Every approval | The trust root |
27
+
28
+ No key may hold two roles. A recovery key must not be the root key, the timestamp key or an approver; the timestamp key must not be the root key or an approver; and the root key must not be an approver (as in v1).
29
+
30
+ ## How a recovery works
31
+
32
+ Example organization: root key `R0`; recovery keys `A`, `B`, `C` held by three people; rotation needs 2 of them, revocation needs 1; timestamp key `T` used by an automated job.
33
+
34
+ 1. **Setup.** Every host's policy pins `R0`, the fingerprints of `A`, `B` and `C`, and `T`. The organization publishes an empty root event log next to the trust root, and the job re-signs a 24-hour timestamp every 6 hours.
35
+ 2. **Leak.** `R0`'s private key turns up in a public CI log.
36
+ 3. **Revoke (minutes).** Trustee A signs event 1, `revoke R0`, and appends it to the log. Each host that reads the new log blocks every Skill, in shadow mode too, and shows one alarm. A host the thief can feed old files does not see event 1, but its timestamp expires within 24 hours, after which it trusts nothing.
37
+ 4. **Rotate (hours).** The organization creates a new root key `R1`. Trustees A and B sign event 2, `rotate R0 -> R1`, keeping the same recovery set and timestamp key, and `R1` signs it too. `R1` then signs a trust root and a revocation list, listing the same approvers as before.
38
+ 5. **Back to normal.** Hosts read event 2, trust `R1`, and accept its documents. Existing certificates keep verifying: they are signed by approver keys and do not name the root. No host policy was edited.
39
+
40
+ The thief, holding only `R0`, cannot undo event 1 or produce event 2: both need recovery keys.
41
+
42
+ ## Host policy v2
43
+
44
+ A policy that uses recovery declares `mago.policy/v2`. A v2 host accepts v1 policies unchanged; they have no recovery set and behave exactly as today.
45
+
46
+ ```json
47
+ {
48
+ "policy_version": "mago.policy/v2",
49
+ "mode": "enforce",
50
+ "root_fingerprint": "sha256:<root key id at setup>",
51
+ "recovery": {
52
+ "key_ids": ["sha256:<A>", "sha256:<B>", "sha256:<C>"],
53
+ "rotate_threshold": 2,
54
+ "revoke_threshold": 1
55
+ },
56
+ "root_events": "root-events.json",
57
+ "freshness": {
58
+ "timestamp": "timestamp.json",
59
+ "key_id": "sha256:<T>",
60
+ "max_lifetime": "24h"
61
+ },
62
+ "trust_root": "trust-root.json",
63
+ "revocations": "revocations.json",
64
+ "state_file": "state.json"
65
+ }
66
+ ```
67
+
68
+ | Field | Required | Meaning |
69
+ |---|---|---|
70
+ | `root_fingerprint` | yes | The root key trusted before any root event. It does not change after a rotation |
71
+ | `recovery` | no | The recovery set trusted before any root event. When absent, the policy behaves as v1, and `root_events` and `freshness` must be absent too |
72
+ | `recovery.key_ids` | yes | Fingerprints of the recovery keys: sorted, unique, 1-16, none equal to `root_fingerprint` |
73
+ | `recovery.rotate_threshold` | yes | Recovery signatures a rotate event needs: `1 <= revoke_threshold <= rotate_threshold <= len(key_ids)` |
74
+ | `recovery.revoke_threshold` | yes | Recovery signatures a revoke event needs |
75
+ | `root_events` | with `recovery` | The root event log. Required when `recovery` is present, and the file must exist: an organization with no events publishes an empty log. A missing file is `UNVERIFIABLE`, so deleting it cannot hide a revocation |
76
+ | `root_events_after` | no | How many events `root_fingerprint`, `recovery` and `freshness.key_id` already reflect (default 0). A host set up after a rotation pins the current keys and this number, and starts walking at the next event. A log with fewer events than this is `UNVERIFIABLE` |
77
+ | `freshness` | no | Turns on the [freshness](#freshness) check. Requires `recovery`, so that a leaked timestamp key can be replaced |
78
+ | `freshness.timestamp` | yes | The timestamp file. It must exist |
79
+ | `freshness.key_id` | yes | The timestamp key trusted before any root event. Not `root_fingerprint` and not in `recovery.key_ids` |
80
+ | `freshness.max_lifetime` | no | The longest timestamp lifetime hosts accept, as a duration such as `24h` (default `24h`, at most `7d`). It caps the damage a leaked timestamp key can do by signing long-lived timestamps |
81
+
82
+ Only fingerprints are pinned. A key's public half is revealed in the first event or timestamp it signs, and must hash to its fingerprint.
83
+
84
+ ## Root event log
85
+
86
+ Canonical JSON, not signed as a whole (each event is signed):
87
+
88
+ ```json
89
+ {"events":[{"payload":"<base64>","payloadType":"application/vnd.mago-ski.root-event+json","signatures":[{"keyid":"sha256:<A>","sig":"<base64>"}]}],"type":"mago.root-events/v1"}
90
+ ```
91
+
92
+ - `events`: DSSE envelope objects in order. The event at index `i` has `sequence` `i + 1`.
93
+ - The log only grows. An organization never removes or rewrites an event, even an unwanted one (see [Rollback and forks](#rollback-and-forks)).
94
+ - At most 256 events; the file is at most 4 MiB.
95
+
96
+ ## Root events
97
+
98
+ Envelopes are DSSE, as for [certificates](skill-certificate-v1.md), with one difference: a root event carries **one signature per signer** instead of exactly one. Signatures are sorted by `keyid`, unique, and every one must be valid; an envelope with an unknown or invalid signature is rejected even if enough valid ones remain.
99
+
100
+ `payloadType`: `application/vnd.mago-ski.root-event+json`
101
+
102
+ ### Revoke
103
+
104
+ ```json
105
+ {
106
+ "type": "mago.root-event/v1",
107
+ "sequence": 1,
108
+ "action": "revoke",
109
+ "root_key_id": "sha256:<R0>",
110
+ "issued_at": "2026-11-02T09:00:00Z",
111
+ "reason": "root.pem appeared in a public CI log",
112
+ "signers": [
113
+ { "key_id": "sha256:<A>", "public_key": "<base64 DER SPKI>" }
114
+ ]
115
+ }
116
+ ```
117
+
118
+ ### Rotate
119
+
120
+ ```json
121
+ {
122
+ "type": "mago.root-event/v1",
123
+ "sequence": 2,
124
+ "action": "rotate",
125
+ "root_key_id": "sha256:<R0>",
126
+ "issued_at": "2026-11-02T15:30:00Z",
127
+ "reason": "replace leaked root",
128
+ "new_root": { "key_id": "sha256:<R1>", "public_key": "<base64 DER SPKI>" },
129
+ "new_recovery": {
130
+ "key_ids": ["sha256:<A>", "sha256:<B>", "sha256:<C>"],
131
+ "rotate_threshold": 2,
132
+ "revoke_threshold": 1
133
+ },
134
+ "signers": [
135
+ { "key_id": "sha256:<A>", "public_key": "<base64 DER SPKI>" },
136
+ { "key_id": "sha256:<B>", "public_key": "<base64 DER SPKI>" }
137
+ ]
138
+ }
139
+ ```
140
+
141
+ ### Fields
142
+
143
+ | Field | Meaning |
144
+ |---|---|
145
+ | `sequence` | Position in the log, starting at 1, with no gaps |
146
+ | `action` | `revoke` or `rotate` |
147
+ | `root_key_id` | The root key the host trusts just before this event (see [Host processing](#host-processing)). A revoke names the key it revokes; a rotate names the key it replaces |
148
+ | `issued_at` | UTC timestamp. Not more than 5 minutes in the future, and not earlier than the previous event's `issued_at` |
149
+ | `reason` | Non-empty text, at most 1024 characters. Shown in verdict reasons, notifications and block messages the model reads, so it must be plain text: no control, format (bidirectional marks, zero-width and tag characters, soft hyphens), surrogate, private-use or unassigned code points, no line or paragraph separators and no variation selectors |
150
+ | `signers` | The recovery keys that sign: sorted by `key_id`, unique. Each `public_key` must hash to its `key_id` |
151
+ | `new_root` | Rotate only. The new root key; `public_key` must hash to `key_id` |
152
+ | `new_recovery` | Rotate only. The recovery set trusted after this event, with the same rules as the policy's `recovery`. It may equal the current set |
153
+ | `new_timestamp` | Rotate only, optional. A new timestamp key, `{ "key_id", "public_key" }`. When absent, the timestamp key does not change. Hosts without `freshness` check the field and its signature but otherwise ignore it |
154
+
155
+ ### Who must sign
156
+
157
+ Let *current set* be the recovery set in force just before the event.
158
+
159
+ | Action | Signatures required |
160
+ |---|---|
161
+ | `revoke` | At least `revoke_threshold` keys of the current set |
162
+ | `rotate` | At least `rotate_threshold` keys of the current set, **and** at least the new `rotate_threshold` keys of `new_recovery`, **and** `new_root`, **and** `new_timestamp` if present |
163
+
164
+ - A key in both sets counts toward both thresholds, so a rotate that keeps the same set needs no extra recovery signatures.
165
+ - Every key in `signers` must belong to the current set or to `new_recovery`. The envelope's signatures are exactly the `signers`, plus `new_root` and `new_timestamp` for a rotate.
166
+ - The signatures from new keys prove that those keys exist and are held. A typo in a fingerprint cannot leave the organization with a recovery set nobody can use, or a root or timestamp key nobody can sign with. This is TUF's rule that new root metadata is signed by both the old and the new root keys.
167
+
168
+ ### Rules for a rotate
169
+
170
+ - `new_root.key_id` must not be in the current recovery set or in `new_recovery`.
171
+ - `new_root.key_id` must not be any key that an earlier event revoked or replaced. A key that has left the root role never returns.
172
+ - `new_root.key_id` may equal `root_key_id` only if that key is not revoked. This changes the recovery set or the timestamp key without changing the root (for example, when a trustee leaves or the timestamp key leaks).
173
+ - `new_timestamp.key_id` must not be the current or new root key, must not be in the current or new recovery set, and must not be a timestamp key that an earlier event replaced.
174
+ - `new_root.key_id` must not be the current or new timestamp key, and `new_recovery` must not contain the current root key, the current timestamp key, or any key that an earlier event revoked or replaced. **A key that has left the root or timestamp role never takes any role again**, so a leaked key cannot come back as a recovery key. Hosts only know the keys replaced by events they walk (after `root_events_after`).
175
+
176
+ ### Rules for a revoke
177
+
178
+ - The key named in `root_key_id` must not already be revoked.
179
+ - After a revoke, the next event, if any, must be a rotate naming the same `root_key_id`.
180
+
181
+ ## Freshness
182
+
183
+ Optional, turned on per policy with `freshness`, and recommended for hosts in enforce mode.
184
+
185
+ Without it, a host acts on whatever files reach it. Someone who controls how files reach a host (a sync job, a mirror, a network path) can keep feeding it an old log that lacks a revoke. If they also hold the leaked root key, they can keep signing fresh trust roots for it indefinitely. Freshness closes this gap: a separate **timestamp key**, used by an automated job, regularly signs a short-lived statement of exactly which files are current. A host rejects files that do not match a timestamp that is still valid.
186
+
187
+ ### Timestamp document
188
+
189
+ A DSSE envelope with exactly one signature, by the timestamp key.
190
+
191
+ `payloadType`: `application/vnd.mago-ski.timestamp+json`
192
+
193
+ ```json
194
+ {
195
+ "type": "mago.timestamp/v1",
196
+ "version": 412,
197
+ "issued_at": "2026-11-02T06:00:00Z",
198
+ "expires_at": "2026-11-03T06:00:00Z",
199
+ "timestamp_key": { "key_id": "sha256:<T>", "public_key": "<base64 DER SPKI>" },
200
+ "root_events": { "sha256": "<64 hex>", "count": 2 },
201
+ "trust_root": { "sha256": "<64 hex>", "version": 7 },
202
+ "revocations": { "sha256": "<64 hex>", "version": 31 }
203
+ }
204
+ ```
205
+
206
+ | Field | Meaning |
207
+ |---|---|
208
+ | `version` | Positive integer, increased with every timestamp |
209
+ | `issued_at` | Not more than 5 minutes in the future |
210
+ | `expires_at` | Later than `issued_at`, at most `max_lifetime` after it, and later than the host's current time |
211
+ | `timestamp_key` | Must be the active timestamp key (below); `public_key` must hash to `key_id`, which must equal the envelope's `keyid` |
212
+ | `root_events` | SHA-256 of the root event log file's bytes, and its number of events |
213
+ | `trust_root`, `revocations` | SHA-256 of each document file's bytes, and the `version` inside it |
214
+
215
+ ### What a host checks
216
+
217
+ The *active timestamp key* is `freshness.key_id`, replaced by each rotate event that carries `new_timestamp`. A host:
218
+
219
+ - reads each file once, and hashes and parses the same bytes;
220
+ - verifies the timestamp's signature with the active timestamp key;
221
+ - checks the times above and that `version` is not lower than the host state records;
222
+ - checks that the three digests, the event count and the two versions match the files it read.
223
+
224
+ Any failure is `UNVERIFIABLE`, and follows the configured mode (see [Reporting trust failures](#reporting-trust-failures-once)).
225
+
226
+ ### What it guarantees
227
+
228
+ - **A frozen host stops trusting.** A host that is fed old files rejects them once the newest timestamp naming them expires: at most `max_lifetime` (24 hours by default). It then trusts nothing until it receives current files.
229
+ - **A leaked root key alone does not reach freshness-checking hosts.** The timestamp names exact file digests, so a trust root signed with a leaked root key is accepted only if it has been published at the place the timestamp job reads from. Someone who can only tamper with the files on their way to a host cannot get it accepted.
230
+ - **A leaked timestamp key alone forges nothing.** It cannot sign events or trust documents. Combined with control over delivery to a host, it can keep that host on the documents it already has; see [What each leak allows](#what-each-leak-allows).
231
+
232
+ The longest time a revoked approver key or digest can still pass also drops, from the revocation list's lifetime (30 days by default) to `max_lifetime`.
233
+
234
+ ### Publishing
235
+
236
+ - The timestamp job runs every 6 hours with a 24-hour lifetime. If it stalls, hosts start failing 18 hours after its first missed run, which leaves time to notice and fix it.
237
+ - It reads the published files, hashes them, and signs. It publishes the timestamp together with any new documents: write everything to a new directory, then switch to it in one step. A host that reads mid-update sees a mismatch, which is `UNVERIFIABLE` until its next load.
238
+ - The timestamp key is online, so treat it as the key most likely to leak. Keep it in a different system from the root key, never in the same CI secret store.
239
+
240
+ ## Host processing
241
+
242
+ ### Walking the log
243
+
244
+ At every trust check, before reading the trust root, a host with a v2 recovery policy:
245
+
246
+ 1. Starts from the policy: *active root* = `root_fingerprint`, *recovery set* = `recovery`, *timestamp key* = `freshness.key_id`, *revoked* = false.
247
+ 2. Reads `root_events`. A missing, malformed or oversized log is `UNVERIFIABLE`.
248
+ 3. For each event after the first `root_events_after`, in order, checks every rule above against the current state, then applies it:
249
+ - revoke: *revoked* = true.
250
+ - rotate: *active root* = `new_root.key_id`, *recovery set* = `new_recovery`, *timestamp key* = `new_timestamp.key_id` if present, *revoked* = false.
251
+ 4. Any event that breaks a rule makes the whole log `UNVERIFIABLE`. The host does not skip it or stop early with the events before it.
252
+
253
+ Walking the full log keeps hosts without state correct, but hosts load trust documents often: the Pi host does so before every agent run and on every tool call that re-verifies a Skill. A worst-case log (256 events of 34 signatures) costs about 8,700 signature checks per walk, over a second on a laptop. So a host caches each **successful** walk, keyed by the policy's starting point (`root_fingerprint`, `recovery`, `freshness.key_id`, `root_events_after`) and the log's SHA-256, and walks again only when one of them changes. An unchanged log then costs one SHA-256 over at most 4 MiB. Failed walks are not cached, because an event that is too far in the future now may be valid later. The rollback and fork checks below run on every load; they only compare a number and a digest.
254
+
255
+ ### Order of checks
256
+
257
+ 1. Walk the root event log. Otherwise `UNVERIFIABLE`.
258
+ 2. Check rollback and forks against the host state. Otherwise `UNVERIFIABLE`.
259
+ 3. If the active root is revoked, every Skill is blocked: see [Revoked root](#revoked-root-blocked-in-every-mode). Nothing else is read.
260
+ 4. With `freshness`, check the timestamp against the files. Otherwise `UNVERIFIABLE`.
261
+ 5. Check the trust root and the revocation list as in v1, except that they must be signed by the **active root** instead of `root_fingerprint`. The trust root is also `UNVERIFIABLE` if any approver's key is in the active recovery set, is the active timestamp key, or is a key that has held the root or timestamp role in the walked events (`trust root lists approver <id>, which has held the root or timestamp role; a key that left those roles never takes another`). Only events after `root_events_after` are walked, so only keys retired in them are known. Hosts do not refuse a former recovery key listed as an approver; the GUI and `root add-approver --policy` refuse it as a new approver. The gate trust store (`src/gate/trust-store.ts`) does not run this check.
262
+
263
+ Before upgrading hosts, an organisation removes such approvers; see the upgrade note in the CHANGELOG.
264
+ 6. Record the new state.
265
+
266
+ ### Revoked root: blocked in every mode
267
+
268
+ When the active root is revoked:
269
+
270
+ - Every Skill is blocked, in **both `enforce` and `shadow` mode**. No policy setting changes this.
271
+ - The reason names the event, for example `root key sha256:... was revoked by root event 1 (root.pem appeared in a public CI log); waiting for a rotation`.
272
+ - The only way back is a rotate event. Switching the policy to shadow mode does not help.
273
+ - **A revoke the host has applied stays in force while the log cannot be checked.** The host state records that the last applied event left the root revoked. If the log later goes missing, becomes malformed, shorter (rollback) or forked, the host still reports `root-revoked`, not `trust-unavailable`, so damaging the log cannot lift a revoke on a shadow-mode host. Only a valid log that ends in a rotate clears it.
274
+ - Hosts load trust before anything the checked content can influence: the Pi host before expanding a `/skill:` command it has not seen yet, the GitHub Action before Skill discovery (whose budget a pull request controls).
275
+
276
+ Shadow mode means "approvals may be incomplete, so observe instead of blocking". It assumes the trust anchor is sound. A revoke is a signed statement by the organization's trustees that the anchor is not, so observing is no longer a safe choice. Making the block independent of the mode also removes the tempting shortcut during the outage, "switch to shadow so people can work", which would let through anything the leaked key signed.
277
+
278
+ Only a revoke, a signed and deliberate statement, overrides the mode. Failures that might have an innocent cause (an unreadable log, an expired timestamp from a stalled job) follow the configured mode.
279
+
280
+ ### Reporting trust failures once
281
+
282
+ A failure in the trust documents affects every Skill at once. Reporting it once per Skill would bury it among dozens of identical warnings, along with any Skill a thief has planted. So hosts report these failures **once per host**:
283
+
284
+ | Failure | Event name | Enforce mode | Shadow mode |
285
+ |---|---|---|---|
286
+ | The active root is revoked | `root-revoked` | block | **block** |
287
+ | Root event log missing or invalid, rollback, fork | `trust-unavailable` | block | would-block |
288
+ | Timestamp missing, invalid, expired or not matching the files | `trust-unavailable` | block | would-block |
289
+ | Trust root or revocation list invalid or expired (as in v1) | `trust-unavailable` | block | would-block |
290
+
291
+ While such a failure lasts:
292
+
293
+ - **Pi host:** one notice when it starts or changes, and the status bar shows it (for example `mago-ski: ROOT KEY REVOKED - all Skills blocked`). `root-revoked` is always an error, whatever the mode. No per-Skill notices are shown.
294
+ - **Decision log:** one record when it starts or changes. It carries the event name, empty `skill` and `skill_dir`, null `digest` and `certificate_id`, verdict `UNVERIFIABLE`, the action from the table and the reason. No per-Skill records are written.
295
+ - **CLI** (`verify`, `verify-all`, `policy check`): prints the failure once and exits non-zero.
296
+ - **GitHub Action:** one summary line and no per-Skill rows. It fails the check on `root-revoked` in both modes; on `trust-unavailable` it follows the mode.
297
+
298
+ ### Rollback and forks
299
+
300
+ Host state version 2:
301
+
302
+ ```json
303
+ {
304
+ "type": "mago.host-state/v2",
305
+ "roots": { "sha256:<R1>": { "trust_root_version": 1, "revocations_version": 1 } },
306
+ "root_events": { "sha256:<R0>": { "sequence": 2, "event_digest": "sha256:<hex>" } },
307
+ "timestamps": { "sha256:<T>": { "version": 412 } }
308
+ }
309
+ ```
310
+
311
+ (Written as canonical JSON; shown indented here.) A `root_events` entry also carries `"revoked": true` when the last applied event left the root revoked (see [Revoked root](#revoked-root-blocked-in-every-mode)); the field is absent otherwise.
312
+
313
+ - **When progress is recorded.** Root event progress is recorded as soon as the log passes the walk and the rollback and fork checks (step 2 of [Order of checks](#order-of-checks)), even if a later step fails or the root is revoked: the events are signed by recovery keys, and remembering a revoke is what stops a host being moved back to a log without it. Trust root, revocation list and timestamp versions are recorded only when every step passes. Only events the host checked are recorded: with `root_events_after` = N, nothing is recorded until the log has more than N events, so an unchecked event cannot be pinned and later reported as a fork.
314
+ - **Shared state files.** Several processes on one host may share a state file (two Pi sessions, Pi and the CLI). Before writing, a host re-reads the file and merges: every version keeps its highest value, the `root_events` entry with the higher `sequence` wins (on a tie with a different digest, the entry already in the file stays, so the fork is reported on the next load), and a v2 file is never written back as v1. If the merged state has applied more events than the log this load read, the load fails as a rollback.
315
+
316
+ - `root_events` has one entry per pinned `root_fingerprint`. `event_digest` is `sha256:` + the hex SHA-256 of the last applied event's envelope, serialized as canonical JSON with its trailing LF.
317
+ - **Rollback:** if the log has fewer events than the recorded `sequence`, it is `UNVERIFIABLE`. This stops a host from being moved back to a log without the revoke.
318
+ - **Fork:** if the event at the recorded `sequence` has a different digest, it is `UNVERIFIABLE`. Two valid but different events with the same number mean that two trustees prepared events at the same time, or that recovery keys were misused. Hosts fail closed until people sort it out. To avoid the honest case, trustees always prepare events against the published log, never a private copy.
319
+ - **Versions are per key.** `roots` is keyed by the root key that signed the documents, as in v1, and `timestamps` by the timestamp key. A new key starts its own count, so a thief who signed a document with a huge `version` using a leaked key cannot lock out its successor.
320
+ - Hosts without a state file (the GitHub Action) still walk and check the log and the timestamp, but have no rollback or fork protection, as for v1 documents. The Action reads them from the protected base revision.
321
+
322
+ An unwanted but valid event, such as a revoke signed with a stolen recovery key, is not rewritten. The organization appends a rotate after it. Because a revoke only removes trust, keeping it in the log is harmless.
323
+
324
+ ## What each leak allows
325
+
326
+ With `k` = `rotate_threshold` and `r` = `revoke_threshold`:
327
+
328
+ | Leaked | The thief can | The organization |
329
+ |---|---|---|
330
+ | The root key | Sign trust roots and revocation lists. Freshness-checking hosts accept them only if the thief can also publish at the place the timestamp job reads; other hosts accept them until they read a revoke | Any `r` trustees revoke; `k` trustees rotate |
331
+ | The timestamp key | Nothing by itself. With control over delivery to a host: keep that host on the documents it already has, by re-signing timestamps for them | `k` trustees rotate with `new_timestamp`; hosts that receive the log directly pick it up at once |
332
+ | The root key and the timestamp key | As the root key on a host without freshness | Revoke, then rotate both keys |
333
+ | Fewer than `r` recovery keys | Nothing | Optionally rotates to a recovery set without the leaked keys |
334
+ | `r` to `k - 1` recovery keys | Revoke the active root: an outage, not a takeover | `k` other trustees rotate, dropping the leaked keys from the set |
335
+ | The root key and fewer than `k` recovery keys | Both of the above | Revokes, then rotates to a new root and a set without the leaked keys |
336
+ | `k` or more recovery keys | Rotate to a root of their choosing: a takeover | Out of scope. Pin new keys on every host by hand |
337
+
338
+ A revocation, like a revocation list, reaches a host only when the host reads the new log. With freshness, a host that is fed old files stops trusting anything once its last timestamp expires, unless whoever feeds it also holds the timestamp key. Without freshness, a thief who holds the root key and controls delivery can keep a host on the old log indefinitely.
339
+
340
+ ## Limits
341
+
342
+ | Item | Limit |
343
+ |---|---|
344
+ | Recovery keys per set | 16 |
345
+ | Events per log | 256 |
346
+ | Log file size | 4 MiB |
347
+ | Signatures per event | 34 (16 current + 16 new recovery keys + the new root + the new timestamp key) |
348
+ | `reason` | 1024 characters |
349
+ | Timestamp file size | 64 KiB |
350
+ | `max_lifetime` | 7 days |
351
+
352
+ ## Recommended setups
353
+
354
+ | Organization | Recovery set | Why |
355
+ |---|---|---|
356
+ | Team or company | 3 keys, `rotate_threshold` 2, `revoke_threshold` 1, held by three people | Any one person can stop trust quickly; no single stolen or lost key prevents recovery or allows a takeover |
357
+ | One maintainer | 3 keys, `rotate_threshold` 2, `revoke_threshold` 1, stored in three places (for example a home safe, a bank box, a trusted person) | Same properties with one person. A 1-of-1 set is allowed but makes the single recovery key as powerful as the root |
358
+
359
+ Recovery private keys never sit next to `root.pem`, never in CI, and are used only to sign root events. Each trustee also keeps a printed copy of their key's fingerprint, so a signed event can be checked by eye.
360
+
361
+ For freshness, run the timestamp job every 6 hours with a 24-hour lifetime, and keep the timestamp key in a different system from the root key.
362
+
363
+ ## Commands
364
+
365
+ Rotations need several trustees who may be in different places, so signing is split into *prepare*, *sign* and *append*, like a TUF root signing ceremony. Every command that reads the log takes the organization's policy (`--policy`), which names the log and the starting keys. A proposal lists its signers up front, because the signatures cover that list.
366
+
367
+ ```
368
+ mago-ski recovery init --public-key a.pub --public-key b.pub --public-key c.pub \
369
+ --rotate-threshold 2 --revoke-threshold 1 # prints the policy "recovery" block
370
+ mago-ski root-events init --out root-events.json # empty log
371
+
372
+ # Revoke: one trustee is enough with revoke_threshold 1
373
+ mago-ski root-events prepare-revoke --policy policy.json --signer-public a.pub --reason TEXT --out proposal.json
374
+ mago-ski root-events sign proposal.json --key a.pem
375
+ mago-ski root-events append proposal.json --policy policy.json
376
+
377
+ # Rotate: the new root and two trustees sign the same proposal
378
+ mago-ski root-events prepare-rotate --policy policy.json --new-root-public r1.pub \
379
+ --signer-public a.pub --signer-public b.pub \
380
+ [--new-recovery-public KEY.pub ... --rotate-threshold N --revoke-threshold N] \
381
+ [--new-timestamp-public t2.pub] --reason TEXT --out proposal.json
382
+ mago-ski root-events sign proposal.json --key r1.pem
383
+ mago-ski root-events sign proposal.json --key a.pem
384
+ mago-ski root-events sign proposal.json --key b.pem
385
+ mago-ski root-events append proposal.json --policy policy.json
386
+
387
+ # Keep a key that held another role out of the trust root: pass the policy
388
+ mago-ski root add-approver --policy policy.json --root-key r1.pem --trust-root trust-root.json --public-key alice.pub --name Alice --scope '*' --expires 180d
389
+
390
+ # After a rotate: re-sign the trust root and revocation list with the new root (approvers and entries are kept)
391
+ mago-ski root adopt --root-key r1.pem --from-root-fingerprint sha256:<R0> \
392
+ --trust-root trust-root.json --revocations revocations.json
393
+
394
+ # Freshness: run by the timestamp job every 6 hours
395
+ mago-ski timestamp sign --policy policy.json --key timestamp.pem --expires 24h
396
+ ```
397
+
398
+ Before signing, each trustee runs `mago-ski root-events show PROPOSAL --policy policy.json`, which prints what the event does (action, number, root key, new keys, thresholds, reason) and checks that it is the next event of the published log, and compares it with what was agreed through a channel other than the one that delivered the proposal. `sign` prints the event it signed, refuses a key the event does not list, and with `--policy` refuses a proposal that is not the next event of the published log. `append` checks every rule a host would check, on the whole new log, so a log that `append` accepts is a log hosts accept; it refuses an event with a missing signature. `timestamp sign` reads the files the policy names, checks that the trust root and revocation list are signed by the active root, signs their digests with the next `version`, and writes the policy's `freshness.timestamp` file. `root adopt` keeps every approver of the old trust root: review them before publishing, because a leaked root key may have been used to add some.
399
+
400
+ Before rolling a v2 policy out to hosts, or after appending an event, the organization checks it the way a host would:
401
+
402
+ ```
403
+ mago-ski policy check --policy policy.json
404
+ ```
405
+
406
+ `policy check` loads the policy, walks the root event log, checks the timestamp if `freshness` is set, verifies that the trust root and revocation list are signed by the active root and that no approver holds another role, and prints the active keys and both thresholds. It exits non-zero on any problem, so it can gate the rollout.
407
+
408
+ ## Not covered yet
409
+
410
+ - **E3 gate service** (`src/gate/`): its trust store pins one root fingerprint and accepts trust roots and revocation lists from its inbox, without root events or timestamps. A follow-up adds both to the inbox and the trust-state manifest. Its verifier worker (`src/gate/verifier-worker.ts`, not yet wired into the service) already loads v2 policies through `loadPolicyTrust`, but turns `rootRevoked` into a per-Skill `UNVERIFIABLE`; the follow-up must make it block in every mode.
411
+ - **Early warning** before a timestamp expires (open question 2) is not implemented.
412
+
413
+ ## Changes to other documents
414
+
415
+ Applied with the implementation:
416
+
417
+ - **[Trust documents](trust-documents-v1.md):** the root-key line under *Key rotation* points here. The host policy and host state sections gain the v2 fields. The decision log section gains the `root-revoked` and `trust-unavailable` records.
418
+ - **[Verification](verification.md):** *Order of checks* starts with the steps in [Order of checks](#order-of-checks) above, and step 1 checks against the active root instead of the pinned fingerprint. The note on shadow mode gains the revoked-root exception.
419
+ - **[Pi host](../hosts/pi.md):** the *What it does* table gains a row for a revoked root (blocked in both modes), and the notification text describes the single report for trust failures.
420
+ - **[GitHub Action](../hosts/github-action.md):** a revoked root fails the check in shadow mode too, with one summary line.
421
+ - **[Threat model](../threat-model.md):** "A compromised root key" moves from *What it does not protect against* to the protections table, limited by the [leak table](#what-each-leak-allows) above. *Revocation timing* gains the freshness bound.
422
+ - **Migration:** every existing host's policy is edited once, to `mago.policy/v2` with a `recovery` block, an empty log and, ideally, `freshness`, after `mago-ski policy check` passes on it.
423
+
424
+ ## Rationale: TUF and KERI
425
+
426
+ Both TUF and KERI address key compromise, and their ideas are compatible; this design takes its structure from TUF and one idea from KERI.
427
+
428
+ **What TUF contributes.** TUF separates a *root role* (a threshold of offline keys, used rarely) from the keys that sign day-to-day metadata. When a day-to-day key leaks, the root role signs new metadata naming its replacement; clients walk the chain of root versions from the one they shipped with. In mago-ski, the root key is the day-to-day key: it signs a revocation list every 30 days, often from automation. So the recovery set plays TUF's root role, root events are the chain of root versions, and the rule that a rotation is signed by both the old and the new keys is TUF's. The freshness check is TUF's *timestamp role*: an online key that frequently re-signs a short-lived statement naming the current metadata, so a client cannot be kept on old metadata unnoticed (a *freeze attack*). TUF secures Sigstore's root of trust and, as Uptane, software updates in vehicles, and PyPI adopted it in PEP 458. mago-ski already follows TUF elsewhere: expiring signed metadata, version-based rollback protection, and short revocation-list lifetimes.
429
+
430
+ **What KERI contributes.** KERI commits to the next keys by their digests, so a key's public half is revealed only when it is used (*pre-rotation*). This design keeps that property in the form mago-ski already uses everywhere: hosts pin recovery and timestamp keys by fingerprint, and public keys appear only in what they sign.
431
+
432
+ **What KERI would add, and why this design does not take it.**
433
+
434
+ - *A single pre-rotated successor key* (rotate by revealing the next key; the next key becomes the root). Simple, but whoever steals the successor from storage can take over, with no threshold to stop them.
435
+ - *Several pre-rotated next keys with a threshold*, which KERI also supports. This is close to the recovery set, with one difference: each set of next keys is used once. Every rotation reveals them and commits to new ones, so all the trustees' keys are replaced at every rotation. The recovery set, like TUF's root role, keeps its keys across rotations until the organization chooses to change them.
436
+ - *Key event logs with witnesses and watchers.* KERI is built for self-certifying identifiers with no central authority, where many parties must agree on a key's history. mago-ski always has a central authority (the organization that publishes the policy and the documents), which is the setting TUF was built for. The root event log is enough.
437
+
438
+ **Alternatives considered.**
439
+
440
+ - *A threshold on every root signature* (k-of-n to sign each trust root and revocation list). It would protect against a root leak too, but would need `k` people every 30 days for the revocation list.
441
+ - *A revocation-only key*, separate from rotation. Kept, as `revoke_threshold`: setting it to 1 gives any one trustee a fast emergency stop whose worst misuse is an outage.
442
+ - *Cross-signing by the old root* (the plan in v1). Useful for planned rotations, but a thief holding the old root can cross-sign their own key, so it does not help after a leak.
443
+ - *Freshness by minimum versions instead of exact digests.* Simpler to publish, because a new document would not need a new timestamp. But it only stops freezes: a thief with the root key and control over delivery could hand a host any trust root with a high enough version. Exact digests also stop that.
444
+ - *A revoked root that follows the mode.* Rejected: see [Revoked root](#revoked-root-blocked-in-every-mode).
445
+
446
+ **Cost.** Freshness adds one signature check and hashes of files the host has already read: about 0.2 ms per trust load, measured on a laptop. Root events cost one SHA-256 of the log per trust load once a walk is cached. The real cost of freshness is operational: an automated job with its own key, and an outage if that job stops for longer than `max_lifetime`.
447
+
448
+ ## Open questions
449
+
450
+ 1. **Gaps while publishing.** A host that reads the files in the middle of a publish sees a mismatch until its next load. Is atomic publishing (a new directory, then one switch) enough, or should a timestamp also accept the previous set of digests for a short time?
451
+ 2. **Early warning.** Should hosts warn when the timestamp is close to expiring (for example, with less than a quarter of its lifetime left), so a stalled job is fixed before it causes an outage?
@@ -1,6 +1,6 @@
1
1
  # Skill certificate v1
2
2
 
3
- Status: draft, implemented by mago-ski 0.1. This page's URL is the certificate's `predicateType`. Test vectors: [`tests/vectors/certificates/`](../../tests/vectors/certificates/).
3
+ Status: draft, implemented by mago-ski 0.1 and later. This page's URL is the certificate's `predicateType`. Test vectors: [`tests/vectors/certificates/`](../../tests/vectors/certificates/).
4
4
 
5
5
  A Skill certificate records that an approver approved one exact version of one Skill until a stated time. It does **not** state that the Skill is safe.
6
6
 
@@ -1,6 +1,6 @@
1
1
  # Skill tree digest: `mago.skill-tree/v2`
2
2
 
3
- Status: draft, implemented by mago-ski 0.1. Test vectors: [`tests/vectors/trees.json`](../../tests/vectors/trees.json).
3
+ Status: draft, implemented by mago-ski 0.1 and later. Test vectors: [`tests/vectors/trees.json`](../../tests/vectors/trees.json).
4
4
 
5
5
  The tree digest identifies the exact contents of a Skill directory. A certificate approves one tree digest.
6
6
 
@@ -55,5 +55,5 @@ Because the digest is computed from the record list, anyone holding a certificat
55
55
 
56
56
  ## Known limitations
57
57
 
58
- - On Windows the executable bit is always `false`, so a Skill approved on Linux or macOS with an executable script will not verify on Windows. mago-ski 0.1 does not support Windows for this reason.
58
+ - On Windows the executable bit is always `false`, so a Skill approved on Linux or macOS with an executable script will not verify on Windows. mago-ski does not support Windows yet for this reason.
59
59
  - Some file systems report every file as executable (for example WSL's DrvFs mounts of Windows drives). Digest Skills on a native Linux or macOS file system.
@@ -1,6 +1,6 @@
1
1
  # Trust documents v1
2
2
 
3
- Status: draft, implemented by mago-ski 0.1. Test vectors: [`tests/vectors/`](../../tests/vectors/).
3
+ Status: draft, implemented by mago-ski 0.1 and later. Test vectors: [`tests/vectors/`](../../tests/vectors/).
4
4
 
5
5
  An organization's trust is anchored in one **root key**, kept offline. Hosts pin the root key's fingerprint (its key id). The root signs two documents: the trust root (who may approve what) and the revocation list (what is no longer trusted). Both are DSSE envelopes signed by the root key, in the same envelope format as [certificates](skill-certificate-v1.md), with canonical JSON payloads.
6
6
 
@@ -24,7 +24,7 @@ An organization's trust is anchored in one **root key**, kept offline. Hosts pin
24
24
 
25
25
  - `version`: positive integer, increased on every change. Hosts with a configured state file reject versions lower than those recorded there.
26
26
  - `root.public_key` must hash to `root.key_id`, which must equal the pinned fingerprint and the envelope's `keyid`.
27
- - `approvers`: sorted by `key_id`, unique, at most 256. The root key may not also be an approver.
27
+ - `approvers`: sorted by `key_id`, unique, at most 256. The root key may not also be an approver. With root recovery, a host also refuses (`UNVERIFIABLE`) a trust root that lists an approver whose key has held the root or timestamp role in the root events the host walked: `trust root lists approver <id>, which has held the root or timestamp role; a key that left those roles never takes another`. Only keys retired in events after `root_events_after` are known, and the gate trust store does not check it. Before upgrading, remove such approvers (see the CHANGELOG).
28
28
  - `scopes`: sorted, unique, 1–64 per approver. `*` matches every Skill name; `prefix*` matches names starting with `prefix`; anything else matches one exact name.
29
29
 
30
30
  ## Revocation list
@@ -72,10 +72,12 @@ Hand-edited JSON, read by hosts and the CLI. Paths are relative to the policy fi
72
72
  | `trust_root`, `revocations` | yes | Signed documents |
73
73
  | `certificate_dirs` | no | Extra certificate locations |
74
74
  | `skill_dirs` | no | Directories scanned by `verify-all` and the GitHub Action |
75
- | `state_file` | no | Rollback protection (below). Strongly recommended on hosts |
76
- | `decision_log` | no | JSON Lines file of decisions |
75
+ | `state_file` | no | Rollback protection (below). Strongly recommended on hosts. Must resolve to a file inside the policy file's directory |
76
+ | `decision_log` | no | JSON Lines file of decisions, one JSON object per line. Must resolve to a file inside the policy file's directory (after following symbolic links); it is opened without following symbolic links and must be a regular file. Records are data, not shell syntax: do not source them |
77
77
 
78
- The policy itself decides who is trusted, so it must live where the code under review cannot change it. The Pi host reads it only from `MAGO_SKI_POLICY` or `~/.mago-ski/policy.json`; the GitHub Action reads it from the pull request's base revision.
78
+ Policy `mago.policy/v2` adds `recovery`, `root_events`, `root_events_after` and `freshness` for root recovery; see [Host policy v2](root-recovery-v1.md#host-policy-v2). Without `recovery`, a v2 policy behaves exactly as v1. `root_events` and `freshness.timestamp` are inputs too: `state_file` and `decision_log` must not be either of them.
79
+
80
+ The policy itself decides who is trusted, so it must live where the code under review cannot change it. The Pi host and the CLI read it only from `MAGO_SKI_POLICY` (an absolute path) or `~/.mago-ski/policy.json`, and the CLI also accepts an explicit `--policy FILE`; the GitHub Action reads it from the pull request's base revision.
79
81
 
80
82
  ## Host state (rollback protection)
81
83
 
@@ -87,6 +89,8 @@ Canonical JSON written by the host:
87
89
 
88
90
  The host records the highest versions it has accepted for each root and rejects older documents as `UNVERIFIABLE` (rollback). Without a state file, a host can be given an older, still-unexpired trust root or revocation list.
89
91
 
92
+ With root recovery, the host writes `mago.host-state/v2`, which adds the root event progress per pinned root and the timestamp version per timestamp key ([Rollback and forks](root-recovery-v1.md#rollback-and-forks)). A host keeps writing v1 until it applies its first root event or timestamp, and never goes back to v1 once it has written v2.
93
+
90
94
  ## Decision log
91
95
 
92
96
  One JSON object per line:
@@ -97,7 +101,9 @@ One JSON object per line:
97
101
 
98
102
  `action` is `allow`, `block` or `would-block` (shadow mode). `certificate_id` is the SHA-256 of the certificate file.
99
103
 
104
+ A failure of the trust documents (trust root, revocation list, root event log or timestamp) affects every Skill, so hosts write **one** record when it starts or changes, instead of one per Skill: `event` is `root-revoked` or `trust-unavailable`, `skill` and `skill_dir` are empty, `digest` and `certificate_id` are null, and `verdict` is `UNVERIFIABLE`. `root-revoked` is always `block`, in shadow mode too ([Revoked root](root-recovery-v1.md#revoked-root-blocked-in-every-mode)).
105
+
100
106
  ## Key rotation
101
107
 
102
108
  - **Approver keys:** add the new key (`root add-approver`), re-approve the Skills, then remove the old key (`root remove-approver`). Certificates from a removed approver stop verifying once a host reads the updated trust root; revoke the old key instead if it may be compromised.
103
- - **Root key:** not implemented in v1. Planned design: the new root's first trust root is also signed by the old root, and hosts that pin the old fingerprint accept the new one only through that cross-signed document. Until then, replacing the root means distributing a new fingerprint to every host.
109
+ - **Root key:** with a v2 policy and a recovery set, the root key is revoked and replaced by root events signed by recovery keys, without editing host policies: [Root recovery v1](root-recovery-v1.md). After a rotate, `mago-ski root adopt` re-signs the trust documents with the new root. With a v1 policy, replacing the root still means distributing a new fingerprint to every host.
@@ -1,6 +1,6 @@
1
1
  # Verification
2
2
 
3
- Status: draft, implemented by mago-ski 0.1 (`src/verify.ts`). Verdict test vectors: [`tests/vectors/cases.json`](../../tests/vectors/cases.json).
3
+ Status: draft, implemented by mago-ski 0.1 and later (`src/verify.ts`). Verdict test vectors: [`tests/vectors/cases.json`](../../tests/vectors/cases.json).
4
4
 
5
5
  ## Verdicts
6
6
 
@@ -14,11 +14,18 @@ Status: draft, implemented by mago-ski 0.1 (`src/verify.ts`). Verdict test vecto
14
14
  | `EXPIRED` | The certificate, the approver key, the trust root or the revocation list has expired | Renew the expired item |
15
15
  | `UNVERIFIABLE` | Something could not be checked: malformed or tampered documents, a trust root not signed by the pinned key, rollback, unreadable Skill files | Fix the input; treat as blocked |
16
16
 
17
- Every verdict except `VERIFIED` blocks on supported hosts in enforce mode. Shadow mode allows it and records `would-block` in the decision log when one is configured (the GitHub Action reports instead).
17
+ Every verdict except `VERIFIED` blocks on supported hosts in enforce mode. Shadow mode allows it and records `would-block` in the decision log when one is configured (the GitHub Action reports instead). One exception: a root key revoked by a root event blocks in shadow mode too ([Revoked root](root-recovery-v1.md#revoked-root-blocked-in-every-mode)).
18
18
 
19
19
  ## Order of checks
20
20
 
21
- Trust documents, once per host check:
21
+ Trust documents, once per host check. With root recovery (a v2 policy with `recovery`), these come first ([Order of checks](root-recovery-v1.md#order-of-checks)):
22
+
23
+ - Walk the root event log from the policy's starting keys. A missing, malformed or invalid log is `UNVERIFIABLE`.
24
+ - Check the log against the host state: fewer events than already applied (rollback) or a different event at the recorded number (fork) is `UNVERIFIABLE`.
25
+ - If the active root is revoked, every Skill is blocked, **in shadow mode too**; nothing else is read.
26
+ - With `freshness`, the timestamp must be signed by the active timestamp key, unexpired, within `max_lifetime`, not older than the host state records, and must name exactly the files read. Otherwise `UNVERIFIABLE`.
27
+
28
+ The steps below then use the **active root** (the pinned root, replaced by each rotate event) instead of the pinned fingerprint, and the trust root is also `UNVERIFIABLE` if an approver is a recovery key or the active timestamp key.
22
29
 
23
30
  1. The trust root's envelope is signed by the pinned root fingerprint, names that root, and its signature is valid. Otherwise `UNVERIFIABLE`.
24
31
  2. The trust root has not expired. Otherwise `EXPIRED`.
@@ -41,6 +48,16 @@ Each certificate, for a Skill named `NAME` whose current tree digest is `D`:
41
48
 
42
49
  If any candidate is `VERIFIED`, the Skill is verified. Otherwise the result is the first match in this order: `REVOKED`, `UNAPPROVED_CHANGE`, `EXPIRED`, `UNTRUSTED_SIGNER`, `UNVERIFIABLE`, `NO_CERTIFICATE`.
43
50
 
51
+ ### Certificate candidate budget
52
+
53
+ Candidates come from the checkout under review, so they are bounded. They are read and evaluated one at a time, in the order explicit file, policy `certificate_dirs`, in-Skill file; only the best result so far is kept, and the first `VERIFIED` candidate ends the scan (later candidates are not read). Each candidate file is at most 8 MiB. For one Skill, at most 64 candidate files may exist and they may total at most 32 MiB; going over either limit, or any candidate that is not a regular non-symlink file, makes the Skill `UNVERIFIABLE` with a reason naming the limit.
54
+
44
55
  ## Skill name
45
56
 
46
57
  The name checked against the certificate is, in order: the name the host gives (the Pi host passes the name Pi loaded), the `name` field in `SKILL.md` frontmatter, or the directory name.
58
+
59
+ `SKILL.md` is read only if it is a regular, non-symlink file no larger than the tree collector's per-file limit (64 MiB), and the type and size are checked before any content is read. A symlinked, special or oversized `SKILL.md` makes the Skill `UNVERIFIABLE`.
60
+
61
+ ## Discovery budget
62
+
63
+ Hosts that scan `skill_dirs` (the GitHub Action and `mago-ski verify-all`) stop discovery when a root holds more than 1,000 Skills (directories reported as too deep and linked Skills count) or when more than 50,000 directory entries have been visited. Discovery then fails closed with a message instead of returning a partial list: `verify-all` exits non-zero with the message, and the GitHub Action reports one summary line and no per-Skill rows (failing the check in `enforce` mode, reported only in `shadow` mode). The Action summary lists at most 200 Skills, failures first, and says how many were not listed.