|
@@ -3597,3 +3597,58 @@ TEST_F(ApiFixture, AFilteredSearchREPORTSWhichPathAnsweredIt) {
|
|
|
EXPECT_FALSE(j.at("scan_capped").get<bool>()) << j.dump();
|
|
EXPECT_FALSE(j.at("scan_capped").get<bool>()) << j.dump();
|
|
|
EXPECT_EQ(j.at("scanned"), 0) << j.dump();
|
|
EXPECT_EQ(j.at("scanned"), 0) << j.dump();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+TEST_F(ApiFixture, EverySecretBearingSTOREcreatesANEncryptedCollection) {
|
|
|
|
|
+ // Prompted by the database team finding that their built-in
|
|
|
|
|
+ // sensitive-FIELD patterns (`*.password`, `*.api_key`, `*.secret`, ...)
|
|
|
|
|
+ // need a dot before the name, so a TOP-LEVEL field of those names is
|
|
|
|
|
+ // stored in plaintext. We store `{"value": ...}` and `{"key": ...}` at the
|
|
|
|
|
+ // top level, and `key` is not in those patterns at any nesting - so if we
|
|
|
|
|
+ // relied on field matching, every credential we hold would be plaintext.
|
|
|
|
|
+ //
|
|
|
|
|
+ // We do not: each store creates its collection with the COLLECTION-level
|
|
|
|
|
+ // encrypted flag, which is independent of field names. This pins that,
|
|
|
|
|
+ // because it is one boolean in one line and the consequence of it flipping
|
|
|
|
|
+ // is every API key and project secret readable from a stolen data
|
|
|
|
|
+ // directory.
|
|
|
|
|
+ //
|
|
|
|
|
+ // Each store is pointed at a FRESH collection name rather than asserting
|
|
|
|
|
+ // on the long-lived shared ones. `encrypted` is a CREATION-TIME option, so
|
|
|
|
|
+ // a collection made before a store passed the flag - or by a database that
|
|
|
|
|
+ // ignored it - stays plaintext forever, and asserting on those would test
|
|
|
|
|
+ // the history of this dev database rather than the behaviour of this code.
|
|
|
|
|
+ // See the note below about the pre-existing one that is NOT encrypted.
|
|
|
|
|
+ const std::string suffix = std::to_string(::time(nullptr));
|
|
|
|
|
+
|
|
|
|
|
+ // bootstrap() is the creating call in each store. It writes a seed row,
|
|
|
|
|
+ // which is fine here: these collections are dropped below.
|
|
|
|
|
+ svapi::KeyStore keys(*db_, "enc_probe_keys_" + suffix);
|
|
|
|
|
+ keys.bootstrap("");
|
|
|
|
|
+ svapi::SettingsStore settings(*db_, "enc_probe_settings_" + suffix, "current");
|
|
|
|
|
+ settings.bootstrap("");
|
|
|
|
|
+
|
|
|
|
|
+ for (const auto& name : {"enc_probe_keys_" + suffix, "enc_probe_settings_" + suffix}) {
|
|
|
|
|
+ const auto info = db_->client().getCollectionInfo(svapi::qualify("default", name));
|
|
|
|
|
+ ASSERT_TRUE(info.has_value()) << name << " was not created";
|
|
|
|
|
+ EXPECT_TRUE(info->encrypted) << name << " holds credentials and is NOT encrypted at rest";
|
|
|
|
|
+ db_->client().dropCollection(svapi::qualify("default", name));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // The project secret store, through the real API so the route is covered
|
|
|
|
|
+ // too. Its collection is created per project by the fixture's own project.
|
|
|
|
|
+ auto c = admin();
|
|
|
|
|
+ const std::string secrets = "/api/v1/projects/" + project_ + "/secrets/PROBE_SECRET";
|
|
|
|
|
+ ASSERT_EQ(c.Put(secrets.c_str(), nlohmann::json{{"value","s3cret"}}.dump(),
|
|
|
|
|
+ "application/json")->status / 100, 2);
|
|
|
|
|
+ const auto sec = db_->client().getCollectionInfo(svapi::qualify(project_, "vectorapi_secrets"));
|
|
|
|
|
+ ASSERT_TRUE(sec.has_value());
|
|
|
|
|
+ EXPECT_TRUE(sec->encrypted)
|
|
|
|
|
+ << "project secrets, including mail passwords, are NOT encrypted at rest";
|
|
|
|
|
+ c.Delete(secrets.c_str());
|
|
|
|
|
+
|
|
|
|
|
+ // The falsifying half: a collection with no credentials in it is NOT
|
|
|
|
|
+ // encrypted, so this is detecting the flag rather than finding everything
|
|
|
|
|
+ // encrypted for some unrelated reason.
|
|
|
|
|
+ const auto plain = db_->client().getCollectionInfo(svapi::qualify(project_, "vectorapi_functions"));
|
|
|
|
|
+ if (plain) EXPECT_FALSE(plain->encrypted) << "the function registry should be plaintext";
|
|
|
|
|
+}
|