@mago-foundation/mago-ski 0.1.0 → 0.2.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.
@@ -0,0 +1,430 @@
1
+ # Root recovery v1
2
+
3
+ Status: **proposal, not implemented.** No released version of mago-ski reads the fields or documents described here. Once implemented, this page becomes normative and the changes listed under [Changes to other documents](#changes-to-other-documents) are applied.
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, no control characters. Shown in verdict reasons |
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
+
175
+ ### Rules for a revoke
176
+
177
+ - The key named in `root_key_id` must not already be revoked.
178
+ - After a revoke, the next event, if any, must be a rotate naming the same `root_key_id`.
179
+
180
+ ## Freshness
181
+
182
+ Optional, turned on per policy with `freshness`, and recommended for hosts in enforce mode.
183
+
184
+ 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.
185
+
186
+ ### Timestamp document
187
+
188
+ A DSSE envelope with exactly one signature, by the timestamp key.
189
+
190
+ `payloadType`: `application/vnd.mago-ski.timestamp+json`
191
+
192
+ ```json
193
+ {
194
+ "type": "mago.timestamp/v1",
195
+ "version": 412,
196
+ "issued_at": "2026-11-02T06:00:00Z",
197
+ "expires_at": "2026-11-03T06:00:00Z",
198
+ "timestamp_key": { "key_id": "sha256:<T>", "public_key": "<base64 DER SPKI>" },
199
+ "root_events": { "sha256": "<64 hex>", "count": 2 },
200
+ "trust_root": { "sha256": "<64 hex>", "version": 7 },
201
+ "revocations": { "sha256": "<64 hex>", "version": 31 }
202
+ }
203
+ ```
204
+
205
+ | Field | Meaning |
206
+ |---|---|
207
+ | `version` | Positive integer, increased with every timestamp |
208
+ | `issued_at` | Not more than 5 minutes in the future |
209
+ | `expires_at` | Later than `issued_at`, at most `max_lifetime` after it, and later than the host's current time |
210
+ | `timestamp_key` | Must be the active timestamp key (below); `public_key` must hash to `key_id`, which must equal the envelope's `keyid` |
211
+ | `root_events` | SHA-256 of the root event log file's bytes, and its number of events |
212
+ | `trust_root`, `revocations` | SHA-256 of each document file's bytes, and the `version` inside it |
213
+
214
+ ### What a host checks
215
+
216
+ The *active timestamp key* is `freshness.key_id`, replaced by each rotate event that carries `new_timestamp`. A host:
217
+
218
+ - reads each file once, and hashes and parses the same bytes;
219
+ - verifies the timestamp's signature with the active timestamp key;
220
+ - checks the times above and that `version` is not lower than the host state records;
221
+ - checks that the three digests, the event count and the two versions match the files it read.
222
+
223
+ Any failure is `UNVERIFIABLE`, and follows the configured mode (see [Reporting trust failures](#reporting-trust-failures-once)).
224
+
225
+ ### What it guarantees
226
+
227
+ - **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.
228
+ - **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.
229
+ - **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).
230
+
231
+ 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`.
232
+
233
+ ### Publishing
234
+
235
+ - 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.
236
+ - 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.
237
+ - 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.
238
+
239
+ ## Host processing
240
+
241
+ ### Walking the log
242
+
243
+ At every trust check, before reading the trust root, a host with a v2 recovery policy:
244
+
245
+ 1. Starts from the policy: *active root* = `root_fingerprint`, *recovery set* = `recovery`, *timestamp key* = `freshness.key_id`, *revoked* = false.
246
+ 2. Reads `root_events`. A missing, malformed or oversized log is `UNVERIFIABLE`.
247
+ 3. For each event after the first `root_events_after`, in order, checks every rule above against the current state, then applies it:
248
+ - revoke: *revoked* = true.
249
+ - rotate: *active root* = `new_root.key_id`, *recovery set* = `new_recovery`, *timestamp key* = `new_timestamp.key_id` if present, *revoked* = false.
250
+ 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.
251
+
252
+ 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.
253
+
254
+ ### Order of checks
255
+
256
+ 1. Walk the root event log. Otherwise `UNVERIFIABLE`.
257
+ 2. Check rollback and forks against the host state. Otherwise `UNVERIFIABLE`.
258
+ 3. If the active root is revoked, every Skill is blocked: see [Revoked root](#revoked-root-blocked-in-every-mode). Nothing else is read.
259
+ 4. With `freshness`, check the timestamp against the files. Otherwise `UNVERIFIABLE`.
260
+ 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 or is the active timestamp key.
261
+ 6. Record the new state.
262
+
263
+ ### Revoked root: blocked in every mode
264
+
265
+ When the active root is revoked:
266
+
267
+ - Every Skill is blocked, in **both `enforce` and `shadow` mode**. No policy setting changes this.
268
+ - 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`.
269
+ - The only way back is a rotate event. Switching the policy to shadow mode does not help.
270
+
271
+ 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.
272
+
273
+ 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.
274
+
275
+ ### Reporting trust failures once
276
+
277
+ 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**:
278
+
279
+ | Failure | Event name | Enforce mode | Shadow mode |
280
+ |---|---|---|---|
281
+ | The active root is revoked | `root-revoked` | block | **block** |
282
+ | Root event log missing or invalid, rollback, fork | `trust-unavailable` | block | would-block |
283
+ | Timestamp missing, invalid, expired or not matching the files | `trust-unavailable` | block | would-block |
284
+ | Trust root or revocation list invalid or expired (as in v1) | `trust-unavailable` | block | would-block |
285
+
286
+ While such a failure lasts:
287
+
288
+ - **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.
289
+ - **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.
290
+ - **CLI** (`verify`, `verify-all`, `policy check`): prints the failure once and exits non-zero.
291
+ - **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.
292
+
293
+ ### Rollback and forks
294
+
295
+ Host state version 2:
296
+
297
+ ```json
298
+ {
299
+ "type": "mago.host-state/v2",
300
+ "roots": { "sha256:<R1>": { "trust_root_version": 1, "revocations_version": 1 } },
301
+ "root_events": { "sha256:<R0>": { "sequence": 2, "event_digest": "sha256:<hex>" } },
302
+ "timestamps": { "sha256:<T>": { "version": 412 } }
303
+ }
304
+ ```
305
+
306
+ (Written as canonical JSON; shown indented here.)
307
+
308
+ - `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.
309
+ - **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.
310
+ - **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.
311
+ - **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.
312
+ - 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.
313
+
314
+ 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.
315
+
316
+ ## What each leak allows
317
+
318
+ With `k` = `rotate_threshold` and `r` = `revoke_threshold`:
319
+
320
+ | Leaked | The thief can | The organization |
321
+ |---|---|---|
322
+ | 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 |
323
+ | 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 |
324
+ | The root key and the timestamp key | As the root key on a host without freshness | Revoke, then rotate both keys |
325
+ | Fewer than `r` recovery keys | Nothing | Optionally rotates to a recovery set without the leaked keys |
326
+ | `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 |
327
+ | 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 |
328
+ | `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 |
329
+
330
+ 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.
331
+
332
+ ## Limits
333
+
334
+ | Item | Limit |
335
+ |---|---|
336
+ | Recovery keys per set | 16 |
337
+ | Events per log | 256 |
338
+ | Log file size | 4 MiB |
339
+ | Signatures per event | 34 (16 current + 16 new recovery keys + the new root + the new timestamp key) |
340
+ | `reason` | 1024 characters |
341
+ | Timestamp file size | 64 KiB |
342
+ | `max_lifetime` | 7 days |
343
+
344
+ ## Recommended setups
345
+
346
+ | Organization | Recovery set | Why |
347
+ |---|---|---|
348
+ | 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 |
349
+ | 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 |
350
+
351
+ 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.
352
+
353
+ 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.
354
+
355
+ ## Commands (informative)
356
+
357
+ Proposed CLI shape; names may change during implementation. 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:
358
+
359
+ ```
360
+ mago-ski recovery init --public-key a.pub --public-key b.pub --public-key c.pub \
361
+ --rotate-threshold 2 --revoke-threshold 1 # prints the policy "recovery" block
362
+ mago-ski root-events init --out root-events.json # empty log
363
+
364
+ # Revoke: one trustee is enough with revoke_threshold 1
365
+ mago-ski root-events prepare-revoke --events root-events.json --reason TEXT --out proposal.json
366
+ mago-ski root-events sign proposal.json --key a.pem
367
+ mago-ski root-events append proposal.json --events root-events.json
368
+
369
+ # Rotate: the new root and two trustees sign the same proposal
370
+ mago-ski root-events prepare-rotate --events root-events.json --new-root-public r1.pub \
371
+ [--new-recovery-public KEY.pub ... --rotate-threshold N --revoke-threshold N] \
372
+ [--new-timestamp-public t2.pub] --reason TEXT --out proposal.json
373
+ mago-ski root-events sign proposal.json --key r1.pem
374
+ mago-ski root-events sign proposal.json --key a.pem
375
+ mago-ski root-events sign proposal.json --key b.pem
376
+ mago-ski root-events append proposal.json --events root-events.json
377
+
378
+ # Freshness: run by the timestamp job every 6 hours
379
+ mago-ski timestamp sign --policy policy.json --key timestamp.pem --expires 24h
380
+ ```
381
+
382
+ `append` checks every rule a host would check, so a log that `append` accepts is a log hosts accept. `timestamp sign` reads the files the policy names, signs their digests with the next `version`, and writes the policy's `freshness.timestamp` file.
383
+
384
+ Before rolling a v2 policy out to hosts, or after appending an event, the organization checks it the way a host would:
385
+
386
+ ```
387
+ mago-ski policy check --policy policy.json
388
+ ```
389
+
390
+ `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.
391
+
392
+ ## Changes to other documents
393
+
394
+ When this is implemented:
395
+
396
+ - **[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.
397
+ - **[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.
398
+ - **[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.
399
+ - **[GitHub Action](../hosts/github-action.md):** a revoked root fails the check in shadow mode too, with one summary line.
400
+ - **[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.
401
+ - **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.
402
+
403
+ ## Rationale: TUF and KERI
404
+
405
+ Both TUF and KERI address key compromise, and their ideas are compatible; this design takes its structure from TUF and one idea from KERI.
406
+
407
+ **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.
408
+
409
+ **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.
410
+
411
+ **What KERI would add, and why this design does not take it.**
412
+
413
+ - *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.
414
+ - *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.
415
+ - *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.
416
+
417
+ **Alternatives considered.**
418
+
419
+ - *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.
420
+ - *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.
421
+ - *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.
422
+ - *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.
423
+ - *A revoked root that follows the mode.* Rejected: see [Revoked root](#revoked-root-blocked-in-every-mode).
424
+
425
+ **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`.
426
+
427
+ ## Open questions
428
+
429
+ 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?
430
+ 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
 
@@ -72,10 +72,10 @@ 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
+ 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
79
 
80
80
  ## Host state (rollback protection)
81
81
 
@@ -100,4 +100,4 @@ One JSON object per line:
100
100
  ## Key rotation
101
101
 
102
102
  - **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.
103
+ - **Root key:** not implemented in v1; replacing the root means distributing a new fingerprint to every host. Proposed design, which also covers a leaked root key: [Root recovery v1](root-recovery-v1.md).
@@ -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
 
@@ -41,6 +41,16 @@ Each certificate, for a Skill named `NAME` whose current tree digest is `D`:
41
41
 
42
42
  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
43
 
44
+ ### Certificate candidate budget
45
+
46
+ 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.
47
+
44
48
  ## Skill name
45
49
 
46
50
  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.
51
+
52
+ `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`.
53
+
54
+ ## Discovery budget
55
+
56
+ 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.
@@ -16,6 +16,7 @@ mago-ski answers one question: **is the Skill this agent is about to use the exa
16
16
  | **Hiding the instructions from the digest**: `.skilldigestignore` listing `SKILL.md` | Rejected. `SKILL.md` is always covered, and certificates without it are `UNVERIFIABLE` |
17
17
  | **Exposing uncovered files**: `.git`, ignored files, or an unused in-tree certificate file in a verified Skill | The Pi host refuses `read` of any file not in the certificate and refuses `grep` over Skills that have excluded files. The in-tree certificate counts as safe only when it is the certificate that verified the Skill |
18
18
  | **Symlinks**: a linked Skill directory, a linked `SKILL.md`, or a link inside a Skill pointing elsewhere | Digests reject symlinks. Discovery (CLI, GitHub Action) reports linked Skills as `UNVERIFIABLE` instead of skipping them, and fails rather than skipping Skills deeper than its search limit. The Pi host matches tool paths both before and after resolving links |
19
+ | **Names outside the digest**: a contributor renames a verified Skill's directory, or names files inside an unverified Skill, so that the text reaches the model | The directory path is not covered by the certificate. The Pi host shows a Skill's path to the model only if it is plainly spelled (see the [Pi host](hosts/pi.md)), and removes entries of unverified Skills from `find` and `ls` results |
19
20
  | **Path aliases**: `@/path`, `file://` URLs, Unicode spaces or filename variants that Pi's tools resolve to a Skill file | The Pi host resolves tool paths the same way Pi's tools do before matching them |
20
21
  | **Verification errors** | The Pi host fails closed in enforce mode: a Skill that cannot be checked is `UNVERIFIABLE`, and if checking crashes outright, file and shell tools that touch any Skill path are blocked |
21
22
  | **Pull request trusting itself**: a PR adds its own root or approver | The GitHub Action reads policy, trust root and revocation list from the protected base revision |
@@ -25,12 +26,12 @@ mago-ski answers one question: **is the Skill this agent is about to use the exa
25
26
 
26
27
  - **Malicious first versions and fooled reviewers.** A certificate records a decision; it does not make the decision correct. Review quality is the organization's job.
27
28
  - **Prompt injection at runtime.** A verified Skill can still be steered by untrusted data it reads (the confused-deputy problem). Runtime evaluation of tool calls against the approved contract is a separate layer (Mago's CLEAR), not part of mago-ski.
28
- - **Shell commands that reach Skill files indirectly.** In Pi, `bash` and `powershell` are checked by matching Skill paths in the command text. Relative paths after `cd`, globs, variables or encoded paths can evade it. In enforce mode, the guarantees that hold are: unverified Skills are not advertised, `/skill:` cannot load them, and the structured file tools (`read`, `grep`, `edit`, `write`, `find`, `ls`) refuse their files. `find` and `ls` may still list file names inside verified Skills.
29
+ - **Shell commands that reach Skill files indirectly.** In Pi, `bash` and `powershell` are checked by matching Skill paths in the command text. Relative paths after `cd`, globs, variables or encoded paths can evade it. In enforce mode, the guarantees that hold are: unverified Skills are not advertised, `/skill:` cannot load them, and the structured file tools (`read`, `grep`, `edit`, `write`, `find`, `ls`) refuse their files. `find` and `ls` may still list file names inside verified Skills; in an unverified Skill they are removed from the results (a `bash` `ls` or `find` is not filtered). Names of files a verified Skill excludes from its certificate can still appear.
29
30
  - **Other code in the agent process.** A hostile Pi extension, MCP server or custom tool runs with the same permissions as mago-ski and can read files directly or change the Skill list after mago-ski filters it. Load mago-ski last and only trusted extensions.
30
31
  - **A compromised host.** Root or same-user malware can change files, the policy, the state file or the extension itself. This includes racing directory replacement between path resolution and reading; the digest re-checks file identity, but a same-user attacker controls the file system.
31
- - **A compromised root key.** Everything chains to it. Keep it offline. Root key rotation is designed but not implemented in v1.
32
+ - **A compromised root key.** Everything chains to it. Keep it offline. Recovery from a leaked root key is proposed in [Root recovery v1](spec/root-recovery-v1.md) but not implemented.
32
33
  - **Files excluded from the digest** (`.skilldigestignore`, root `.git`) are not approved. The Pi host refuses to read them from a verified Skill, but other tools may still use them.
33
- - **Windows.** Not supported in 0.1. Windows has no POSIX executable bit, so it cannot reproduce Linux and macOS digests; see the [digest spec](spec/skill-tree-v2.md).
34
+ - **Windows.** Not supported yet. Windows has no POSIX executable bit, so it cannot reproduce Linux and macOS digests; see the [digest spec](spec/skill-tree-v2.md).
34
35
 
35
36
  ## Revocation timing
36
37
 
@@ -39,6 +40,6 @@ Revocation is not instant everywhere. A host acts on a revocation once it reads
39
40
  ## Assumptions
40
41
 
41
42
  - The root private key is offline and only its holder can sign trust documents.
42
- - Approver private keys are kept by the people they name; `approve` refuses a key stored inside the Skill directory.
43
- - The host policy, trust documents and state file are writable only by the user or administrator, not by the code under review. The Pi host never reads policy from the project directory.
43
+ - Approver private keys are kept by the people they name; `approve` refuses a key stored inside the Skill directory, and refuses a Skill that contains private-key material in a recognizable format (PEM, PKCS#8, OpenSSH and SSH2 private keys, PGP private key blocks, PuTTY `.ppk` files and age secret keys). This is a best-effort check for accidents, not a general secret scanner.
44
+ - The host policy, trust documents and state file are writable only by the user or administrator, not by the code under review. Neither the Pi host nor the CLI reads policy from the project directory (the CLI uses `--policy`, `MAGO_SKI_POLICY` or `~/.mago-ski/policy.json`). The policy may place `decision_log` and `state_file` only inside its own directory.
44
45
  - Clocks are roughly correct (5 minutes of skew is tolerated for issue times).