Commit graph

10 commits

Author SHA1 Message Date
dd27af3cc2 round3-hub: backup, metrics auth, device ls, gc --keep-days, access log
Some checks are pending
CI / vet-build-test (push) Waiting to run
2026-06-30 13:53:16 -05:00
f8135b9d07 feat(M8a): adversarial auth audit — close +s escalation + add invite revocation 🛡️
Some checks are pending
CI / vet-build-test (push) Waiting to run
P2 adversarial audit (6 finders + skeptic verification, 13 agents). Two real
findings fixed with regression tests; rest documented as single-owner residuals.

- FIX (+s attenuation): MayGrant never constrained the GRANTED reshare bit, so an
  invite could confer +s the caller didn't hold (req.Reshare copied verbatim).
  MayGrant now takes grantReshare and rejects conferring +s you don't hold (owners
  unconstrained) — attenuation is total over role + target + reshare.
- FIX (invite revocation): invites were unrevocable 24h bearer capabilities — no
  way to kill a leaked/regretted one. Added meta.RevokeInvite (token+binding in one
  tx), POST /v1/invite/revoke (only a caller who could mint it may revoke), and
  'devbox invite revoke <token>'.
- Tests: TestMayGrant (+5 +s cases), TestInviteCannotGrantReshareCallerLacks,
  TestInviteRevoke. go test ./... -race clean (18 pkgs).
- docs/M8a-audit.md: findings, confirmed defenses, accepted residuals.

Confirmed-defended under attack: single-use redeem (atomic CAS), role bounding,
revoke-at-auth (revoked=0 in bearer+role lookups), cross-share binding, PoP.
2026-06-23 20:27:12 -05:00
05ebdeea77 refactor: ponytail-audit — drop the EffectiveRole delegating wrapper 🧹
It only called EffectiveMember and dropped one return; its sole prod
caller (the push gate) discarded that return anyway. Inline it: the gate
calls EffectiveMember directly and the test now targets the real method.
Kept blobstore.Store (single impl, but the documented M9 S3/R2 seam) and
control.Daemon (single impl, but breaks the daemon->control import cycle).
2026-06-23 11:52:25 -05:00
fd873a02c3 feat(M8a): device-facing invites with privilege attenuation ✉️🔐
Completes M8a's collaboration surface. A member mints an invite; the
invitee redeems it through the EXISTING /v1/join proof-of-possession flow
and lands enrolled + assigned the bound principal + granted the bound role.

- migration #3: invites table (token_hash → principal/share/role/+s),
  chains 0→1→2→3 — verified on a copy of the real hub DB.
- POST /v1/invite (authed) enforces ATTENUATION server-side via the pure,
  unit-tested meta.MayGrant: never grant above your own role, never touch a
  principal who outranks you, viewers can't grant, editors need +s. On a
  legacy share the inviter is seeded as owner before the explicit flip so
  they (and their same-principal devices) never self-lock-out.
- /v1/join applies a redeemed invite's binding (plain token = v1 join).
- transport.Invite + devbox invite <share> <principal> <role> [--reshare].

Tests: MayGrant attenuation matrix, invite binding round-trip, and the
end-to-end TestInviteFlow (owner invites → flip preserves owner → invitee
redeems into editor → editor-without-+s denied). 18 pkgs -race green;
linux/amd64 + windows cross-build.
2026-06-23 11:31:29 -05:00
81fbc5c81a feat(M8a): principals + per-share roles + write enforcement 👥🔐
V2-SPEC §5.2 (write-side, staged before read-side M9). Migration #2 (rides
the M8 runner, chains 0→1→2 — verified on real .10 data, version 2, all
counts preserved):

- principals table + devices.principal_id (every v1 device backfills to one
  synthetic 'owner' principal — byte-identical to v1 until a share opts in).
- members(share, principal_id, role, can_reshare) + shares.acl_mode. A share
  with zero grants is 'legacy' (every device an implicit owner = v1); the
  first grant flips it to 'explicit' = deny-by-default.
- EffectiveRole(device, share) resolves device→principal→role; legacy⇒owner.
- Push write gate: role>=editor AND the access.writable clamp (which can only
  REMOVE write). Legacy shares reduce to the v1 writable bit exactly.
- devbox-hub member set/rm/list + principal <device> <principal> admin CLI —
  the populate path, so the role layer has a real consumer now (no dead code).

Tests: legacy↔explicit lifecycle, deny-by-default, viewer<editor, HTTP push
gate (403 unmembered/viewer, opens at editor). 18 pkgs -race green; hub
cross-compiles linux/amd64; windows builds.
2026-06-23 11:09:32 -05:00
9a9321adf7 feat(M8): migration runner + per-(share,id) snapshots 🏗️🔑
The v2 foundation (V2-SPEC §5.1). Two things land:

- PRAGMA user_version migration runner in internal/hub/meta: ordered,
  append-only, each step in its own txn with the version bump LAST so a
  crash rolls back cleanly. Backs up an existing DB to <path>.pre-v2.bak
  (VACUUM INTO) before migrating; refuses a DB written by a newer build.
  Every later v2 schema change rides this.

