@krysoworks/kryso 0.0.2 → 2.0.0-rc.1
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.
- package/LICENSE +21 -0
- package/README.md +146 -6
- package/bin/kryso +31 -0
- package/bin/ship-it-status +14 -0
- package/bin/ship-ledger +14 -0
- package/bin/ship-loop +14 -0
- package/bin/ship-pass +14 -0
- package/bin/warden +14 -0
- package/dist/answer.d.ts +38 -0
- package/dist/answer.js +48 -0
- package/dist/bytes.d.ts +5 -0
- package/dist/bytes.js +35 -0
- package/dist/cleanup.d.ts +1 -0
- package/dist/cleanup.js +629 -0
- package/dist/commands.d.ts +48 -0
- package/dist/commands.js +293 -0
- package/dist/completions.d.ts +24 -0
- package/dist/completions.js +239 -0
- package/dist/daemon.d.ts +15 -0
- package/dist/daemon.js +23 -0
- package/dist/diagnose.d.ts +47 -0
- package/dist/diagnose.js +314 -0
- package/dist/doctor.d.ts +1 -0
- package/dist/doctor.js +241 -0
- package/dist/env.d.ts +9 -0
- package/dist/env.js +17 -0
- package/dist/evidence.d.ts +39 -0
- package/dist/evidence.js +327 -0
- package/dist/home.d.ts +3 -0
- package/dist/home.js +27 -0
- package/dist/install.d.ts +59 -0
- package/dist/install.js +137 -0
- package/dist/isolate.d.ts +28 -0
- package/dist/isolate.js +402 -0
- package/dist/leftovers.d.ts +5 -0
- package/dist/leftovers.js +156 -0
- package/dist/machine.d.ts +6 -0
- package/dist/machine.js +185 -0
- package/dist/palette.d.ts +147 -0
- package/dist/palette.js +167 -0
- package/dist/plan.d.ts +1 -0
- package/dist/plan.js +133 -0
- package/dist/proc.d.ts +23 -0
- package/dist/proc.js +23 -0
- package/dist/read.d.ts +1 -0
- package/dist/read.js +297 -0
- package/dist/readiness.d.ts +5 -0
- package/dist/readiness.js +64 -0
- package/dist/remote.d.ts +6 -0
- package/dist/remote.js +85 -0
- package/dist/self-update.d.ts +1 -0
- package/dist/self-update.js +224 -0
- package/dist/semver.d.ts +7 -0
- package/dist/semver.js +42 -0
- package/dist/style.d.ts +71 -0
- package/dist/style.js +187 -0
- package/dist/update.d.ts +47 -0
- package/dist/update.js +190 -0
- package/dist/work.d.ts +25 -0
- package/dist/work.js +449 -0
- package/dist/workflows.d.ts +4 -0
- package/dist/workflows.js +73 -0
- package/docker/entrypoint.sh +44 -0
- package/docker/runner.Dockerfile +39 -0
- package/package.json +55 -22
- package/scripts/install-skills.sh +607 -0
- package/skills/code-review/SKILL.md +231 -0
- package/skills/kryso/SKILL.md +107 -0
- package/skills/kryso/golden/help.rounded.ansi +23 -0
- package/skills/kryso/golden/help.square.ansi +23 -0
- package/skills/kryso/golden/help.txt +23 -0
- package/skills/kryso/golden/table-narrow.json +11 -0
- package/skills/kryso/golden/table-narrow.rounded.ansi +4 -0
- package/skills/kryso/golden/table-narrow.square.ansi +4 -0
- package/skills/kryso/golden/table.ansi +5 -0
- package/skills/kryso/golden/table.json +11 -0
- package/skills/kryso/ledger.sh +2146 -0
- package/skills/kryso/palette.json +57 -0
- package/skills/kryso/reference/resuming.md +30 -0
- package/skills/kryso/reference/routing.md +23 -0
- package/skills/kryso/reference/stage-1-claim.md +79 -0
- package/skills/kryso/reference/stage-2-build.md +133 -0
- package/skills/kryso/reference/stage-3-prove.md +51 -0
- package/skills/kryso/reference/stage-4-pr.md +76 -0
- package/skills/kryso/reference/stage-5-reconcile.md +81 -0
- package/skills/kryso/reference/stage-6-merge-or-park.md +73 -0
- package/skills/kryso/reference/stage-7-close-out.md +62 -0
- package/skills/kryso/reference/terminal.md +7 -0
- package/skills/kryso/ship-it-status.sh +1503 -0
- package/skills/kryso/ui.py +274 -0
- package/skills/kryso/ui.sh +609 -0
- package/skills/kryso-build/SKILL.md +168 -0
- package/skills/kryso-shift/SKILL.md +167 -0
- package/skills/kryso-shift/archive.py +2784 -0
- package/skills/kryso-shift/archive_checker.py +462 -0
- package/skills/kryso-shift/archive_checker_lambda.py +155 -0
- package/skills/kryso-shift/archive_health.py +364 -0
- package/skills/kryso-shift/archive_launchd.py +140 -0
- package/skills/kryso-shift/archive_remote.py +990 -0
- package/skills/kryso-shift/archiving-checker.md +140 -0
- package/skills/kryso-shift/archiving-keep.md +115 -0
- package/skills/kryso-shift/archiving-recovery.md +112 -0
- package/skills/kryso-shift/archiving-remote.md +166 -0
- package/skills/kryso-shift/archiving.md +146 -0
- package/skills/kryso-shift/coverage.schema.json +225 -0
- package/skills/kryso-shift/deadline.sh +254 -0
- package/skills/kryso-shift/feedback.schema.json +35 -0
- package/skills/kryso-shift/feedback.sh +228 -0
- package/skills/kryso-shift/history-manifest.schema.json +331 -0
- package/skills/kryso-shift/keep-after.sh +55 -0
- package/skills/kryso-shift/measure.sh +611 -0
- package/skills/kryso-shift/merge-ready.sh +207 -0
- package/skills/kryso-shift/outcome.schema.json +16 -0
- package/skills/kryso-shift/pass-rules.md +8 -0
- package/skills/kryso-shift/profile.schema.json +42 -0
- package/skills/kryso-shift/reader.sh +692 -0
- package/skills/kryso-shift/reads.sh +151 -0
- package/skills/kryso-shift/reference/allowance.md +21 -0
- package/skills/kryso-shift/reference/driver.md +95 -0
- package/skills/kryso-shift/reference/measuring.md +67 -0
- package/skills/kryso-shift/reference/outputs.md +21 -0
- package/skills/kryso-shift/reference/pass-script.md +115 -0
- package/skills/kryso-shift/reference/reconcile-and-merge.md +55 -0
- package/skills/kryso-shift/reference/second-reader.md +9 -0
- package/skills/kryso-shift/reference/sweeps.md +83 -0
- package/skills/kryso-shift/repair.schema.json +14 -0
- package/skills/kryso-shift/report-template.html +679 -0
- package/skills/kryso-shift/report.py +389 -0
- package/skills/kryso-shift/report_fixture.py +65 -0
- package/skills/kryso-shift/reporting.md +58 -0
- package/skills/kryso-shift/result.sh +91 -0
- package/skills/kryso-shift/runner.sh +1178 -0
- package/skills/kryso-shift/ship-loop.sh +3977 -0
- package/skills/kryso-shift/ship-pass.sh +4987 -0
- package/skills/kryso-shift/steps.jq +19 -0
- package/skills/kryso-shift/workflow.mjs +830 -0
- package/skills/kryso-shift/workflows/default.json +22 -0
- package/skills/kryso-shift/workflows/ralph.json +13 -0
- package/skills/kryso-watch/SKILL.md +100 -0
- package/skills/kryso-watch/answer.schema.json +23 -0
- package/skills/kryso-watch/base-refs.sh +44 -0
- package/skills/kryso-watch/board.sh +58 -0
- package/skills/kryso-watch/reference/config.md +23 -0
- package/skills/kryso-watch/reference/outputs.md +30 -0
- package/skills/kryso-watch/reference/report.md +29 -0
- package/skills/kryso-watch/reference/scheduler.md +32 -0
- package/skills/kryso-watch/reference/settlement.md +29 -0
- package/skills/kryso-watch/reference/shift.md +44 -0
- package/skills/kryso-watch/reference/shim-limits.md +22 -0
- package/skills/kryso-watch/reference/triage.md +26 -0
- package/skills/kryso-watch/schema.jq +40 -0
- package/skills/kryso-watch/settle.schema.json +36 -0
- package/skills/kryso-watch/stage-common.sh +187 -0
- package/skills/kryso-watch/stages/report.sh +525 -0
- package/skills/kryso-watch/stages/settle.sh +722 -0
- package/skills/kryso-watch/stages/shift.sh +466 -0
- package/skills/kryso-watch/stages/triage.sh +379 -0
- package/skills/kryso-watch/tracker.sh +27 -0
- package/skills/kryso-watch/triage.schema.json +77 -0
- package/skills/kryso-watch/warden.launchd.plist +50 -0
- package/skills/kryso-watch/warden.schema.json +98 -0
- package/skills/kryso-watch/warden.sh +1004 -0
- package/bin/kryso.js +0 -11
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# Checking the archive from outside the Mac
|
|
2
|
+
|
|
3
|
+
The checker tells the owner that evidence has stopped reaching the bucket, including when the Mac itself is off, asleep or gone. It is an AWS Lambda in the bucket's own account and region, invoked every ten minutes by an EventBridge Scheduler schedule. Each check lists the bucket's recent health snapshots with a read-only grant of its own, judges the newest one it can trust, appends a check record to a CloudWatch Logs group it can only append to, and emails the owner through the SNS topic `evidence-archive-alerts` when the state changes. It keeps working when both the Mac and the netcup box are down, no long-lived credential leaves AWS, and the age identity never comes near it.
|
|
4
|
+
|
|
5
|
+
What a keep publishes, and how `archive.py health` selects a snapshot, is in [archiving-keep.md](archiving-keep.md#health-snapshots). The checker selects one with the same code, because both call `archive_health.py`.
|
|
6
|
+
|
|
7
|
+
## What a check reports
|
|
8
|
+
|
|
9
|
+
| State | When |
|
|
10
|
+
| --- | --- |
|
|
11
|
+
| `healthy` | The newest snapshot it trusts was published in the last 30 minutes, and no archive snapshot has waited in the upload queue longer than that. |
|
|
12
|
+
| `stale` | No health snapshot was published in the last 30 minutes: keeps have stopped, or they run and their health snapshots no longer reach the bucket. |
|
|
13
|
+
| `backlog` | Health snapshots still arrive, but the oldest snapshot pending upload was queued more than 30 minutes ago: keeps run and their uploads fail. |
|
|
14
|
+
| `unknown` | Nothing it can trust: no health snapshot in the days it looks back, a newer one whose bytes do not match its name or that does not parse as a health snapshot, or one published more than 5 minutes ahead of the checker's clock. |
|
|
15
|
+
| `failed` | The bucket could not be listed or a snapshot could not be read. |
|
|
16
|
+
|
|
17
|
+
`judge` in [archive_health.py](archive_health.py) sets the order the states are tried in and what each check record reports. A missing, unreadable or mismatched snapshot is never healthy. A check looks back 7 days, and further when a quiet window needs it. It lists the next UTC day as well, where a keep whose clock runs a few minutes ahead publishes just before midnight.
|
|
18
|
+
|
|
19
|
+
## Check records
|
|
20
|
+
|
|
21
|
+
Every check appends one `ship-archive-check/1` record and never changes one:
|
|
22
|
+
|
|
23
|
+
| Field | What it holds |
|
|
24
|
+
| --- | --- |
|
|
25
|
+
| `at`, `state`, `reasons` | When the check ran, its state, and one sentence per reason it is not healthy. |
|
|
26
|
+
| `health` | The snapshot it trusted: its object name, when it was published and how many minutes before the check, the keep's `at` and `host`, and the counts of `gaps` and `errors` it carried. Null when there is none. |
|
|
27
|
+
| `stale`, `backlog` | Whether the snapshot is too old, and the upload queue it reported: `pending`, `pending_bytes`, `oldest_pending`, how long that one has waited, and whether it is `overdue`, queued more than 30 minutes ago. |
|
|
28
|
+
| `rejected` | Every key newer than the trusted snapshot, with why it was passed over. A key that is no health snapshot's name is listed here and changes nothing else, because it is not a snapshot. |
|
|
29
|
+
| `quiet` | The quiet window that applies, or null. |
|
|
30
|
+
| `alert` | The alert this check sent: `kind` (`change`, `reminder` or null), `status` (`sent`, `failed` or `none`), the topic's message id, or the error. |
|
|
31
|
+
| `announced` | The state the owner was last told about, and when, carried forward from record to record. |
|
|
32
|
+
| `errors` | The checker's own problems: a journal it could not read, or this record not being appended. |
|
|
33
|
+
|
|
34
|
+
The deployed journal is the log group `evidence-archive-checks`, one stream per UTC day, with no retention policy, so no record expires, written by a role that can only append to it, as [Deploy](#deploy) lists. A failed alert is recorded on its check, beside a state that is exactly what it would have been had the alert gone out. Neither the state nor the alert is a backup outcome or a delivery outcome: the checker writes no archive, no queue, no pass record and no tracker.
|
|
35
|
+
|
|
36
|
+
## Alerts
|
|
37
|
+
|
|
38
|
+
A check alerts on a change of state, into `stale`, `backlog`, `unknown` or `failed` and back to `healthy`, and once a day while a state other than healthy lasts, counted from the last alert that was sent. It sends nothing else, so a state that holds is one email a day, not one per check. A first check with nothing announced before it counts the last announcement as healthy, so a healthy start sends nothing. An alert that fails to send leaves what was announced as it was, and the next check sends it again. The subjects are `Evidence archive <state>`, `Evidence archive still <state>` for a reminder and `Evidence archive healthy again`.
|
|
39
|
+
|
|
40
|
+
## The checker configuration
|
|
41
|
+
|
|
42
|
+
A JSON file, with relative paths taken from its own directory:
|
|
43
|
+
|
|
44
|
+
```json
|
|
45
|
+
{
|
|
46
|
+
"remote": "remote.json",
|
|
47
|
+
"quiet": [
|
|
48
|
+
{ "from": "2026-10-10T08:00:00Z", "until": "2026-10-12T20:00:00Z", "reason": "the Mac is in for repair" }
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`remote` names a [remote configuration](archiving-remote.md#the-remote-configuration) that `archive.py check` passes. For an `s3` remote, its account, region, bucket and prefix are where the checker is deployed and what it reads. For a `local` remote, `journal` and `alerts` name the directories the check records and the alerts go to, which is how the tests run it. Any other key is refused.
|
|
54
|
+
|
|
55
|
+
### Quiet windows
|
|
56
|
+
|
|
57
|
+
Expected downtime is configuration. By default there is none: the Mac is always expected to run, because shifts run overnight. Each window in `quiet` is a UTC span from `from` up to but not including `until`, with the `reason` the checker reports while it applies. Inside one, a stale state is recorded with `quiet` set and sends nothing. A window explains a Mac that is off and nothing else, so `failed`, `unknown` and `backlog` still alert inside one. When it ends with the Mac still silent, the next check sends the stale alert at once. While a window applies, and for 7 days after it ends, a check looks back to the day before it began, so a declared outage longer than 7 days still reads stale rather than `unknown`. An undeclared silence longer than 7 days reads `unknown`.
|
|
58
|
+
|
|
59
|
+
## Verbs
|
|
60
|
+
|
|
61
|
+
| Verb | What it does | Exit |
|
|
62
|
+
| --- | --- | --- |
|
|
63
|
+
| `checker run --config <file> [--now <time>]` | One check against a local remote, at `--now` if given. Prints the record. An s3 remote is refused, because its checker is the Lambda. | 0 healthy, recorded, with no failed alert and no error of its own, 1 otherwise |
|
|
64
|
+
| `checker provision --config <file>` | Prints the script that deploys the checker. Runs nothing. | 0, or 1 when not ready |
|
|
65
|
+
| `checker audit --config <file>` | Reads the deployment as the operator's own credentials and lists every way it differs from that script, holding the subscription to `ALERT_EMAIL` when that is set. | 0 matches, 1 differs |
|
|
66
|
+
| `checker package --out <zip>` | Writes the Lambda's deployment package: `archive_health.py` and `archive_checker_lambda.py`, stored with fixed times, so one checkout always makes the same bytes. | 0 |
|
|
67
|
+
|
|
68
|
+
## Deploy
|
|
69
|
+
|
|
70
|
+
Prerequisites: the remote is provisioned and audited as [the runbook](archiving-remote.md#runbook-the-first-real-round-trip) says, the `aws` CLI is authenticated as an administrator of the account, and the alert address is to hand. None of the names below is configurable, because an account holds one checker.
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
python3 ~/.agents/skills/kryso-shift/archive.py checker provision --config ~/ship-archive/checker.json > deploy-checker.sh
|
|
74
|
+
less deploy-checker.sh
|
|
75
|
+
ALERT_EMAIL=<address> bash deploy-checker.sh
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The script stops unless `ALERT_EMAIL` is set and the CLI's account is the remote's. The address goes to SNS and to no file. A rerun with another address subscribes that one too, and the audit reports the second subscription until the old one is unsubscribed with `aws sns unsubscribe --subscription-arn <arn>`, the ARN read from `aws sns list-subscriptions-by-topic`. The script creates, or updates when it runs again:
|
|
79
|
+
|
|
80
|
+
- the topic `evidence-archive-alerts`, with an email subscription for the address
|
|
81
|
+
- the log group `evidence-archive-checks`, with no retention policy
|
|
82
|
+
- the role `evidence-archive-checker`, which Lambda assumes: `s3:ListBucket` on the bucket for keys under `<prefix>health/` only, `s3:GetObject` on `<prefix>health/*` and nothing else in it, `sns:Publish` on the topic, stream and event access on the journal with every delete and retention action on it denied, and its own function log
|
|
83
|
+
- the role `evidence-archive-checker-schedule`, which Scheduler assumes for this account only, allowed `lambda:InvokeFunction` on the function and nothing else
|
|
84
|
+
- the function `evidence-archive-checker`: Python 3.13, 60 seconds, 128 MB, the package `checker package` writes, its settings in the `ARCHIVE_CHECKER` environment variable, and no retry of a failed invocation, since the next check comes ten minutes later
|
|
85
|
+
- the schedule `evidence-archive-check`, `rate(10 minutes)`
|
|
86
|
+
|
|
87
|
+
Neither role holds anything that writes to the bucket or decrypts. The recovery role is not reused: it exists for restores. The checker's `ListBucket` carries an `s3:prefix` condition, `StringLike` on `<prefix>health/*`, because the credential runs away from the Mac and should not name keys outside the health snapshots, which is all a check lists. The uploader's grant stays unconditional for the reason [archiving-remote.md](archiving-remote.md#provisioning) gives. The condition costs the checker one thing: without an unconditional `ListBucket`, a `GetObject` for a key that is not there answers 403 rather than 404. A health snapshot deleted between a check's list and its read therefore reads `failed` instead of `unknown`. Neither is ever healthy. The uploader can neither replace nor delete an object, so only an administrator's delete can cause that race, and the checker does not work around it.
|
|
88
|
+
|
|
89
|
+
The topic's ARN is `arn:aws:sns:<region>:<account>:evidence-archive-alerts`. #317's budget alert publishes to the same topic, so one subscription carries both. The audit does not read the topic's access policy, so the statement #317 adds to it for AWS Budgets is not reported as drift.
|
|
90
|
+
|
|
91
|
+
`checker audit` reads the two roles, the function with its layers, resource policy and invoke configuration, the schedule, the topic and its subscriptions, and the log group, and holds each to what the script writes. An extra statement, policy, managed policy, layer, resource policy statement, environment variable, setting or retention policy is a problem however harmless it looks, and running the script again is the fix: a rerun deletes the inline policies and detaches the managed policies it did not write, empties the function's layers and resource policy, and removes the journal's retention policy. Subscriptions are the exception, because the script adds the owner's and removes none. The audit reports every subscription that is not email and every email one past the first, which are unsubscribed by hand as above. With `ALERT_EMAIL` set, it also reports when no subscription is for that address, and prints the address nowhere. The deployed code is compared by hash with this checkout's package. A read the operator is refused stops the audit with an error instead of passing what it could not see.
|
|
92
|
+
|
|
93
|
+
## Activation checklist
|
|
94
|
+
|
|
95
|
+
The owner runs this once, after #317's keep agent is running. Keep every command's output. The `aws` commands below and under [Remove](#remove) take the account from the environment, so first set it to the remote configuration's `region` and `profile`, leaving `AWS_PROFILE` out when it names none. The script's last line prints this for you:
|
|
96
|
+
|
|
97
|
+
```sh
|
|
98
|
+
export AWS_REGION=us-east-1 AWS_PROFILE=evidence-admin
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
1. Deploy as above.
|
|
102
|
+
2. Open the email from AWS Notifications and confirm the subscription. `ALERT_EMAIL=<address> python3 ~/.agents/skills/kryso-shift/archive.py checker audit --config ~/ship-archive/checker.json` must print `"problems": []`.
|
|
103
|
+
3. See `healthy`. Invoke the function, which runs a real check and records it:
|
|
104
|
+
|
|
105
|
+
```sh
|
|
106
|
+
aws lambda invoke --function-name evidence-archive-checker /dev/stdout
|
|
107
|
+
aws logs tail evidence-archive-checks --since 30m
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
4. Stop the keep with `python3 ~/.agents/skills/kryso-shift/archive.py launchd remove`, and note the time.
|
|
111
|
+
5. Within 40 minutes, the journal shows `stale` and an email titled `Evidence archive stale` arrives: 30 minutes for the newest snapshot to age, and up to 10 for the next check.
|
|
112
|
+
6. Reinstall the keep with `python3 ~/.agents/skills/kryso-shift/archive.py launchd install --config ~/ship-archive/keep.json`. Within ten minutes of its first keep, the journal shows `healthy` and an email titled `Evidence archive healthy again` arrives.
|
|
113
|
+
7. Save the commands and their outputs from steps 2 to 6 in `docs/reviews/<date>-archive-checker-activation.md`.
|
|
114
|
+
|
|
115
|
+
## Silence a known outage
|
|
116
|
+
|
|
117
|
+
Add a window to `quiet` in the checker configuration, then run the provisioning script again, which updates the function's settings in place. `checker audit` reports the difference until it has run. While the window applies, the checker records the stale state with the window's reason and sends nothing. Old windows can stay: one that has ended applies to nothing.
|
|
118
|
+
|
|
119
|
+
## Remove
|
|
120
|
+
|
|
121
|
+
```sh
|
|
122
|
+
aws scheduler delete-schedule --name evidence-archive-check
|
|
123
|
+
aws lambda delete-function --function-name evidence-archive-checker
|
|
124
|
+
aws iam delete-role-policy --role-name evidence-archive-checker-schedule --policy-name evidence-archive-checker-schedule
|
|
125
|
+
aws iam delete-role --role-name evidence-archive-checker-schedule
|
|
126
|
+
aws iam delete-role-policy --role-name evidence-archive-checker --policy-name evidence-archive-checker
|
|
127
|
+
aws iam delete-role --role-name evidence-archive-checker
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
The log group `evidence-archive-checks` and the topic stay. The log group is the history of every check, and #317's budget alert publishes to the topic. Deleting either is a separate decision, made as an administrator, and running the provisioning script again later picks up whichever is left.
|
|
131
|
+
|
|
132
|
+
## When an alert arrives
|
|
133
|
+
|
|
134
|
+
- **Stale.** No health snapshot has arrived: keeps have stopped, or they run and cannot publish one. On the Mac, `launchctl print gui/$(id -u)/io.github.krysoworks.kryso-keep` says whether the keep job runs, and the end of `<archive>/logs/keep.log` says why it stopped or why its health snapshot was not published, as [archiving-keep.md](archiving-keep.md#recover) describes.
|
|
135
|
+
- **Backlog.** Keeps run and uploads fail. `archive.py status --archive <dir> --remote <config>` names the failures on each waiting snapshot.
|
|
136
|
+
- **Unknown.** `archive.py health --remote <config>` lists what was rejected and why.
|
|
137
|
+
- **Failed.** The checker cannot read the bucket. `checker audit` and `archive.py audit` find a changed role or bucket policy.
|
|
138
|
+
- **An alert that failed.** Its check record holds the error. `checker audit` says whether the subscription is still confirmed.
|
|
139
|
+
|
|
140
|
+
[Playbook ADR 0028](../../docs/adr/0028-the-archive-checker-is-a-lambda-that-shares-the-archives-judgement-and-appends-its-checks-to-cloudwatch-logs.md) records why the checker is built this way.
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Keeping the archive
|
|
2
|
+
|
|
3
|
+
`archive.py keep` is the unattended run that keeps shipping evidence protected without a person uploading it or a model watching the driver. launchd starts one every five minutes and at login, and `keep-after.sh` starts one as soon as a shift ends. Each keep captures a history over the configured roots, uploads that capture and every snapshot the upload queue still holds unverified, runs the monthly restore check when one is due, and publishes a health snapshot. The capture is the `history` verb's and the upload is `upload`'s, so [archiving.md](archiving.md) and [archiving-remote.md](archiving-remote.md) hold their contracts and nothing below changes them.
|
|
4
|
+
|
|
5
|
+
A keep reads evidence and writes only the archive, the remote and a restore check's scratch root. It starts no model, writes nothing to a tracker, stops or restarts no context and prunes nothing, locally or remotely. Its failures are the archive's: a keep that cannot reach the bucket never changes a shift's exit status or outcome, and a verified upload is not proof that anything was delivered.
|
|
6
|
+
|
|
7
|
+
## The keep configuration
|
|
8
|
+
|
|
9
|
+
A JSON file. Relative paths are taken from the file's own directory, and `~` is expanded.
|
|
10
|
+
|
|
11
|
+
```json
|
|
12
|
+
{
|
|
13
|
+
"archive": "~/ship-archive",
|
|
14
|
+
"remote": "~/ship-archive/remote.json",
|
|
15
|
+
"repos": ["~/Dev/kryso", "~/Dev/iran-monitor"],
|
|
16
|
+
"claude_projects": "~/.claude/projects",
|
|
17
|
+
"codex_sessions": "~/.codex/sessions",
|
|
18
|
+
"inputs": ["~/ship-archive/prices.json"],
|
|
19
|
+
"recovery_identity": "/Volumes/keys/recovery-identity.txt",
|
|
20
|
+
"restore_scratch": "/Volumes/scratch",
|
|
21
|
+
"skipped_dirs": {"iran-monitor": ["coverage", "tmp-*"]}
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`archive` and a non-empty `repos` are required. `remote` names a [remote configuration](archiving-remote.md#the-remote-configuration), and without it a keep captures and writes health snapshots locally and uploads nothing. The roots are the `history` verb's: each repository's shifts, retained ledgers and shipped copies, and from the host session directories only the transcripts a record names by session id. Repository source, other sessions and anything a symlink points at are never staged. `recovery_identity` names the age identity file that decrypts the remote, and turns on [the restore check](archiving-recovery.md#the-restore-check). It needs `remote`. `restore_scratch` is the directory the check restores into, the system's temporary directory when it is absent, and it may not lie inside the archive, a configured repository or a host session directory. `skipped_dirs` maps a configured repository's directory name to the directory names its captures leave out, on top of [the ones every capture leaves out](archiving.md#collect). A name may be a shell pattern such as `tmp-*`, and it matches a directory at any depth under that repository's ledgers, shipped copies and shift directories, which is then listed under `excluded` once, with everything under it. A key that names no configured repository, an empty list, and a name holding a `/` or standing for `.` or `..` are refused. A string holding private key material is refused: the file names where the key is, never the key. Any other key is refused, and so is a missing or malformed one, before anything is written. A configured repository that has gone is recorded as an error and the others are still kept.
|
|
26
|
+
|
|
27
|
+
## What one keep does
|
|
28
|
+
|
|
29
|
+
1. Takes the archive's keep lock, `<archive>/keep.lock`. A keep that finds it held prints `"status": "skipped"` and exits 0 with nothing written, because the keep holding it, or the next scheduled one, takes the same evidence. `--wait <seconds>` waits for it instead, and `keep-after.sh` waits up to 900.
|
|
30
|
+
2. Captures a history over the roots. Unchanged evidence names the same snapshot and writes nothing. A running pass is captured as it stands, with its attempt marked `active`. A file that is still changing after three reads is a capture error and makes the capture `partial`, and the next keep takes it again once it settles. Evidence that was overwritten or removed before a keep looked is absent from that capture, never rebuilt. The time, snapshot, completeness and attempt counts of the last capture that succeeded go to `<archive>/keep/last-scan.json`.
|
|
31
|
+
3. Uploads this keep's capture first, so it is queued before anything else can stop the keep, then every other snapshot the queue holds unverified, oldest first. An object the destination already verified for the same recipient, under any earlier snapshot, is adopted from the queue's record in `<queue>/known/` and neither sent nor read again, a record the first keep fills in from a queue verified before it existed, so a capture that differs by one ledger line moves one object, the manifest and the completion manifest. Offline, each snapshot stays pending with its failure on its queue entry, and the next keep resumes it. So does a keep that was killed: the kernel frees its lock with the process. An upload with more to send than fits in one interval publishes a health snapshot of the queue every 300 seconds while it runs, or every `--health-every` seconds, so the checker reads it as `backlog` once its snapshot has waited 30 minutes, and not as `stale`. The keep still holds its lock until the upload ends, so no other keep captures in the meantime.
|
|
32
|
+
4. Runs [the restore check](archiving-recovery.md#monthly-inside-the-keep) when the configuration names `recovery_identity` and one is due, which is about once a month. It restores the snapshot the queue verified most recently, so after step 3 that is usually this keep's capture. A failed check is this keep's error. It runs inside the keep lock, so later keeps skip until it ends.
|
|
33
|
+
5. Builds a health snapshot, writes it to `<archive>/health/`, then creates it on the remote and reads it back.
|
|
34
|
+
|
|
35
|
+
`keep` prints one JSON line: `status`, the `scan` result, one row per `uploads` attempt, the `restore_check` record when this keep ran one and null otherwise, where the `health` snapshot went and whether it was published, and `errors`. Each error names its stage, `scan`, `capture`, `upload`, `restore-check` or `health`, and is also printed to stderr. The exit is 1 for any error but a capture one, 2 for a partial capture with nothing else wrong, and 0 otherwise, a skipped keep included.
|
|
36
|
+
|
|
37
|
+
## A first capture of a new repository
|
|
38
|
+
|
|
39
|
+
Adding a repository to `repos` makes the next capture hold every file of its history that the destination has not verified, and each of those is a new object. An object costs one `age` process to encrypt, then a create and a read back, and each remote call is one `aws` process. Past keeps sent about 5.5 seconds an object, after the 100 seconds a keep with nothing to send takes. The first capture over ten repositories, on 2026-11-21, held 23,075 new objects and 2.62 GB: about 35 hours at that rate, with no other capture until it ends. A capture that differs by a few files moves only those, because every object the destination already verified is adopted.
|
|
40
|
+
|
|
41
|
+
Count a repository's objects before it is queued, with a capture into a scratch archive. Only an upload queues anything, so the count sends nothing and leaves the keep's archive alone:
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
python3 ~/.agents/skills/kryso-shift/archive.py history --archive /tmp/count-archive \
|
|
45
|
+
--repo ~/Dev/new-repo --claude-projects ~/.claude/projects
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`entries` in its output is the number of files the capture holds, and `manifest` names its manifest. An upload sends each distinct object once, so count those and their bytes:
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
jq '[.entries[] | {sha256, bytes}] | unique | length, (map(.bytes) | add)' <manifest>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Multiply the first number by about 5.5 seconds for the upload time, and remove the scratch archive afterwards. Files another configured repository already holds are adopted, so the real count may be lower. When it runs to hours, add the repository when the Mac can stay on, or leave out what the capture should not hold with [`skipped_dirs`](#the-keep-configuration).
|
|
55
|
+
|
|
56
|
+
## Health snapshots
|
|
57
|
+
|
|
58
|
+
A health snapshot (`ship-archive-health/1`) is what a reader that cannot see the Mac uses to tell whether evidence is reaching the bucket. Its fields:
|
|
59
|
+
|
|
60
|
+
| Field | What it holds |
|
|
61
|
+
| --- | --- |
|
|
62
|
+
| `at`, `host`, `archive`, `destination` | When the keep started and where it ran, and the queue's destination. Every snapshot one keep publishes during a long upload has the same `at`, and the time in its name says when it was published. |
|
|
63
|
+
| `latest_scan` | The last capture that succeeded: `at`, `snapshot`, `status`, `completeness`, `attempts` and how many are `active`. |
|
|
64
|
+
| `last_verified`, `oldest_pending`, `pending_bytes` | The upload queue on this destination, as [`status`](archiving-remote.md#the-upload-queue) reports it. |
|
|
65
|
+
| `pending` | The number of snapshots waiting. |
|
|
66
|
+
| `gaps` | The `gaps` of the latest capture's manifest: absent or ambiguous sessions, missing inputs, attempts that vanished since an earlier capture and the rest. |
|
|
67
|
+
| `restore_check` | The newest restore check the archive recorded, whether this keep ran it or not: `at`, `snapshot`, `status` (`passed` or `failed`) and `problems`. Null before the first. |
|
|
68
|
+
| `errors` | This keep's errors up to the point the snapshot was built. A failure to publish the snapshot itself is in the keep's output, and the snapshot stays in `<archive>/health/`. |
|
|
69
|
+
|
|
70
|
+
Each one is a new object, `health/<YYYY-MM-DD>/<YYYYMMDDTHHMMSSffffffZ>-<sha256>.json`, created with the same conditional create as every other object and never replaced. The name holds the UTC day, the time to the microsecond and the hash of the bytes, so publishing needs no overwrite permission and a reader can check what it fetched against the name it fetched.
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
python3 archive.py health --remote remote.json [--days 7]
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`health` lists the last `--days` UTC days of health snapshots as the recovery identity, which holds `s3:GetObject` and `s3:ListBucket` and nothing that writes, and returns the newest one whose bytes match its name and parse as a health snapshot. Anything newer that does not is listed under `rejected` with the reason. It exits 0 with a snapshot and 1 with none or when the remote cannot be listed, which is never reported as an empty answer. Deciding that the newest one is too old, and alerting on it, is [the checker](archiving-checker.md)'s job, which selects a snapshot with this same code.
|
|
77
|
+
|
|
78
|
+
## Install the launch agent
|
|
79
|
+
|
|
80
|
+
Prerequisites: the remote is provisioned and audited as [the runbook](archiving-remote.md#runbook-the-first-real-round-trip) says, `archive.py check --remote` prints `"ready": true`, and `age` and the `aws` CLI are on the `PATH` of the shell you install from.
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
python3 ~/.agents/skills/kryso-shift/archive.py launchd print --config ~/ship-archive/keep.json # read it first
|
|
84
|
+
python3 ~/.agents/skills/kryso-shift/archive.py launchd install --config ~/ship-archive/keep.json
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`install` validates the keep configuration and the remote, writes `~/Library/LaunchAgents/io.github.krysoworks.kryso-keep.plist`, and loads it with `launchctl bootstrap gui/<uid>`, after `launchctl bootout` when it replaces an earlier keep job. A keep job under the label before the rename, `com.github.jv-k.ship-archive.keep`, is unloaded and its plist deleted first, so one Mac never runs two keeps. The result names it under `replaced`. The job runs `archive.py keep --config <file>` at load, which is every login, and every 300 seconds after, at background priority. It carries the installing shell's `PATH`, because launchd's own finds neither `age` nor `aws`. Its output is appended to `<archive>/logs/keep.log`. Reinstalling replaces the same label's plist and nothing else. A plist at the label that does not run `archive.py keep`, or a job loaded under the label with no plist in the agents directory, is refused with nothing written or unloaded. `--label` names a second job, for a second archive, and `--no-load` writes the plist without loading it. The restore check has no job of its own: it runs inside this one. `install` prints `restore_check` with the identity file, whether it is there now, and the 30-day and one-day intervals, or null when the configuration names no `recovery_identity`. An identity file that is absent at install time is allowed, for the reason [the recovery guide](archiving-recovery.md#the-identity-on-the-uploading-machine) gives. The launchd side, the plist and the `launchctl` calls, is `archive_launchd.py`, which sits beside `archive.py` and installs with it.
|
|
88
|
+
|
|
89
|
+
Run a shift through the wrapper so its evidence is kept the moment it ends:
|
|
90
|
+
|
|
91
|
+
```sh
|
|
92
|
+
bash ~/.agents/skills/kryso-shift/keep-after.sh --config ~/ship-archive/keep.json -- \
|
|
93
|
+
bash ~/.agents/skills/kryso-shift/ship-loop.sh --epic 276
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
The header of [keep-after.sh](keep-after.sh) says what the wrapper passes through and the status it exits with. Stop a shift it runs by signalling the process group, because a signal to the wrapper alone waits for the shift. A shift started without the wrapper, or one that crashed, is taken by the next scheduled keep.
|
|
97
|
+
|
|
98
|
+
## Disable it
|
|
99
|
+
|
|
100
|
+
```sh
|
|
101
|
+
python3 ~/.agents/skills/kryso-shift/archive.py launchd remove
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`remove` runs `launchctl bootout gui/<uid>/io.github.krysoworks.kryso-keep` and deletes that one plist, and does the same for a keep job under the old label, `com.github.jv-k.ship-archive.keep`, which the result names under `old`. When the bootout fails and the job is still loaded, the plist stays and `remove` exits 1, so running it again retries. A plist at the label that does not run `archive.py keep` is refused, with nothing unloaded or deleted, so a mistyped `--label` cannot take another agent with it. With no plist at the label, `remove` runs no `launchctl` command and unloads nothing, because nothing says the job loaded under that label is a keep. A keep job still loaded after its plist was deleted by hand has to be stopped by hand, with `launchctl bootout gui/$(id -u)/<label>`. No other launch agent is read, unloaded or changed. The archive, the queue, the health snapshots and the remote are left as they are, and a later `install` carries on from the queue.
|
|
105
|
+
|
|
106
|
+
## Recover
|
|
107
|
+
|
|
108
|
+
- **Keeps are failing.** Read the last lines of `<archive>/logs/keep.log`, or run `archive.py keep --config <file>` by hand, and fix what the errors name. Pending work is in the queue: `archive.py status --archive <dir> --remote <config>` shows it, and the next keep resumes it. Nothing needs replaying.
|
|
109
|
+
- **The Mac was off or offline.** Nothing to do. The first keep after login uploads everything still pending. Evidence that changed more than once while it was off has only the versions a keep saw.
|
|
110
|
+
- **A keep was killed or the Mac crashed mid-upload.** Nothing to do. The lock went with the process, and the queue entry resumes without making a new object, as [the upload queue](archiving-remote.md#the-upload-queue) describes.
|
|
111
|
+
- **A keep looks stuck.** `launchctl print gui/$(id -u)/io.github.krysoworks.kryso-keep` shows whether it is running. A keep that is still publishing health snapshots is uploading, and `archive.py status` shows the queue going down. Every later keep skips while it holds the lock, so a hung one stops all of them until it ends. Stop that process by its pid and the next keep picks up from the queue.
|
|
112
|
+
- **The archive directory was lost.** The remote still holds every verified snapshot. Restore from it with `restore --remote` and the recovery identity. A new archive starts a new queue and re-encrypts, so its first uploads make new ciphertext objects beside the old ones, which playbook ADR 0024 records.
|
|
113
|
+
- **Evidence was cleaned up locally.** Nothing is lost that a keep saw. Later captures leave out what has gone, and every earlier snapshot stays on the remote and restores as it was.
|
|
114
|
+
|
|
115
|
+
[Playbook ADR 0027](../../docs/adr/0027-a-keep-adopts-verified-objects-and-health-snapshots-are-listed-by-name.md) records why a keep adopts verified objects without reading them and why the storage seam gained `list`.
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Recovering the archive
|
|
2
|
+
|
|
3
|
+
This page is the archive's recovery side: the restore check that proves every month that the remote still gives evidence back, and what to do when a restore is needed, the key is lost or the disk fills. The verbs it uses are specified in [archiving.md](archiving.md), [archiving-remote.md](archiving-remote.md) and [archiving-keep.md](archiving-keep.md), and nothing here changes them.
|
|
4
|
+
|
|
5
|
+
## The restore check
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
python3 ~/.agents/skills/kryso-shift/archive.py restore-check --config ~/ship-archive/keep.json [--snapshot <id>]
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
An upload proves that ciphertext reached the bucket. It cannot prove that the ciphertext decrypts, that the recovery identity can still read it, or that the manifest still lays out a tree, because the uploader holds neither the key nor the recovery role. The restore check is the proof of those, repeated without a person. It reads the [keep configuration](archiving-keep.md#the-keep-configuration), which must name `remote` and `recovery_identity`, and then:
|
|
12
|
+
|
|
13
|
+
1. Takes the snapshot the configured remote's upload queue verified most recently, or the one `--snapshot` names.
|
|
14
|
+
2. Makes a scratch directory under `restore_scratch`, or under the system's temporary directory when that is absent, and restores the snapshot into it the way `restore --remote` does, as the recovery identity: the recovery role on S3, and the age identity file `recovery_identity` names.
|
|
15
|
+
3. Reads every restored file back and checks its size and SHA-256 against the manifest that came back with it. The manifest must be the snapshot that was asked for, every file it names must be there, and no file it does not name may be.
|
|
16
|
+
4. Removes the scratch directory, whatever happened.
|
|
17
|
+
5. Writes the result to `<archive>/restore-checks/<YYYYMMDDTHHMMSSffffffZ>-<sha256>.json`, a new file each time that is never rewritten, and prints it with its path.
|
|
18
|
+
|
|
19
|
+
The check writes nothing on the remote, and it reads the remote only as the recovery identity, which cannot write. In the archive it writes its record and nothing else, so no snapshot, object, staged ciphertext or queue entry changes, and it never reads the evidence roots. The scratch root may not lie inside anything the check must leave alone, which [the keep configuration](archiving-keep.md#the-keep-configuration) lists, nor inside a local remote's root, so a restored copy never lands among the originals.
|
|
20
|
+
|
|
21
|
+
It exits 0 when the check passed and 1 when it failed. Everything that stops a restore is a failure with its reason in `problems`: no verified snapshot in the queue, an identity file that is missing or is not the key the evidence was encrypted to, a missing completion manifest, a missing or corrupt object or manifest, a refused or dropped connection, a scratch root that cannot be written or fills up, and age not installed. A restore that completes and then disagrees with its manifest fails the same way. A configuration that cannot be read, or that names no `recovery_identity`, is refused without a record, because no check ran.
|
|
22
|
+
|
|
23
|
+
| Field | What it holds |
|
|
24
|
+
| --- | --- |
|
|
25
|
+
| `schema` | `ship-archive-restore-check/1` |
|
|
26
|
+
| `at`, `host`, `archive` | When the check started, and where. |
|
|
27
|
+
| `destination` | The remote it read, as the upload queue names it, or null when the remote configuration could not be read or is not ready. |
|
|
28
|
+
| `snapshot` | The snapshot it restored, or null when none was verified. |
|
|
29
|
+
| `named` | True when `--snapshot` chose the snapshot, false when the queue did. |
|
|
30
|
+
| `status` | `passed` or `failed`. It is `passed` only when `problems` is empty. |
|
|
31
|
+
| `completeness` | The restored snapshot's own completeness. A partial snapshot that restores intact is a passed check of a partial snapshot. |
|
|
32
|
+
| `files`, `bytes` | How many restored files matched the manifest, and their size. |
|
|
33
|
+
| `problems` | Each reason the check failed. |
|
|
34
|
+
| `scratch`, `removed` | The scratch directory, and whether it was gone afterwards. One that could not be removed fails the check, because the restored files are still in it. |
|
|
35
|
+
| `seconds` | How long the check took. |
|
|
36
|
+
|
|
37
|
+
### Monthly, inside the keep
|
|
38
|
+
|
|
39
|
+
The restore check has no launch agent of its own. The keep job that `archive.py launchd install` loads runs it, so archive jobs have one installer, one log in `<archive>/logs/keep.log` and one health snapshot to read. A keep whose configuration names `recovery_identity` runs a check after its uploads when one is due: the archive has no record yet, the newest one passed 30 days ago or more, or the newest one failed a day ago or more. A failure is retried daily rather than at every keep, because each attempt downloads and decrypts a whole snapshot. A check run by hand with `--snapshot` proves only the snapshot it names, so it is left out of that reckoning, and one run by hand without it counts like a keep's.
|
|
40
|
+
|
|
41
|
+
A failed check is the keep's error, with the stage `restore-check`, so the keep exits 1 and `keep-after.sh` reports that keeping the archive failed. Every health snapshot carries the newest record in `restore_check`, so a reader without the Mac sees the last result and its date with `archive.py health`. A check that should have run and did not shows there as an old `at`.
|
|
42
|
+
|
|
43
|
+
[Playbook ADR 0029](../../docs/adr/0029-the-restore-check-runs-inside-a-keep-and-reads-only-as-the-recovery-identity.md) records why the check rides on the keep rather than on a launchd calendar slot of its own.
|
|
44
|
+
|
|
45
|
+
### The identity on the uploading machine
|
|
46
|
+
|
|
47
|
+
The recovery identity was kept apart from the uploader so that the machine that uploads cannot read what it uploaded. An unattended check on that machine needs the identity there when the check runs, and on S3 needs the Mac's credentials to be allowed to assume the recovery role. That is a real loss of separation, and the configuration leaves the trade to the owner:
|
|
48
|
+
|
|
49
|
+
- Keep the identity file on a volume that is mounted only when wanted. A month in which it is absent records a failed check, and the daily retry passes once the volume is back.
|
|
50
|
+
- Keep it on the Mac, with the second copy that key recovery below needs held somewhere else.
|
|
51
|
+
|
|
52
|
+
The check reads the identity file and never copies it. A keep configuration holding the key itself, rather than the path to it, is refused.
|
|
53
|
+
|
|
54
|
+
## Backfilling a saved history
|
|
55
|
+
|
|
56
|
+
The order the tooling expects for a first upload of an existing history, with the remote configured and audited as [the runbook](archiving-remote.md#runbook-the-first-real-round-trip) says:
|
|
57
|
+
|
|
58
|
+
1. `archive.py history --archive <dir> --repo ... --claude-projects ... --codex-sessions ... --input ...` captures every repository at once and prints the capture's snapshot id. A partial capture exits 2 and still goes on.
|
|
59
|
+
2. `archive.py coverage --archive <dir> --snapshot <id> > coverage-<id>.json` writes [the coverage report](archiving.md#the-coverage-report). Read its `gaps` before anything leaves the machine.
|
|
60
|
+
3. `archive.py upload --archive <dir> --snapshot <id> --remote remote.json` uploads the capture, or a keep does on its next run.
|
|
61
|
+
4. `archive.py restore-check --config keep.json --snapshot <id>` restores what was uploaded as the recovery identity and records the result.
|
|
62
|
+
|
|
63
|
+
The coverage report reaches the remote the way prices and tracker snapshots do, as an input to a capture: add it to `inputs` in the keep configuration, or pass it with `--input` to the next `history`, and the capture that holds it is uploaded like any other. The restore check's result reaches the remote in every later health snapshot.
|
|
64
|
+
|
|
65
|
+
## Restoring evidence
|
|
66
|
+
|
|
67
|
+
Restore from the remote when the Mac, the archive or the original evidence has gone, or to look at evidence somewhere it cannot change. The machine needs the remote configuration, the recovery identity file and credentials allowed to assume the recovery role. It needs neither the uploader nor the local archive.
|
|
68
|
+
|
|
69
|
+
1. Find the snapshot. `archive.py health --remote remote.json` prints the newest health snapshot, whose `latest_scan.snapshot` is the last capture and whose `restore_check.snapshot` is the last one proved. With the archive still there, `archive.py status --archive <dir> --remote remote.json` lists every snapshot the queue holds. A saved coverage report names its snapshot too.
|
|
70
|
+
2. `archive.py verify --remote remote.json --snapshot <id> --identity <file>` must print `"problems": []`.
|
|
71
|
+
3. `archive.py restore --remote remote.json --snapshot <id> --identity <file> --to <empty root>` rebuilds it. The root must be absent or empty, and a failure leaves it untouched.
|
|
72
|
+
4. `archive.py coverage --manifest <root>/archive-manifest.json` says what the restored history holds and what it lacks.
|
|
73
|
+
5. Run the report or the measurement over it as [archiving.md](archiving.md#restore) shows.
|
|
74
|
+
|
|
75
|
+
Each capture is a whole history, so when one snapshot will not verify, the one before it holds nearly the same evidence. A new archive started after the old one was lost begins a new queue and encrypts again, as [the keep's recovery notes](archiving-keep.md#recover) say. Nothing on the remote is replaced by that.
|
|
76
|
+
|
|
77
|
+
## Key recovery
|
|
78
|
+
|
|
79
|
+
The age identity file is the only thing that decrypts the evidence. The bucket's owner cannot decrypt it, nothing in the archive can recreate it, and the uploader only ever held the public recipient. Keep at least two copies: the one the restore check reads, and one that survives losing the Mac, such as a password manager entry or a printout in a safe. Prove the second copy now and then with `archive.py verify --remote remote.json --snapshot <id> --identity <copy>`, which decrypts every object of the snapshot and checks it.
|
|
80
|
+
|
|
81
|
+
When the file the check reads is lost and a copy survives, put the copy back where `recovery_identity` points and run `restore-check` by hand. Nothing else changes.
|
|
82
|
+
|
|
83
|
+
When every copy is lost, the evidence on the remote cannot be read again, and the uploader cannot delete it. Make a new key pair with `age-keygen`, put the new public recipient in the remote configuration as `encryption.recipient`, and point `recovery_identity` at the new file. Snapshots already verified under the old key stay as they are, because a completion manifest is created once. The next capture that differs from the last is encrypted to the new key, and its objects are uploaded again, since the record of verified objects is kept per recipient. A `history` run with one extra `--input`, a note recording the rotation say, followed by `upload` of the snapshot it prints, makes one at once. Until a snapshot encrypted to the new key is verified, the restore check fails, because the newest verified snapshot is still the old key's. Evidence that is no longer on the Mac exists only under the old key, and is lost with it.
|
|
84
|
+
|
|
85
|
+
When the key may be in someone else's hands, rotate it the same way. Rotation protects only what is uploaded afterwards. The objects encrypted to the old key stay readable to whoever holds it, because no lifecycle rule expires them and the uploader cannot delete them. Removing them is an administrator's act on the bucket, outside this tooling.
|
|
86
|
+
|
|
87
|
+
When the recovery role itself is lost or its trust policy no longer names the operator, an administrator of the account recreates it from the `provision` script, and `archive.py audit --remote remote.json` must print `"problems": []` again.
|
|
88
|
+
|
|
89
|
+
## Disk pressure
|
|
90
|
+
|
|
91
|
+
The archive only grows. Nothing prunes it, because which evidence may go is a person's decision, so its size is worth watching:
|
|
92
|
+
|
|
93
|
+
| Path | What grows it |
|
|
94
|
+
| --- | --- |
|
|
95
|
+
| `<archive>/objects/` | One copy of each distinct evidence file, shared between snapshots. |
|
|
96
|
+
| `<archive>/snapshots/` | One manifest per capture. A history capture names every file, so each keep that sees a change adds a manifest the size of the whole inventory. |
|
|
97
|
+
| `<archive>/remote/<recipient hash>/` | The staged ciphertext of every object uploaded, about the size of `objects/` again. |
|
|
98
|
+
| `<archive>/queue/` | One entry per snapshot, naming each of its objects, and one small record per verified object. |
|
|
99
|
+
| `<archive>/health/`, `restore-checks/` | One small file per keep, and one per check. |
|
|
100
|
+
| `<archive>/logs/keep.log` | Every keep's output, appended. |
|
|
101
|
+
|
|
102
|
+
`du -sh <archive>/*` shows where the space went. A restore check also needs free space for the whole snapshot it restores, for as long as it runs: the coverage report's `inventory.bytes` for that capture. Point `restore_scratch` at a volume with that much room to spare, or the check fails, removes what it wrote and records why.
|
|
103
|
+
|
|
104
|
+
A full disk does not lose evidence that was already captured. A keep that cannot write records the error against the stage that failed, a capture that cannot be written is a scan error, an upload that cannot update the queue leaves its snapshot pending, and the next keep tries both again.
|
|
105
|
+
|
|
106
|
+
To make room:
|
|
107
|
+
|
|
108
|
+
- When `archive.py status` reports `pending` and `uploaded` both 0, the staging directory `<archive>/remote/<recipient hash>/` can be deleted. Every object in it is verified, and a verified object is never sent again or read for its staged copy.
|
|
109
|
+
- `keep.log` is a plain log. Truncating it loses nothing the queue, the health snapshots or the restore check records hold.
|
|
110
|
+
- Move the archive to a bigger volume rather than deleting from it. Stop the keep with `archive.py launchd remove`, move the whole directory, change `archive` in the keep configuration, and install again. The queue names its destination, not its own path, so it carries on.
|
|
111
|
+
|
|
112
|
+
Do not delete from `objects/` or `snapshots/` by hand. An object can belong to several snapshots, and one still pending in the queue cannot upload without it.
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# Archiving to a remote
|
|
2
|
+
|
|
3
|
+
`archive.py` also preserves an archive snapshot off the machine. `upload` encrypts a snapshot's files with age, creates them in a private bucket, reads each one back, and publishes a completion manifest last. `verify --remote` and `restore --remote` check and rebuild it from the bucket alone, with a separate identity and a key the uploader never held. The local archive, its layout and the manifest are in [archiving.md](archiving.md) and are unchanged. Restoring in earnest, the monthly restore check, key recovery and disk pressure are in [archiving-recovery.md](archiving-recovery.md). `archive_remote.py` sits beside `archive.py` and installs with it. Python 3.10 or newer, `age` and, for an S3 remote, the `aws` CLI are required.
|
|
4
|
+
|
|
5
|
+
## Verbs
|
|
6
|
+
|
|
7
|
+
| Verb | What it does | Exit |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| `check --remote <config>` | Validates the configuration and names every missing or invalid field. Touches nothing else. | 0 ready, 1 not ready |
|
|
10
|
+
| `upload --archive <dir> --snapshot <id> --remote <config>` | Encrypts, creates, verifies, then publishes the completion manifest. | 0 complete, 2 partial, 1 refused or stopped |
|
|
11
|
+
| `upload --archive <dir> --remote <config>` | Resumes every snapshot the upload queue has not verified, oldest first. One failing does not stop the rest. | 0 all verified, 2 one is partial, 1 one failed |
|
|
12
|
+
| `status --archive <dir> --remote <config> [--snapshot <id>]` | Reports the upload queue from the local archive alone. With a snapshot, lists each of its items. | 0 |
|
|
13
|
+
| `verify --remote <config> --snapshot <id> [--identity <age identity>]` | Checks the ciphertext against the completion manifest. With an identity it decrypts and checks the original hashes too. | 0 clean, 1 problems |
|
|
14
|
+
| `restore --remote <config> --snapshot <id> --identity <age identity> --to <root>` | Rebuilds the snapshot under an empty root, as `restore --archive` does. | 0 restored, 1 refused |
|
|
15
|
+
| `provision --remote <config>` | Prints the script that creates the bucket and identities. Runs nothing. | 0, or 1 when not ready |
|
|
16
|
+
| `audit --remote <config>` | Reads the deployed bucket as the operator's own credentials and lists every way it differs from that script. | 0 matches, 1 differs |
|
|
17
|
+
|
|
18
|
+
Every verb that takes `--remote` validates the whole configuration first, so a missing value stops the run before any request. The failure names each prerequisite at once.
|
|
19
|
+
|
|
20
|
+
## The remote configuration
|
|
21
|
+
|
|
22
|
+
A JSON file. It holds no secret: the uploader's configuration is refused when any string in it holds private key material.
|
|
23
|
+
|
|
24
|
+
```json
|
|
25
|
+
{
|
|
26
|
+
"kind": "s3",
|
|
27
|
+
"account": "123456789012",
|
|
28
|
+
"region": "eu-west-1",
|
|
29
|
+
"bucket": "nightshifter-evidence-1",
|
|
30
|
+
"prefix": "evidence/",
|
|
31
|
+
"profile": "evidence-admin",
|
|
32
|
+
"retention": "versioned-forever",
|
|
33
|
+
"uploader": { "identity": "arn:aws:iam::123456789012:role/evidence-uploader" },
|
|
34
|
+
"recovery": { "identity": "arn:aws:iam::123456789012:role/evidence-recovery" },
|
|
35
|
+
"encryption": { "tool": "age", "recipient": "age1..." }
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`kind` is `s3` or `local`. A `local` remote needs only `root` and `encryption.recipient`: it is a directory standing in for a bucket, and it is what the tests inject faults into. The checks are shape checks, made without a network call. `prefix` and `profile` are optional and the rest is required. `account` is the 12 digits of the AWS account that owns the bucket, and both identity ARNs must sit in that account. The bucket name must pass S3's rules, which are stricter than Google's: lowercase letters, digits, dots and dashes, 3 to 63 characters, no underscores and no uppercase, with separate refusals for a name that looks like an IP address, starts with `xn--`, ends with `-s3alias` or holds two dots in a row. The uploader and recovery identities are IAM role ARNs and must differ. A user ARN is refused, because every operation's credentials come from `sts assume-role` and STS cannot assume a user, so a user configuration would pass the shape check and then fail at the first call. Only the `aws` partition is accepted, since every resource the module builds is an `arn:aws` one. A role at a path is accepted and provisioned with `--path`. The recipient is an age public recipient, never the secret key. The age identity file that decrypts is passed to `verify` and `restore` on the command line and appears in no configuration.
|
|
40
|
+
|
|
41
|
+
`profile` names a profile the `aws` CLI reads credentials from, for an operator whose default profile is another account.
|
|
42
|
+
|
|
43
|
+
### Retention
|
|
44
|
+
|
|
45
|
+
`retention` takes one value, `versioned-forever`. S3 has no soft-delete duration to set. A replaced or deleted object survives only as a noncurrent version, and only for as long as no lifecycle rule expires it, so the one way to put a literal 90-day floor under a deleted object is a `NoncurrentVersionExpiration` rule that throws it away on day 91. That is the thing "evidence must never expire" forbids. The two requirements are in direct conflict on this provider, and a day count is unimplementable, so the configuration states the guarantee the bucket actually holds to instead of a number it cannot: versioning on, and no lifecycle rule at all. `audit` enforces both halves.
|
|
46
|
+
|
|
47
|
+
## What is on the remote
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
<prefix>objects/<sha256 of the ciphertext>.age one encrypted file, created once
|
|
51
|
+
<prefix>snapshots/<id>/manifest.json the archive manifest, byte for byte, private but readable
|
|
52
|
+
<prefix>snapshots/<id>/complete.json the completion manifest, created last
|
|
53
|
+
<prefix>health/<day>/<time>-<sha256>.json a health snapshot, one per keep, see archiving-keep.md
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Raw bytes are encrypted before they leave the machine, one object per distinct file, so a file shared by two snapshots is stored once. The manifest and completion manifest are not encrypted: they hold paths, sizes, hashes and outcomes, and the bucket is private. The completion manifest (`ship-archive-complete/1`) names the snapshot, its `completeness` as the manifest states it, the recipient, and for each object the original hash and size beside the ciphertext's object name, hash and size. A snapshot with no completion manifest is not preserved, however many objects of it are there.
|
|
57
|
+
|
|
58
|
+
## Upload
|
|
59
|
+
|
|
60
|
+
`upload` first refuses a snapshot whose manifest restore would refuse: an unsafe or colliding path, an entry with no hash or no whole-number size, or no `completeness`. The completion manifest vouches for the evidence, and nothing should vouch for a snapshot nobody can rebuild. Nothing is sent in that case. Then it runs in this order and stops at the first failure:
|
|
61
|
+
|
|
62
|
+
1. If a completion manifest for the snapshot already exists, check it end to end. A matching one is reused and nothing is written (`unchanged`). One that does not verify, or was encrypted to another recipient, is refused.
|
|
63
|
+
2. Encrypt each distinct object into the local archive's staging directory, `<archive>/remote/<recipient hash>/`. A retry reads the staged ciphertext instead of encrypting again, so it sends the same bytes under the same object name. age is not deterministic, which is why the copy is kept. A staged file's name holds its own ciphertext hash, and one that no longer matches is discarded and encrypted again.
|
|
64
|
+
3. Create each object with a conditional create that fails instead of replacing. Read it back and compare the hash. An object that is already there with the same bytes is reused. One there with other bytes is an identity conflict and is refused, with nothing overwritten.
|
|
65
|
+
4. Create the manifest the same way, then the completion manifest, and read both back.
|
|
66
|
+
|
|
67
|
+
A network error, a lost response or a refused read stops the run, and until the completion manifest exists nothing is preserved. Running the same command again resumes it, and so does `upload` with no snapshot, which takes every snapshot the queue has not verified. When the lost response was the completion manifest's own, the repeat finds it, checks it and reports `unchanged`. The uploader never holds the age identity, so `upload` cannot prove the evidence decrypts. After the first upload, run `verify --remote --identity` where the identity lives. [The restore check](archiving-recovery.md#the-restore-check) repeats the proof monthly: a keep restores the snapshot it verified most recently, decrypting it with the identity, and records whether every file came back. A recipient whose private key was lost uploads and reports `complete`, and only a run with the key finds out. A partial snapshot uploads like any other and its completion manifest says `partial`, with exit 2. A failed pass and a partial snapshot are separate facts, as in the local archive.
|
|
68
|
+
|
|
69
|
+
## The upload queue
|
|
70
|
+
|
|
71
|
+
Every upload is recorded in the local archive before the remote is touched, at `<archive>/queue/<destination hash>/<snapshot>.json`, one entry per snapshot and destination. The destination is the local root or the bucket and prefix, so two configuration files naming one place share a queue. The entry names each distinct object by its original hash and size and, once it is encrypted, by its object name and ciphertext hash, alongside the manifest and the completion manifest. Each of those items moves from `pending` to `uploaded` when its create returns and to `verified` when it reads back with the bytes it was sent.
|
|
72
|
+
|
|
73
|
+
A change to one item is appended as one short line to `<snapshot>.changes` beside the entry and synced before the upload goes on, so what an upload writes grows with its objects, not with its objects times the entry's size. Reading an entry replays its change log. The whole entry is rewritten only when a run starts, fails or finishes, and that rewrite starts a new generation and drops the log, so a log left by a run killed between the two is passed over rather than replayed onto newer state.
|
|
74
|
+
|
|
75
|
+
Each directory the queue or the staging area makes is synced into its parent as it is made, whether an upload or a keep's backfill makes it first. A synced file is only as durable as the name of the directory holding it.
|
|
76
|
+
|
|
77
|
+
A snapshot is as far along as its least advanced item, so it is `verified` only when its completion manifest is. The last failure stays on the entry until a run verifies it.
|
|
78
|
+
|
|
79
|
+
A retry reads before it sends. Every object an earlier run tried to create is read from the remote first: one that is there with the bytes its name promises is verified without being sent again, whatever the earlier run heard back, and one that is there with other bytes is an identity conflict. The entry marks an object tried before its create is sent, so a run killed during the create leaves it to be read. An object that was encrypted and named but never tried cannot be on the remote, and is not read.
|
|
80
|
+
|
|
81
|
+
Every object is encrypted and staged before the first create, so a damaged local object still stops the run with nothing written, and each ciphertext is read back from staging only when it is sent, so a large snapshot is never held in memory whole. Then the rest are sent. Because the entry records the identities, a staging directory lost after its objects landed costs nothing either: they are read back under the names the queue holds and no new object is made. Only an object that never reached the remote is encrypted again. [Playbook ADR 0026](../../docs/adr/0026-the-upload-queue-records-object-identities-and-a-retry-reads-before-it-sends.md) records that change to playbook ADR 0024's consequences. [Playbook ADR 0053](../../docs/adr/0053-the-upload-queue-appends-item-changes-and-a-retry-reads-only-what-a-run-tried-to-create.md) narrows the read to what a run tried, and records the change log.
|
|
82
|
+
|
|
83
|
+
Each object verified on a destination is also remembered under `<queue>/known/<recipient hash>/<original hash>.json`, written once. A later snapshot holding the same bytes adopts that identity when it is queued, marks it verified and neither sends nor reads it, so a scheduled keep moves only what changed. The uploader can neither delete nor replace an object, so an identity that once read back with its bytes stays true. A snapshot's own objects that an earlier run tried are still read again on a retry, as above, and one it named and never tried is adopted like any other. A queue verified before this record existed has it filled in from its verified entries by the first keep, once, which leaves `known/backfilled.json` behind.
|
|
84
|
+
|
|
85
|
+
Nothing is removed. A verified entry stays, the staged ciphertext stays and the local snapshot stays, because pruning any of them is not this command's decision. A snapshot deleted locally keeps its entry: a verified one is still reported verified, and a pending one stays pending with `no snapshot` as its failure. Neither touches the remote, which the uploader cannot delete from anyway.
|
|
86
|
+
|
|
87
|
+
One run at a time uploads a snapshot to a destination. A second is refused at once rather than left to wait, because two runs with nothing staged would each encrypt the same file and age would give them different objects for it.
|
|
88
|
+
|
|
89
|
+
`status` reads only the queue, so it is cheap enough for a scheduler to run every few minutes and it works with the network down. Its fields:
|
|
90
|
+
|
|
91
|
+
- `last_verified` is the most recent time a snapshot's completion manifest verified, by being published or by a repeat finding it intact.
|
|
92
|
+
- `oldest_pending` is the snapshot queued longest ago that is not verified, with that time.
|
|
93
|
+
- `pending_bytes` is the original size of every object and manifest not yet verified, an object shared by two waiting snapshots counted once. The completion manifest is not counted, so a snapshot waiting only on it shows no bytes and is still pending.
|
|
94
|
+
- `failures` holds each snapshot's last error, a verified snapshot's failed re-check included, and every queue file that cannot be read.
|
|
95
|
+
|
|
96
|
+
The counts of `pending`, `uploaded` and `verified` snapshots and one row per snapshot follow. Nothing in it is a pass's outcome. An upload that fails is the archive's failure and changes no snapshot, record or delivery result.
|
|
97
|
+
|
|
98
|
+
## Verify and restore
|
|
99
|
+
|
|
100
|
+
`verify --remote` fetches the completion manifest, then the manifest it names, then every object. It reports a missing or altered manifest, an unsafe or mismatched object name, a ciphertext whose hash or size is wrong, any manifest entry the completion manifest does not cover, and a manifest whose layout restore would refuse. Without an identity it proves the ciphertext is the ciphertext that was uploaded. It cannot prove that it decrypts, so only a run with `--identity` reports `plaintext`.
|
|
101
|
+
|
|
102
|
+
`restore --remote` does the same checks, decrypts each object, checks the original hash and size, and then rebuilds the layout the way `restore --archive` does: every path is checked for traversal and collisions, files are written to a staging directory beside the root and renamed into place only when all of them are in. A missing identity file, a wrong key, a corrupt or missing object, a tampered manifest and an unsafe path all stop it with the root untouched and a message that says nothing was restored.
|
|
103
|
+
|
|
104
|
+
## Adapters
|
|
105
|
+
|
|
106
|
+
The storage seam has three operations, `create` (conditional, never replacing), `read` and `list`, which names the objects under a prefix and reads none of their bytes. Only the health reader and [the checker](archiving-checker.md) list. An adapter fills it for one provider, and no caller handles provider details.
|
|
107
|
+
|
|
108
|
+
- `s3` shells out to the `aws` CLI, calling `aws s3api` for the bucket, `aws iam` for the identities and `aws sts` for credentials. Neither botocore nor boto3 is installed, and the CLI already signs SigV4 correctly, so the adapter runs it rather than implementing signing or taking a dependency. One `aws sts assume-role --role-arn <identity>` per identity returns temporary credentials, which are passed to each call as environment variables, cached per store, and replaced once when a call comes back `ExpiredToken`. No key file is written anywhere. With no identity, which is how the audit reads the bucket, the operator's own credentials are used and no role is assumed. `ARCHIVE_S3_ENDPOINT` points the adapter at a stand-in server in the tests, and nothing else reads it.
|
|
109
|
+
- `local` is a directory. `ARCHIVE_STORE_FAULTS` names a JSON file of rules, `{"op": "create" | "read" | "list", "match": "<part of an object name or listed prefix>", "fault": "error" | "lose-response" | "corrupt" | "drop" | "deny" | "interrupt" | "interrupt-after"}`, which the tests use to drop a connection before or after a create, return flipped bytes, make a written object vanish, refuse a permission, or kill the process before a call or just after a create lands. An empty `match` takes every object, which is how an offline store is injected.
|
|
110
|
+
|
|
111
|
+
A list is `aws s3api list-objects-v2`, which follows the continuation token itself, and a refusal to list is an error rather than an empty listing. Every create is `aws s3api put-object --if-none-match '*'`, the conditional create S3 offers. The header is present in `aws-cli/2.34.51` and reaches the wire. Four outcomes are told apart: created (exit 0), already there (`PreconditionFailed` or `ConditionalRequestConflict`), denied (`AccessDenied`), and absent on a read (`NoSuchKey`). A 403 names the identity that was refused.
|
|
112
|
+
|
|
113
|
+
`test-archive-remote.sh` runs both adapters through the commands above, and `test-archive-resume.sh` interrupts uploads against the local store and reads the result through `status`, the remote's objects and a restore. It runs the real `age` when one is installed and a stand-in with the same command lines when not, and says which on stderr. The S3 side runs the real `aws` CLI, signing real requests, against a stand-in HTTP server: it proves the request shapes, the conditional-create header and the error-code mapping, not real S3 or real IAM semantics.
|
|
114
|
+
|
|
115
|
+
## Provisioning
|
|
116
|
+
|
|
117
|
+
`provision` prints a script for an owner to read and run. It creates the bucket in the configured region with `--object-ownership BucketOwnerEnforced`, sets the public access block with all four flags true, turns versioning on, and sets default encryption to AES256 with bucket keys. It sets no lifecycle rule anywhere, so nothing expires. For each identity it creates the role with a trust policy naming `UPLOADER_OPERATOR` or `RECOVERY_OPERATOR`, the principals allowed to assume it, at the ARN's path where it has one. The trust policy is assembled by `printf` at run time, so the operator's ARN arrives as data and a value holding shell or JSON metacharacters cannot reach the script's syntax. Then it attaches one inline policy per identity with `put-role-policy`. `us-east-1` is the one region sent without `--create-bucket-configuration`, because S3 rejects it as a `LocationConstraint` and treats its absence as that region.
|
|
118
|
+
|
|
119
|
+
The uploader's policy is allow plus deny. It allows `s3:PutObject` and `s3:GetObject` on the objects, then explicitly denies `s3:DeleteObject`, `s3:DeleteObjectVersion`, `s3:PutObjectAcl`, `s3:PutBucketPolicy`, `s3:PutBucketVersioning`, `s3:PutLifecycleConfiguration`, `s3:DeleteBucket` and `s3:DeleteBucketPolicy`. Two further denies carry the no-overwrite restriction: `s3:PutObject` is denied when the request's `If-None-Match` is absent (`Null` is true) and when it is anything but `*` (`StringNotEquals`). The recovery identity gets `s3:GetObject`.
|
|
120
|
+
|
|
121
|
+
Both identities also get `s3:ListBucket` on the bucket ARN, with no condition. A `GetObject` for a key that is not there answers 404 `NoSuchKey` only to a principal holding that permission, and 403 `AccessDenied` otherwise. The first upload of a snapshot reads its `complete.json` before creating anything, and the adapter turns a 403 into a stop rather than an absence, so without the grant a first upload never starts. The health reader also lists `health/` with it, as the recovery identity. It reads key names, never an object's bytes.
|
|
122
|
+
|
|
123
|
+
The grant must stay unconditional, which reads like something to tighten and is not. An `s3:prefix` condition looks like the obvious narrowing and breaks every first upload: `s3:prefix` is defined for `ListBucket` alone, a `GetObject` request never carries it, and IAM reads a positive operator over a key the request does not carry as false, so the grant would not apply to the read that needs it. The condition also withholds nothing worth having, because both identities hold `s3:GetObject` across the whole bucket, so it hides key names while every object's bytes stay readable. The checker's role does carry the condition, for the reasons [archiving-checker.md](archiving-checker.md#deploy) gives.
|
|
124
|
+
|
|
125
|
+
The conditional denies are load-bearing, and this is where S3 differs from GCS. GCS had `roles/storage.objectCreator`, a role that creates but cannot replace, so the permission set carried the restriction. S3 has no equivalent: `s3:PutObject` alone permits overwriting an existing object, and with versioning on the replacement simply becomes the current version, so no delete permission is ever consulted. Denying the delete actions does not stop a replace. What stops it is the pair of denies on `s3:PutObject` itself, which make a PUT that is not a conditional create unauthorised in IAM rather than merely refused by a well-behaved client.
|
|
126
|
+
|
|
127
|
+
Neither conditional deny folds into the other. `Null` true matches only an absent header, while `StringNotEquals` matches a wrong value and, because IAM reads a negated operator as true for a key the request does not carry, an absent one as well. In one statement the conditions would be ANDed and the pair would narrow to what `Null` alone already does. Kept apart, either one closes the hole and `audit` requires both. Versioning sits behind them as defence in depth, surviving a privilege escalation past them rather than being what stops a replace. Removing any of these statements as redundant breaks the guarantee.
|
|
128
|
+
|
|
129
|
+
`audit` checks the result with the operator's own credentials, which must be able to read the bucket's configuration and policy. It makes five `s3api` reads (the public access block, versioning, the lifecycle configuration, the location and the bucket policy) and `iam` reads per identity. It reports any public access block flag that is not true, versioning that is not `Enabled`, any enabled lifecycle rule that expires or transitions anything, a region that is not the configured one, any action an identity holds beyond its allowed set, any allowed action it is missing, any missing deny on the uploader including the two conditional ones, any attached managed policy, and any inline policy the script does not write.
|
|
130
|
+
|
|
131
|
+
It reads a policy the way IAM does on the points that decide the guarantee. A statement reaches an action only when its `Resource` names the ARN that action needs, so a deny scoped to the bucket alone denies no object write however its action list reads. A grant and a deny are judged differently, because the safe direction differs by effect. A grant is a problem when it reaches any archive object, so an extra one on a narrower prefix is still reported. A deny is protection, and it counts only when it names the resource the provisioning script writes, or a bare `*`. The ARN a deny is checked against is itself a pattern standing for every key under it, so matching one pattern against another proves nothing about the keys: a deny on `<bucket>/?` reaches only single-character keys, and no archive object has one. Anything else is reported missing rather than found, which is why reprovisioning is the fix for a deny the audit does not recognise. An action both allowed and unconditionally denied is reported, because the deny wins. A `Deny` carrying a condition does not count as an unconditional one, so a `SecureTransport` condition on a required deny no longer passes for protection. The bucket policy is judged for any `Allow` naming either configured identity, not only for a public principal.
|
|
132
|
+
|
|
133
|
+
Where a construct cannot be evaluated exactly, the audit says so instead of passing it. `NotAction`, `NotResource`, an `Effect` that is neither `Allow` nor `Deny`, and a wildcard reaching more than one judged action are each reported by name, with every judged action such a pattern does reach reported alongside. Reading a policy loosely is what let an uploader with `s3:PutObject` replace evidence while the audit called the bucket clean, so a report that asks the operator to look is the safe direction.
|
|
134
|
+
|
|
135
|
+
It reads only what is attached to those two identities. A permission granted higher up, by a service control policy on the account or the organisation, or by a resource policy on something else, is invisible to it, so the restriction check in the runbook below is still needed.
|
|
136
|
+
|
|
137
|
+
## What the owner provides
|
|
138
|
+
|
|
139
|
+
None of these exist in the repository, and the code chooses none of them:
|
|
140
|
+
|
|
141
|
+
1. An AWS account with billing, and its 12-digit id.
|
|
142
|
+
2. The bucket's region and name, and the folder prefix if the bucket is shared.
|
|
143
|
+
3. The two identities' ARNs, in that account. `provision` creates the roles.
|
|
144
|
+
4. An administrator of the account, to run `provision`.
|
|
145
|
+
5. The principals allowed to assume each role, for `UPLOADER_OPERATOR` and `RECOVERY_OPERATOR`.
|
|
146
|
+
6. `age` and the `aws` CLI installed, with the CLI authenticated, where each step runs.
|
|
147
|
+
7. An age key pair. The public recipient goes in the configuration. The identity file is kept where the uploading machine cannot reach it, with a copy somewhere that survives losing that machine.
|
|
148
|
+
|
|
149
|
+
The automated tests exercise a stand-in HTTP server with the real `aws` CLI doing real signing, which covers the request shapes, the conditional-create header and the error-code mapping, and covers neither real S3 nor real IAM semantics. For what has been shown against a real bucket, see the round trip below.
|
|
150
|
+
|
|
151
|
+
## Runbook: the first real round trip
|
|
152
|
+
|
|
153
|
+
Run it after the local suite passes, with a small real attempt. Keep every command's output.
|
|
154
|
+
|
|
155
|
+
1. `age-keygen -o recovery-identity.txt`. Put the printed public key in the configuration as `encryption.recipient`. Move the identity file to its independent home.
|
|
156
|
+
2. `python3 archive.py check --remote remote.json` must print `"ready": true`.
|
|
157
|
+
3. `python3 archive.py provision --remote remote.json`, read it, then run it as an administrator of the account with the two operator variables set.
|
|
158
|
+
4. `python3 archive.py audit --remote remote.json` must print `"problems": []`.
|
|
159
|
+
5. `python3 archive.py collect ...` for one small completed attempt, then `python3 archive.py upload --archive <dir> --snapshot <id> --remote remote.json`. The result must be `created` and `complete`. List the bucket with `aws s3 ls --recursive s3://<bucket>/<prefix>` and confirm no object name or content shows a plaintext transcript.
|
|
160
|
+
6. Show the restrictions, as the uploader. Create `probe/<time>` with `--if-none-match '*'`, which must succeed. Repeat that create unchanged, which must return `PreconditionFailed` because the key is taken. Then `put-object` the same key without the header, which must return 403 from the explicit deny: `s3:PutObject` alone would have replaced the object, so this is the statement doing the work. Then `delete-object` the probe, which must return 403. Then read the bucket's configuration, which must return 403. Repeat the create as the recovery identity, which must return 403. Request any object with no credentials, which must be refused.
|
|
161
|
+
7. From a different directory, with the original evidence and the local archive absent, run `python3 archive.py restore --remote remote.json --snapshot <id> --identity recovery-identity.txt --to <empty root>`. Compare every restored file's hash with the manifest's. Run `python3 report.py --repo <root>/<repository> ...` over it.
|
|
162
|
+
8. Save the commands and their outputs from steps 4 to 7 in `docs/reviews/<date>-archive-s3-round-trip.md`.
|
|
163
|
+
|
|
164
|
+
The first real round trip ran on 2026-10-04 and is recorded in [docs/reviews/2026-10-04-archive-s3-round-trip.md](../../docs/reviews/2026-10-04-archive-s3-round-trip.md): `audit` clean, a snapshot uploaded and read back, the nine refusals shown as the uploader and the recovery identity, and the snapshot rebuilt byte for byte in a clean location from the bucket and an independent key alone. The headerless PUT returning `AccessDenied` there is the first test of the create-only deny against real IAM rather than the stand-in.
|
|
165
|
+
|
|
166
|
+
That run covered one small snapshot on a good network. A large snapshot, an interrupted upload, a partial snapshot and two snapshots sharing objects are still only exercised against the fake server and the local store, and the upload queue only against the local store.
|