Просмотр исходного кода

docs: grep -F alone returns 0 for EVERYTHING on a snapshot or WAL - use strings -a with a positive control

Measured: grep -c -F novitax returns 0 on a WAL where strings -a shows
5957 hits. Custom framing (CALWAL01/CALSNAP1) with embedded NULs, and the
files are not compressed, so the text is present and grep will not
surface it.

That makes the obvious credential audit a check that cannot fail: it
reports a clean bill of health while being incapable of reporting
anything. Requires a positive control on a known-present string before
any zero is believed.
fszontagh 1 месяц назад
Родитель
Сommit
75f5935ba6
1 измененных файлов с 1 добавлено и 1 удалено
  1. 1 1
      CLAUDE.md

+ 1 - 1
CLAUDE.md

@@ -152,7 +152,7 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
   **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.
   **`ProjectSecretStore::ensure` deliberately KEEPS its guard**, and the difference is the call path rather than the intent: it runs on every secret READ (the runner builds `ctx.env` through it) and `CreateCollection` is REFUSED by a read-only database, so making it unconditional would turn every function run into a 503 during read-only recovery - trading a live outage for a hardening step that collection does not need.
-  **What database 2.17.0 actually does, confirmed from their source and then independently by them:** collection-level `encrypted=true` encrypts EVERY non-null value in the collection whatever the field is called (`isEncryptedPath` returns true for any non-empty path when the rule is whole-document). Strings become `$ENC$...`, and numbers, bools, objects and arrays become `$ENCJ$...` and read back with their original type. The built-in sensitive-name patterns match a WHOLE path segment, so `openai_api_key` does NOT match `api_key` - which is why the collection flag, not the field name, is the only thing that was ever going to protect us. Grep a data file with `grep -F`: a bare `$ENC$` pattern is a regex anchor and matches nothing.
+  **What database 2.17.0 actually does, confirmed from their source and then independently by them:** collection-level `encrypted=true` encrypts EVERY non-null value in the collection whatever the field is called (`isEncryptedPath` returns true for any non-empty path when the rule is whole-document). Strings become `$ENC$...`, and numbers, bools, objects and arrays become `$ENCJ$...` and read back with their original type. The built-in sensitive-name patterns match a WHOLE path segment, so `openai_api_key` does NOT match `api_key` - which is why the collection flag, not the field name, is the only thing that was ever going to protect us. Grep a data file with `grep -F`: a bare `$ENC$` pattern is a regex anchor and matches nothing. **AND `grep -F` ALONE IS STILL NOT ENOUGH - ON THESE FILES IT RETURNS 0 FOR EVERYTHING, INCLUDING THINGS THAT ARE CERTAINLY THERE, SO IT IS A CHECK THAT CANNOT FAIL.** Measured 2026-10-19 on a snapshot and a WAL segment: `grep -c -F novitax` returned **0** on a WAL that `strings -a | grep -c -F novitax` shows **5957** times. The files carry custom framing (`CALWAL01`, `CALSNAP1` magic) with embedded NULs, and they are NOT compressed - gzip still halves them - so the text is right there and grep simply will not surface it. **Use `strings -a`, and ALWAYS run a POSITIVE CONTROL first: grep for a collection or project name you know is in the file, and do not believe a zero until a known-present string returns non-zero.** Without that control the audit reads as a clean bill of health while being incapable of reporting anything, which is the most dangerous possible result for a credential check - and I filed exactly that conclusion before the control caught it.
   **I PREDICTED THOSE TWO COLLECTIONS WOULD SURVIVE THE MIGRATION UNENCRYPTED, AND THEY DID NOT.** The prediction was written down before the upgrade, which is the only reason it could be checked rather than quietly reinterpreted afterwards. Measured after 2.17.0: `default:vectorapi_keys` and `default:vectorapi_settings` are both `[encrypted]` with plaintext-required 0, and the boot log shows their rows and history versions being encrypted. The cause is an accident of history. The `encrypted=true` our code asked for landed on the BARE-name collections (`vectorapi_keys`, not `default:vectorapi_keys`), almost certainly through the pre-2.4.5 client bug where `createCollection` sent the unqualified name and the options went to a phantom collection - and 2.17.0 MERGES a collection's options with those of its bare alias, because migration files use bare names, so the qualified collections inherited the flag. **The exposure was real and the guard was real; the rescue came from somewhere I had not looked, so my conclusion was wrong in the direction of alarm.** The fix remains right for a reason that does not depend on the accident - encryption no longer rests on an alias merge surviving a future cleanup - but it is HARDENING, not the rescue its commit message claims.
   **`getCollectionInfo` / `info` IS NOT THE ENFORCED RULE, and that is how the wrong prediction happened.** `info default:vectorapi_settings` still reports `encrypted: no` on 2.17.0 while that collection's data IS encrypted, because it reports the collection's OWN options rather than the merged rule in force. So the flag can be wrong in BOTH directions: false while encryption is active, and (before 2.17.0) true while nothing was encrypted at all. **Treat `encryption-verify`'s `[encrypted]` marker as authoritative and the flag as a hint**; the database is fixing `info` in 2.17.1. This is the lesson this file keeps relearning, with a new edge: a field recording an intention is not a measurement of the outcome, and when it disagrees with the bytes it can disagree in the REASSURING direction as easily as the alarming one.
   **`encryption-verify` BLOCKS WRITES SERVER-WIDE before 2.17.1, so never run it against a shared database.** It audits history through the same routine the migration uses to rewrite it, and that routine holds the GLOBAL history mutex for the whole scan, so every write recording a history version - update, patch, upsert of an existing row, delete, in ANY collection - waits for it. Measured at ~10 minutes on the live box, during which a consumer saw a collection wedged with Deadline Exceeded. Use a scratch server until 2.17.1.