Selaa lähdekoodia

test: a secret is now ENCRYPTED at rest, and my prediction was wrong

Database 2.17.0 is deployed on the dev box, and the self-correcting canary
did its job: AStoredSecretIsCurrentlyPLAINTEXTatRest failed and said to flip
it. Flipped and renamed to AStoredSecretIsENCRYPTEDatRest, now asserting the
property we want rather than the defect we had.

The correction that matters more. I predicted, in writing and before the
upgrade, that vectorapi_keys and vectorapi_settings would survive the
migration UNENCRYPTED, because their flag read as false and the field names
do not match the sensitive-name patterns. Both came back [encrypted] with
plaintext-required 0, and the boot log shows their rows and history being
encrypted.

Two things I had wrong:

The flag our code asked for landed on the BARE-name collections rather than
the default:-qualified ones, almost certainly via the pre-2.4.5 client bug
where createCollection sent the unqualified name. 2.17.0 merges a
collection's options with those of its bare alias, so the qualified
collections inherited encryption. The exposure and the guard were both real;
the rescue came from somewhere I had not looked.

And getCollectionInfo is not the enforced rule. info default:vectorapi_
settings still reports encrypted: no while that data IS encrypted, because it
reports the collection's own options and not the merged rule in force. So the
flag can be wrong in both directions, and here it was wrong in the
reassuring-to-doubt direction, which is how a careful reading still reached a
false conclusion. encryption-verify's marker is authoritative; the flag is a
hint.

The unconditional createCollection stays. It puts the flag on the collection
we actually read and write, so encryption no longer depends on an alias merge
surviving a future cleanup - but it is hardening, not the rescue the previous
commit message claims, and CLAUDE.md now says so.

Also recorded: encryption-verify holds the global history mutex before 2.17.1
and blocks writes server-wide for the length of the scan (~10 min measured on
live, where a consumer saw a wedged collection), so it must not be run
against a shared database. And the index-route encrypted_field gap is fixed
upstream as FailureDetail overloads, not as new CreateIndexResult fields -
growing a by-value struct changes its size under one soname, which is what
crashed a consumer in 2.7.1.

1253/1253 green, nothing skipped.
fszontagh 1 kuukausi sitten
vanhempi
sitoutus
1a2306b2ef
2 muutettua tiedostoa jossa 29 lisäystä ja 30 poistoa
  1. 4 2
      CLAUDE.md
  2. 25 28
      tests/test_api_integration.cpp

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 4 - 2
CLAUDE.md


+ 25 - 28
tests/test_api_integration.cpp

@@ -3756,19 +3756,21 @@ TEST_F(ApiFixture, BootstrapAsksForEncryptionOnAnAlreadyEXISTINGCollection) {
 
 // --- is a credential actually encrypted at rest? ----------------------------
 //
-// The test above asserts getCollectionInfo()->encrypted, which is THE FLAG.
-// The database team then established, by code reading and a canary of their
-// own, that nothing in the write path reads that flag - so the flag is not
-// evidence about the bytes, and a test asserting it was pinning a mechanism
-// that does not exist. That is the same proxy-not-the-thing failure this file
-// is full of notes about, committed by me.
+// The test above asserts getCollectionInfo()->encrypted, which is THE FLAG,
+// and a flag is not evidence about bytes. Worse than merely weak: measured on
+// 2.17.0, `info default:vectorapi_settings` reports `encrypted: no` while the
+// stored data IS encrypted, because that call reports the collection's OWN
+// options and not the merged rule actually enforced (a bare-name alias can
+// carry the flag). So the flag can be wrong in BOTH directions, and reading it
+// as the answer is how this file's author once concluded that two credential
+// collections would survive the migration unencrypted. They did not.
 //
 // This asserts the PROPERTY: write a credential through our own route, then
 // look for it in the database's data directory. It needs the directory to be
 // readable from here, which it is for the bind-mounted dev container, so the
 // test SKIPS rather than fails when it is not - a skip says "not checked",
 // which is honest, where a pass would be a false assurance.
-TEST_F(ApiFixture, AStoredSecretIsCurrentlyPLAINTEXTatRest) {
+TEST_F(ApiFixture, AStoredSecretIsENCRYPTEDatRest) {
     const char* dataDir = "/data/smartbotic-db/data";
     struct stat st{};
     if (::stat(dataDir, &st) != 0 || !S_ISDIR(st.st_mode)) {
@@ -3800,26 +3802,21 @@ TEST_F(ApiFixture, AStoredSecretIsCurrentlyPLAINTEXTatRest) {
     }
     c.Delete(path.c_str());
 
-    // ASSERTS THE DEFECT, deliberately. The property we want does NOT hold:
-    // collection-level `encrypted=true` encrypts nothing, and the database's
-    // sensitive-field patterns need a dot before the name so our top-level
-    // `value` never matched. Measured here: the canary appears in
-    // `wal/wal-current.log` and in the project's `env/data.mdb`.
+    // FLIPPED on 2026-10-12, by this test failing and telling us to. It used
+    // to assert the DEFECT - that the canary WAS findable on disk - and said
+    // the moment to turn it round would be the release that shipped encryption
+    // at rest. Database 2.17.0 is that release, and this is what a
+    // self-correcting test is for: the suite announced the change rather than
+    // staying green through it or being quietly deleted.
     //
-    // Pinned this way round rather than left failing, for two reasons. A
-    // permanently red test gets ignored, and this one is self-correcting: when
-    // the database ships encryption at rest, THIS TEST FAILS and says so,
-    // which is the moment to flip it back to `hits.empty()` and delete this
-    // comment. A silent skip would have hidden the exposure instead.
-    EXPECT_FALSE(hits.empty())
-        << "A secret is NO LONGER plaintext at rest - the database appears to have shipped "
-           "encryption. Flip this assertion back to hits.empty() and remove the known-defect "
-           "framing; the credentials written before that release are still plaintext and need "
-           "rewriting.";
-    if (!hits.empty()) {
-        GTEST_LOG_(WARNING)
-            << "KNOWN DEFECT: a project secret written through our own route is PLAINTEXT in "
-               "the database's data directory, and therefore in every backup of it. Files:\n"
-            << hits;
-    }
+    // Now it asserts the PROPERTY, which is the only form worth having. Not a
+    // flag, not getCollectionInfo, not a capability name: a credential is
+    // written through our own HTTP route and then looked for in the bytes on
+    // disk. `grep -F`, because a bare `$ENC$` pattern is a regex anchor and
+    // matches nothing - a false clean.
+    EXPECT_TRUE(hits.empty())
+        << "A project secret written through our own route is PLAINTEXT in the database's data "
+           "directory, and therefore in every backup of it. Encryption at rest is not in "
+           "effect for this collection. Files:\n"
+        << hits;
 }

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä