Browse Source

docs: nothing queries a credential collection by value, so the encryption fix is safe

fszontagh 1 month ago
parent
commit
250f6f33a2
1 changed files with 3 additions and 0 deletions
  1. 3 0
      CLAUDE.md

+ 3 - 0
CLAUDE.md

@@ -88,6 +88,9 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
   **Measured here, not taken on report:** a project secret written through our own HTTP route was found in plaintext in `wal/wal-current.log` and in the project's `env/data.mdb`. `AStoredSecretIsCurrentlyPLAINTEXTatRest` does exactly that, and asserts the DEFECT so the suite stays honest and green while being self-correcting: when the database ships encryption at rest, that test fails and says to flip it.
   **AND I HAD A TEST ASSERTING THE OPPOSITE.** It read `getCollectionInfo()->encrypted` and presented a flag as evidence about bytes, which is the same proxy-not-the-thing failure this file is full of warnings about. It is now named `EachCredentialStoreSetsTheEncryptedFLAG_whichProtectsNothing` and says so. **A flag that records an intention is not a measurement of the outcome** - if a security property matters, assert the property: write a canary and look for it on disk.
   Until the database ships encryption at rest, the only reliable protection is encrypting CLIENT-SIDE before the value is stored.
+  **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.
+  Our startup already calls `createCollection(..., encrypted=true, ...)` unconditionally, so once the database lets that switch the flag on an EXISTING collection, the three repair themselves on the next restart - by accident rather than by design, so verify it with the canary rather than assuming it.
 - **Project secrets** live in `<project>:vectorapi_secrets`, encrypted and deliberately NOT in the collection registry - so the documents API and `ctx.collections` both 404 it, and even a policy granting every collection cannot read it. Writes are admin-only; no GET ever returns a value. A `SVAPI_FN_<project>__<NAME>` host variable WINS over a stored secret of the same name, which is the break-glass a stolen API credential cannot shadow.
 - **The runner SUBSCRIBES to project settings; it does not poll.** `ProjectWallMax` wraps a `SettingsStore` with `reloadAll()` plus `startWatch()`, so a changed cap reaches the next run immediately. It used to be a hand-rolled cache on a `project_budget_ttl_sec` TTL, which made clearing a cap look broken for up to 15 s and produced a false bug report. **`reloadAll()`, never `bootstrap()`** - bootstrap WRITES, seeding the settings document, and a runner must never author configuration it only reads.
 - **The runner's `runtime` ceilings are boot-time only**, unlike every hot-reloading setting in the server: QuickJS fixes a runtime's memory limit at creation, so changing one live would mean draining and recreating the whole pool. Editing them means restarting the runner - cheap, because vectorapi answers 503 for that moment and stores nothing unvalidated. By contrast `function_egress_blocked_cidrs` / `function_egress_allow_private` DO hot-reload, because they are read per run.