Audit and marks sealed into the bucket (#823) + unfinished uploads expire (#826) #828

Merged
Cordy merged 3 commits from fix-826 into main 2026-10-01 08:48:09 +00:00
Owner

One batch, one release (v0.6.312). Two commits per issue (code, docs), review per commit if you like.

#823 — audit log and marks on s3 (recommendation 1–6 from the issue)

  • internal/segments: sealer that turns the local month files into immutable, age-encrypted objects .cairn-state/{audit,marks}/<seq>.<YYYY-MM>.<offset>.<length>.jsonl, every 5 min / 1,000 events / shutdown (sealed before the instance lock is released). First line of each segment = header with the SHA-256 of the previous segment (CloudTrail-style chain). Boot: names alone give next seq + sealed bytes per month; a month whose local file is shorter (lost volume) is rebuilt from the segments. Retention deletes whole months.
  • cairnd audit-verify -config <file>: read-only; checks chain, sequence, header-vs-name, byte coverage per month; exit 0/1/2.
  • Marks secret becomes state (marks-secret), adopted once from the old file (statestore.MigrateFileAs), so old marks keep verifying after a volume loss.
  • No more silent failures: audit.Logger counts write failures (Health()); metrics cairn_audit_write_failures_total, cairn_audit_seal_failures_total, cairn_audit_unsealed_bytes, cairn_audit_last_seal_timestamp_seconds; admin-only, mutable bell item audit-failing after 15 min, landing on Administration › Audit log (i18n ×4, existing bell styling, guarded "undefined reason" line).
  • audit.stdout / CAIRN_AUDIT_STDOUT=true: JSON line per event on stdout, follows the toggle.
  • posix: unchanged (files on the share since #821).

#826 — unfinished uploads expire

  • TUS Expiration extension: Upload-Expires on create and every PATCH (sliding deadline), expiration advertised, HEAD/PATCH past the deadline → 410 + cleanup (web client already treats 410 as "start over").
  • Sweep at startup and hourly: expired uploads + stray spool files older than the expiry; pre-#826 sidecars get a deadline from their last mtime.
  • tusExpiry / CAIRN_TUS_EXPIRY, default 24h, 0 = old behaviour.
  • Peering staging: confirmed the gap (a body was only discarded after a successful delivery); DirBlobs.Sweep removes bodies older than 24 × transferTTL, at boot and hourly.

Tests

segments (seal + lost-volume rebuild + chain continuation, tamper detection: deleted and edited segment, retention prune keeps the chain verifiable, failure visible); statestore Backend.List; audit stdout/OnAppend/failure counting (root-skip for CI); end-to-end on a real posix driver: lost volume → audit back, old mark still verifies, both chains intact; posix = no sealing; bell item admin-only after the 15-min grace; web pin qa823; tus expiry advertise/stamp, sweep + 410, strays + legacy sidecars on restart; peering staging sweep. go vet, full go test ./... and all web tests green locally.

Docs

admin-policy (Audit logging: storage per driver, sealing, verify, failure behaviour, stdout), leak-tracing (ledger + secret), deployment (local table, ops, tusExpiry), account (new pref row), ARCHITECTURE (§5.4 audit, §7 TUS, §11 local list), README, CHANGELOG v0.6.312.

One batch, one release (v0.6.312). Two commits per issue (code, docs), review per commit if you like. ## #823 — audit log and marks on s3 (recommendation 1–6 from the issue) - **`internal/segments`**: sealer that turns the local month files into immutable, age-encrypted objects `.cairn-state/{audit,marks}/<seq>.<YYYY-MM>.<offset>.<length>.jsonl`, every 5 min / 1,000 events / shutdown (sealed before the instance lock is released). First line of each segment = header with the SHA-256 of the previous segment (CloudTrail-style chain). Boot: names alone give next seq + sealed bytes per month; a month whose local file is shorter (lost volume) is rebuilt from the segments. Retention deletes whole months. - **`cairnd audit-verify -config <file>`**: read-only; checks chain, sequence, header-vs-name, byte coverage per month; exit 0/1/2. - **Marks secret** becomes state (`marks-secret`), adopted once from the old file (`statestore.MigrateFileAs`), so old marks keep verifying after a volume loss. - **No more silent failures**: `audit.Logger` counts write failures (`Health()`); metrics `cairn_audit_write_failures_total`, `cairn_audit_seal_failures_total`, `cairn_audit_unsealed_bytes`, `cairn_audit_last_seal_timestamp_seconds`; admin-only, mutable bell item `audit-failing` after 15 min, landing on Administration › Audit log (i18n ×4, existing bell styling, guarded "undefined reason" line). - **`audit.stdout`** / `CAIRN_AUDIT_STDOUT=true`: JSON line per event on stdout, follows the toggle. - posix: unchanged (files on the share since #821). ## #826 — unfinished uploads expire - TUS **Expiration extension**: `Upload-Expires` on create and every PATCH (sliding deadline), `expiration` advertised, HEAD/PATCH past the deadline → 410 + cleanup (web client already treats 410 as "start over"). - **Sweep** at startup and hourly: expired uploads + stray spool files older than the expiry; pre-#826 sidecars get a deadline from their last mtime. - `tusExpiry` / `CAIRN_TUS_EXPIRY`, default `24h`, `0` = old behaviour. - **Peering staging**: confirmed the gap (a body was only discarded after a *successful* delivery); `DirBlobs.Sweep` removes bodies older than 24 × transferTTL, at boot and hourly. ## Tests segments (seal + lost-volume rebuild + chain continuation, tamper detection: deleted and edited segment, retention prune keeps the chain verifiable, failure visible); statestore `Backend.List`; audit stdout/OnAppend/failure counting (root-skip for CI); end-to-end on a real posix driver: lost volume → audit back, **old mark still verifies**, both chains intact; posix = no sealing; bell item admin-only after the 15-min grace; web pin qa823; tus expiry advertise/stamp, sweep + 410, strays + legacy sidecars on restart; peering staging sweep. `go vet`, full `go test ./...` and all web tests green locally. ## Docs admin-policy (Audit logging: storage per driver, sealing, verify, failure behaviour, stdout), leak-tracing (ledger + secret), deployment (local table, ops, tusExpiry), account (new pref row), ARCHITECTURE (§5.4 audit, §7 TUS, §11 local list), README, CHANGELOG v0.6.312.
- internal/segments: immutable, age-encrypted, hash-chained segments
  (<seq>.<month>.<offset>.<length>.jsonl) sealed every 5 min / 1000 events /
  shutdown; boot rebuilds months a lost volume took; Verify checks chain,
  sequence and byte coverage
- marks HMAC secret becomes state (marks-secret), adopted once from disk
- audit Append failures counted (no longer silent); metrics
  cairn_audit_{write,seal}_failures_total, _unsealed_bytes,
  _last_seal_timestamp_seconds; admin bell item audit-failing after 15 min,
  mutable, lands on Audit log (i18n x4)
- cairnd audit-verify subcommand
- audit.stdout / CAIRN_AUDIT_STDOUT mirrors events to stdout
- docs: admin-policy, leak-tracing, deployment, account, ARCHITECTURE,
  README, CHANGELOG v0.6.312
docs: TUS expiry and peering staging cleanup (#826)
All checks were successful
ci / test-and-build (pull_request) Successful in 1m16s
f73da18dc2
Cordy merged commit aa21f053be into main 2026-10-01 08:48:09 +00:00
Cordy deleted branch fix-826 2026-10-01 08:48:13 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Cordy/Cairn#828
No description provided.