- Re-key snapshots from a GLOBAL id PK to per-(share, id). v1's global id
  meant identical content pushed to two shares collided on one row, so the
  second share never counted its chunk refcounts (undercount) and recorded
  no snapshot row. Per-share rows fix the refcount and let each share own
  its history. Wire id/Head stays the manifest hash — clients unchanged.
  Migration also backfills any share head left rowless by the v1 idempotent
  push, restoring the head-has-a-row invariant. GC reworked to prune per
  (share, id), decrementing each share's chunks and freeing a shared
  manifest blob at most once.

Tests: cross-share refcount, migration versioning + refuse-newer, and a
realistic populated-v1 -> v2 upgrade (data preserved, backup written,
head backfill). All 17 pkgs -race green; hub cross-compiles linux/amd64.

Deferred to M8-3 (conflict sidecar): restore/deploy conflict-copy — a naive
version breaks restore-reproduces-snapshot; it needs the base/ancestor
awareness the sidecar introduces. snapshot_chunks edge table deferred to
M9 (no consumer yet; the runner makes adding it a one-line migration).
2026-06-23 10:46:26 -05:00
9ad2a9da74 fix(dataloss): make hub GC safe against cross-share refcount undercount 🩸🗑️
Snapshots are content-addressed with a GLOBAL id, so two shares with identical
content collide on one snapshots row and the idempotent push skips the refcount
bump — a chunk two share heads both need ends up refcount=1. The old GC then
pruned the 'old' snapshot for one share and freed chunks/manifests the OTHER
share's live head still pointed at. Permanent cross-share data loss.

Rework runGC as mark-and-sweep from every share's live snapshots as roots:
nothing reachable from a kept snapshot is ever deleted, whatever the refcounts
say. Never prune a snapshot that is any share's head. Plus hardening:
- DeleteSnapshot floors refcount at 0 and only decrements if the row existed
  (no negative counts from a double-delete).
- DeleteChunkRow is now conditional (WHERE refcount<=0) and reports if it
  deleted, so a push that re-references a chunk mid-GC isn't corrupted.
Cross-share repro test + existing single-share GC test both green.

Deferred to v2 (documented): proper per-(share,id) refcount accounting — needs
a schema migration of the live hub; the ground-truth GC makes it safe meanwhile.
2026-06-23 02:35:43 -05:00
6d0453d8e3 feat(M6): versioning — log, restore, hub gc 🕰️
- devbox log <share>: hub GET /v1/log (meta.SnapshotLog newest-first), client.Log
- devbox restore <share> <snapshot> [path]: snapshot id == manifest blob hash, so
  syncer.Restore fetches the old manifest, rewrites the file(s) (+deletes extras for
  a whole-tree restore), and pushes -> itself a new reversible snapshot
- devbox-hub gc [--keep N]: prune snapshots beyond the newest N (never the head),
  decrement chunk refcounts, sweep refcount<=0 chunks + manifest blobs from the store
- meta: SnapshotLog, ShareNames, DeletableSnapshots (rowid tiebreaker), DeleteSnapshot
  (tx + refcount--), UnreferencedChunks, DeleteChunkRow
- tests: log order/limit, deletable keeps head+newest, refcount decrement, whole-tree
  + single-path restore, gc end-to-end (old unique chunks freed, head intact)
2026-06-23 01:01:54 -05:00
55175fa2ac feat(M2): hub server + transport client + push engine + CLI 🛰️
- internal/hub: HTTP server (join/publish/have/blob/push/head/metrics), bearer auth,
  blob hash-verify, hand-rolled Prometheus /metrics (no dep)
- internal/transport: device HTTP client for the full wire contract
- internal/syncer: device push engine (build manifest -> upload missing blobs ->
  commit snapshot) + .devignore loader; in-process e2e test (join->publish->push)
- meta: idempotent AddSnapshot (content-addressed re-push advances head, no double
  refcount) + busy_timeout for multi-process CLI access
- cmd/devbox-hub: serve/token/readonly/revoke; cmd/devbox: real join + publish/push
- config: persist bearer + device id

Verified end-to-end with real binaries: secret blocked, node_modules ignored,
re-publish dedups to 0 uploads.
2026-06-22 23:40:18 -05:00
3884f732b5 feat(M2): SQLite hub metadata store 🗄️
- internal/hub/meta: pure-Go modernc.org/sqlite (no CGO -> trivial cross-compile)
- schema: devices, tokens, shares, access(writable bit), snapshots, chunks(refcount)
- AddSnapshot in a tx: insert + bump distinct-chunk refcounts + advance share head
- single access knob = per-(device,share) writable; tokens redeem-once + expiry
- tests: device lifecycle, token redeem-once/expiry, writable default+override,
  shares/snapshots/refcounts (dedup within + across snapshots)
2026-06-22 23:24:55 -05:00