Răsfoiți Sursa

docs: the reseal cost is one-off per collection, not per startup

The reseal is requested only when createCollection actually changes the
options, so once our bootstraps have set the flag, later startups do nothing
and ask for nothing. My previous note did not say so and could be read as a
standing tax on every restart.

Upstream is considering requesting the reseal only when the upgrade actually
rewrote something - our keys and settings were already ciphertext via the
bare-alias merge, so the flag change wrote no plaintext and arguably need not
compact at all. Not in 2.17.1, so the three-step window stands as written.
fszontagh 1 lună în urmă
părinte
comite
2223978f96
1 a modificat fișierele cu 1 adăugiri și 1 ștergeri
  1. 1 1
      CLAUDE.md

+ 1 - 1
CLAUDE.md

@@ -91,7 +91,7 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
   **THE COMING FIX IS SAFE FOR US, and the reason is worth keeping because it is not obvious: NOTHING queries a credential collection by value.** The database asked before releasing, because full-value encryption uses a random IV, so a FILTER on an encrypted field never matches and an INDEX on one indexes ciphertext. Audited: `KeyStore::lookup()` scans an IN-MEMORY snapshot (`k.key == key`) loaded by a `find()` carrying only a limit, so authentication is a full read compared in process - it never asks the database to match a key. Settings and project secrets are addressed by DOCUMENT ID throughout (the secret's NAME is its id). The global settings document is told apart from the per-project ones by `p.project.empty()`, evaluated in our process after a full read, which LOOKS like a value query and is not. `opts.filters` is set in exactly three places service-wide - `vector_search.cpp`, `function_run_log.cpp` (`function_id`) and `host_context.cpp` (`ctx.collections`) - none of them a credential collection, and no index is declared on any of the three.
   **The adjacent hazard that WOULD break: `vectorapi_function_runs` is filtered by `function_id`.** It, the job queue, the function registry and the collection registry are all deliberately `encrypted=false`, and user collections are always created `encrypted=false` (`handlers/collections.cpp:74`) so a user's index is never over ciphertext. If anyone ever flips the flag on those, that filter stops matching silently.
   **THE FLAG WAS ASKED FOR AND NEVER APPLIED, AND THIS NOTE USED TO CLAIM THE OPPOSITE.** It said our startup calls `createCollection(..., encrypted=true, ...)` "unconditionally", so the three stores would "repair themselves on the next restart". Both halves were false. Every call site was guarded by `if (!getCollectionInfo(...).has_value())`, so the create was skipped for a collection that ALREADY EXISTED - which is exactly the case that needed it, because the collection had been created implicitly by an earlier write, with the default flag of `false`. Measured on the dev database: `vectorapi_keys` and `vectorapi_settings` report `encrypted: no` while the code reads as though it had asked for `true`, and only `<project>:vectorapi_secrets` (a later store, whose collection our code did create) reports `yes`. A guard that skips the repair in precisely the broken case is worse than no guard, and the suite could not see it because the flag test deliberately points each store at a FRESH collection name - correct for testing the creating path, and the reason it was blind to this one.
-  **THAT UNCONDITIONAL CALL COSTS A SECOND WINDOW ON 2.17.x, AND IT MUST BE PLANNED RATHER THAN DISCOVERED.** Under 2.17.x, re-issuing `createCollection(existing, encrypted=true)` performs the ONLINE encryption upgrade when it changes anything - and a collection reaching encryption through the bare-alias option merge still has its OWN flag unset, so our call does change something: it moves the flag where it belongs. That requests a RESEAL at the next boot, and the reseal **compacts every project**, which is the 167-second term measured above. Seen for real: the dev box's restart onto 2.17.1 took ~3.5 minutes instead of ~15 seconds, caused by our own bootstraps having flipped those flags under 2.17.0.
+  **THAT UNCONDITIONAL CALL COSTS A SECOND WINDOW ON 2.17.x, AND IT MUST BE PLANNED RATHER THAN DISCOVERED.** Under 2.17.x, re-issuing `createCollection(existing, encrypted=true)` performs the ONLINE encryption upgrade when it changes anything - and a collection reaching encryption through the bare-alias option merge still has its OWN flag unset, so our call does change something: it moves the flag where it belongs. That requests a RESEAL at the next boot, and the reseal **compacts every project**, which is the 167-second term measured above. Seen for real: the dev box's restart onto 2.17.1 took ~3.5 minutes instead of ~15 seconds, caused by our own bootstraps having flipped those flags under 2.17.0. **It is a ONE-OFF, not a standing tax:** the reseal is requested only when `createCollection` actually CHANGES the options, so once the flag is set every later startup does nothing and asks for nothing. The cost is one compacting restart per collection that gains its flag. Upstream is also considering requesting the reseal only when the upgrade actually REWROTE something - our keys and settings were already ciphertext through the alias, so their flag change wrote no plaintext anywhere and arguably need not cost a compaction at all - but that is NOT in 2.17.1, so plan step 3 as written.
   So the prod sequence has THREE steps and two compactions, not one: upgrade the database (first-boot migration, 190 s measured), start vectorapi so the bootstraps move the flags, then **restart the database inside the SAME window** so the reseal happens while everyone is expecting an outage. Skip that last step and a routine restart weeks later silently takes three minutes with no visible cause - the same shape as the `/etc` mode 0751 trap below, and the reason "under 10 minutes" is the right thing to ask consumers to approve for that window rather than three.
   **Today's release is unaffected**: prod runs 2.14.0, where the upgrade branch does not exist and the re-call is a plain no-op. The cost arrives only with 2.17.x.
   **So `KeyStore::bootstrap` and `SettingsStore::bootstrap` now call `createCollection` UNCONDITIONALLY**, which puts the flag on the collection we actually read and write. Read the correction two paragraphs down before relying on the reasoning that motivated it. Re-issuing it against an existing collection switches encryption ON (never off), encrypting the stored rows and their history; against an older server it is a no-op, so it is safe on every version we support. Verified safe before shipping, not reasoned about: `MemoryStore::createCollection`'s existing-collection path only acts on a `vectorDimension > 0` and on `defaultTtlSeconds`, and we pass 0 for every option but the flag, while `upgradeEncryptionOptions` only ever flips false to true and appends sensitive fields. `BootstrapAsksForEncryptionOnAnAlreadyEXISTINGCollection` pins it with a CONTROL collection that is never bootstrapped, so the assertion cannot pass for an unrelated reason, and it asserts the pre-existing row survives the re-call.