|
|
@@ -205,10 +205,36 @@ static std::optional<uint64_t> expiryOverrideFrom(const Req& request) {
|
|
|
static_cast<uint64_t>(request.ttl_seconds()) * 1000ULL;
|
|
|
}
|
|
|
|
|
|
+// v2.17.1 - "project:_name" is reserved. A leading '_' marks a system
|
|
|
+// collection, but the checks disagreed on WHERE to look: the LMDB mirror tests
|
|
|
+// the collection part (and skips it), the read paths test the whole qualified
|
|
|
+// name (and go to LMDB). So a write to "app:_x" answered ok, lived only in
|
|
|
+// memory and the WAL, and no read could ever find it - silently, since 2.3.0.
|
|
|
+// Refused for reads and writes alike, before any handler work. Bare "_name"
|
|
|
+// (the global system collections) is unchanged.
|
|
|
+static grpc::Status refuseReservedName(const grpc::ServerContext* context, const std::string& qualified) {
|
|
|
+ const auto colon = qualified.find(':');
|
|
|
+ if (colon == std::string::npos || colon + 1 >= qualified.size() || qualified[colon + 1] != '_') {
|
|
|
+ return grpc::Status::OK;
|
|
|
+ }
|
|
|
+ attachErrorDetail(const_cast<grpc::ServerContext*>(context),
|
|
|
+ {{"reason", "reserved_collection_name"},
|
|
|
+ {"fields", nlohmann::json::array({qualified})}});
|
|
|
+ return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT,
|
|
|
+ "collection name '" + qualified +
|
|
|
+ "' is reserved: a name starting with '_' inside a project is an "
|
|
|
+ "internal name. Choose a name that does not start with '_'.");
|
|
|
+}
|
|
|
+
|
|
|
grpc::Status DatabaseGrpcImpl::gate(const grpc::ServerContext* context,
|
|
|
const std::string& qualified,
|
|
|
smartbotic::database::Access access,
|
|
|
- smartbotic::database::Decision& out) const {
|
|
|
+ smartbotic::database::Decision& out,
|
|
|
+ bool allowReservedName) const {
|
|
|
+ // v2.17.1 - "project:_name" is reserved (see refuseReservedName).
|
|
|
+ if (!allowReservedName) {
|
|
|
+ if (auto st = refuseReservedName(context, qualified); !st.ok()) return st;
|
|
|
+ }
|
|
|
// Fast path: no project has security enabled, which is the default and the
|
|
|
// whole pre-2.8.0 world. One relaxed atomic load.
|
|
|
if (!policy_manager_.anyProjectSecured()) {
|
|
|
@@ -1567,6 +1593,10 @@ grpc::Status DatabaseGrpcImpl::Find(
|
|
|
const pb::FindRequest* request,
|
|
|
pb::FindResponse* response
|
|
|
) {
|
|
|
+ // v2.17.1 - before the existence check, so a reserved name is refused
|
|
|
+ // whether or not an older server left such a collection behind.
|
|
|
+ if (auto st = refuseReservedName(context, request->collection()); !st.ok()) return st;
|
|
|
+
|
|
|
// Resolve view to real collection (if applicable)
|
|
|
std::string targetCollection = request->collection();
|
|
|
std::optional<ViewInfo> view;
|
|
|
@@ -2455,8 +2485,11 @@ grpc::Status DatabaseGrpcImpl::DropCollection(
|
|
|
pb::DropCollectionResponse* response
|
|
|
) {
|
|
|
// v2.8.0 — access gate. Destructive; must never be reachable without a write grant.
|
|
|
+ // v2.17.1: a reserved "project:_name" may still be DROPPED, so the empty
|
|
|
+ // collections the pre-2.17.1 bug left behind can be removed.
|
|
|
smartbotic::database::Decision dec;
|
|
|
- if (auto st = gate(context, request->name(), smartbotic::database::Access::Write, dec); !st.ok()) {
|
|
|
+ if (auto st = gate(context, request->name(), smartbotic::database::Access::Write, dec,
|
|
|
+ /*allowReservedName=*/true); !st.ok()) {
|
|
|
return st;
|
|
|
}
|
|
|
|
|
|
@@ -2611,6 +2644,21 @@ grpc::Status DatabaseGrpcImpl::GetCollectionInfo(
|
|
|
}
|
|
|
|
|
|
*response->mutable_info() = toProtoCollInfo(*info);
|
|
|
+ // v2.17.1 - report the encryption that is ENFORCED: the collection's own
|
|
|
+ // options merged with its bare/qualified alias (encryptionOptionsFor), the
|
|
|
+ // rule every write and the at-rest migration apply. Reporting only the
|
|
|
+ // collection's own flag said "encrypted: no" for collections whose values
|
|
|
+ // were encrypted through the alias (found on a live server: options set on
|
|
|
+ // a bare name by a pre-2.4.5 client).
|
|
|
+ {
|
|
|
+ bool enc = false;
|
|
|
+ std::vector<std::string> fields;
|
|
|
+ store_.encryptionOptionsFor(request->name(), enc, fields);
|
|
|
+ auto* opts = response->mutable_info()->mutable_options();
|
|
|
+ opts->set_encrypted(enc);
|
|
|
+ opts->clear_sensitive_fields();
|
|
|
+ for (const auto& f : fields) opts->add_sensitive_fields(f);
|
|
|
+ }
|
|
|
response->set_found(true);
|
|
|
|
|
|
return grpc::Status::OK;
|
|
|
@@ -3330,10 +3378,11 @@ grpc::Status DatabaseGrpcImpl::VerifyEncryption(
|
|
|
}
|
|
|
uint64_t versions = 0;
|
|
|
if (auto* hs = service_.historyStore()) {
|
|
|
- hs->rewrite(coll, [&](DocumentVersion& v) {
|
|
|
- ++versions;
|
|
|
+ // Read-only, no append lock: rewrite() would stall every
|
|
|
+ // history-recording write server-wide while a large file is
|
|
|
+ // read (minutes on a 230 MB file, found on a live server).
|
|
|
+ versions = hs->forEach(coll, [&](const std::string&, const DocumentVersion& v) {
|
|
|
encryption_.auditTree(v.data(), rule, hist);
|
|
|
- return false; // audit only: nothing is written
|
|
|
});
|
|
|
}
|
|
|
a->set_rows(n);
|