Key rotation re-seals items' stored bytes, so it can't grow over the quota (#996) #36

Open
backmeupplz wants to merge 2 commits from board/996-6d4dad into main
Owner

Part 2 of #996 (rotations over the quota). Part 1 (a vault's charge moving without a quota check) waits on a product decision and is not in this PR.

What changes

  • Vault::rotate (core/src/vault.rs) now opens each item's stored blob with the current key and re-seals those exact bytes under the new key, instead of re-serialising the parsed Item. A rotated blob is now byte-for-byte the same length, so push_within_quota (after.0 > before.0) and the stage allowance (all <= items) hold with equality, and removing a member keeps working over the quota as DESIGN promises. It also keeps fields this client doesn't know. If a blob can't be opened (it shouldn't, since rotate requires no pending changes), it falls back to the old re-serialisation.
  • This fixes it at the source rather than loosening the server. The ticket's two server-side options both weaken the quota that part 1 is meant to tighten: per-item slack compounds with every rotation, and comparing item counts lets each item grow up to MAX_BLOB.

Test: storage_quota plants an item sealed more compactly than this client would serialise it (no kind/title, 256 bytes padded vs 512 for ours). Over the quota, revoke succeeds and the stored blob stays 297 bytes. Against the old rotate, the same test fails at the revoke with 507.

Known gaps (in DESIGN.md): rotations by older clients still re-serialise items. The rotation's manifest is still serialised anew, so a vault name another client wrote more compactly could still cross a step.

🤖 Generated with Claude Code

Part 2 of #996 (rotations over the quota). Part 1 (a vault's charge moving without a quota check) waits on a product decision and is not in this PR. **What changes** - `Vault::rotate` (core/src/vault.rs) now opens each item's stored blob with the current key and re-seals those exact bytes under the new key, instead of re-serialising the parsed `Item`. A rotated blob is now byte-for-byte the same length, so `push_within_quota` (`after.0 > before.0`) and the stage allowance (`all <= items`) hold with equality, and removing a member keeps working over the quota as DESIGN promises. It also keeps fields this client doesn't know. If a blob can't be opened (it shouldn't, since `rotate` requires no pending changes), it falls back to the old re-serialisation. - This fixes it at the source rather than loosening the server. The ticket's two server-side options both weaken the quota that part 1 is meant to tighten: per-item slack compounds with every rotation, and comparing item counts lets each item grow up to `MAX_BLOB`. **Test:** `storage_quota` plants an item sealed more compactly than this client would serialise it (no `kind`/`title`, 256 bytes padded vs 512 for ours). Over the quota, `revoke` succeeds and the stored blob stays 297 bytes. Against the old `rotate`, the same test fails at the revoke with 507. **Known gaps (in DESIGN.md):** rotations by older clients still re-serialise items. The rotation's manifest is still serialised anew, so a vault name another client wrote more compactly could still cross a step. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Key rotation re-seals each item's stored bytes, so it can't grow over the quota (#996)
Some checks failed
Apple / Apple (pull_request) Successful in 27s
Android / android (pull_request) Has been cancelled
CI / check (pull_request) Has been cancelled
CI / wasm (pull_request) Has been cancelled
3a6ef3b559
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rotation comment: which unknown fields re-serialising would lose
All checks were successful
Apple / Apple (pull_request) Successful in 35s
CI / wasm (pull_request) Successful in 8m7s
CI / check (pull_request) Successful in 11m36s
Android / android (pull_request) Successful in 31m22s
4ccb479857
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
All checks were successful
Apple / Apple (pull_request) Successful in 35s
CI / wasm (pull_request) Successful in 8m7s
CI / check (pull_request) Successful in 11m36s
Android / android (pull_request) Successful in 31m22s
This pull request has changes conflicting with the target branch.
  • DESIGN.md
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'board/996-6d4dad:board/996-6d4dad'
git switch 'board/996-6d4dad'
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
backmeupplz/plaintext!36
No description provided.