summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKatherine Wu <katherine.wu@mongodb.com>2020-05-14 13:47:20 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-06-02 20:08:49 +0000
commitbecc8e5ecca4260e844725fa71f4ed1164647e4a (patch)
tree6945818b345b2e5bf943b89a2ec11cb0f40b387f /src
parent1468dbb72e5384c58c8dfc19003beed84befecfd (diff)
downloadmongo-becc8e5ecca4260e844725fa71f4ed1164647e4a.tar.gz
SERVER-46625 Improve diagnostics when mongocryptd requests are sent to non-mongocryptd daemon
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/command_generic_argument.cpp4
-rw-r--r--src/mongo/db/command_generic_argument.h6
-rw-r--r--src/mongo/db/commands/explain_cmd.cpp3
-rw-r--r--src/mongo/db/pipeline/aggregation_request.cpp4
-rw-r--r--src/mongo/db/query/find_and_modify_request.cpp4
-rw-r--r--src/mongo/db/query/query_request.cpp6
-rw-r--r--src/mongo/idl/idl_parser.cpp8
-rw-r--r--src/mongo/s/commands/cluster_explain_cmd.cpp3
8 files changed, 38 insertions, 0 deletions
diff --git a/src/mongo/db/command_generic_argument.cpp b/src/mongo/db/command_generic_argument.cpp
index 89c3cd20a87..daf4ccf6e6b 100644
--- a/src/mongo/db/command_generic_argument.cpp
+++ b/src/mongo/db/command_generic_argument.cpp
@@ -116,4 +116,8 @@ bool isReplyStripArgument(StringData arg) {
return filteredSpecialsContains<&SpecialArgRecord::stripFromReply>(arg);
}
+bool isMongocryptdArgument(StringData arg) {
+ return arg == "jsonSchema"_sd;
+}
+
} // namespace mongo
diff --git a/src/mongo/db/command_generic_argument.h b/src/mongo/db/command_generic_argument.h
index 5d4026e9177..69d695250ec 100644
--- a/src/mongo/db/command_generic_argument.h
+++ b/src/mongo/db/command_generic_argument.h
@@ -53,4 +53,10 @@ bool isRequestStripArgument(StringData arg);
*/
bool isReplyStripArgument(StringData arg);
+/**
+ * Returns true if the provided argument is one that should be handled by a mongocryptd process.
+ */
+bool isMongocryptdArgument(StringData arg);
+
+
} // namespace mongo
diff --git a/src/mongo/db/commands/explain_cmd.cpp b/src/mongo/db/commands/explain_cmd.cpp
index 2d3460d6a63..5cc8bc330c8 100644
--- a/src/mongo/db/commands/explain_cmd.cpp
+++ b/src/mongo/db/commands/explain_cmd.cpp
@@ -145,6 +145,9 @@ std::unique_ptr<CommandInvocation> CmdExplain::parse(OperationContext* opCtx,
CommandHelpers::uassertNoDocumentSequences(getName(), request);
std::string dbname = request.getDatabase().toString();
const BSONObj& cmdObj = request.body;
+ uassert(ErrorCodes::FailedToParse,
+ "Unrecognized field 'jsonSchema'. This command may be meant for a mongocryptd process.",
+ !cmdObj.hasField("jsonSchema"_sd));
ExplainOptions::Verbosity verbosity = uassertStatusOK(ExplainOptions::parseCmdBSON(cmdObj));
uassert(ErrorCodes::BadValue,
"explain command requires a nested object",
diff --git a/src/mongo/db/pipeline/aggregation_request.cpp b/src/mongo/db/pipeline/aggregation_request.cpp
index 71eddc792d1..b75fb66a055 100644
--- a/src/mongo/db/pipeline/aggregation_request.cpp
+++ b/src/mongo/db/pipeline/aggregation_request.cpp
@@ -226,6 +226,10 @@ StatusWith<AggregationRequest> AggregationRequest::parseFromBSON(
<< typeName(elem.type())};
}
request.setIsMapReduceCommand(elem.boolean());
+ } else if (isMongocryptdArgument(fieldName)) {
+ return {ErrorCodes::FailedToParse,
+ str::stream() << "unrecognized field '" << elem.fieldName()
+ << "'. This command may be meant for a mongocryptd process."};
} else if (!isGenericArgument(fieldName)) {
return {ErrorCodes::FailedToParse,
str::stream() << "unrecognized field '" << elem.fieldName() << "'"};
diff --git a/src/mongo/db/query/find_and_modify_request.cpp b/src/mongo/db/query/find_and_modify_request.cpp
index b6d89bdc3b3..660cc9c95a5 100644
--- a/src/mongo/db/query/find_and_modify_request.cpp
+++ b/src/mongo/db/query/find_and_modify_request.cpp
@@ -275,6 +275,10 @@ StatusWith<FindAndModifyRequest> FindAndModifyRequest::parseFromBSON(NamespaceSt
writeConcernOptionsSet = true;
writeConcernOptions = sw.getValue();
}
+ } else if (isMongocryptdArgument(field)) {
+ return {ErrorCodes::FailedToParse,
+ str::stream() << "unrecognized field '" << field
+ << "'. This command may be meant for a mongocryptd process."};
} else if (!isGenericArgument(field) &&
!std::count(_knownFields.begin(), _knownFields.end(), field)) {
return {ErrorCodes::Error(51177),
diff --git a/src/mongo/db/query/query_request.cpp b/src/mongo/db/query/query_request.cpp
index dc3113f11c3..df70966c9aa 100644
--- a/src/mongo/db/query/query_request.cpp
+++ b/src/mongo/db/query/query_request.cpp
@@ -367,6 +367,12 @@ StatusWith<std::unique_ptr<QueryRequest>> QueryRequest::parseFromFindCommand(
if (!status.isOK()) {
return status;
}
+ } else if (isMongocryptdArgument(fieldName)) {
+ return Status(ErrorCodes::FailedToParse,
+ str::stream()
+ << "Failed to parse: " << cmdObj.toString()
+ << ". Unrecognized field '" << fieldName
+ << "'. This command may be meant for a mongocryptd process.");
// TODO SERVER-47065: A 4.6 node still has to accept the '_use44SortKeys' field, since
// it could be included in a command sent from a 4.4 mongos. In 4.7 development, this
diff --git a/src/mongo/idl/idl_parser.cpp b/src/mongo/idl/idl_parser.cpp
index 135d49b784b..e78ce27b161 100644
--- a/src/mongo/idl/idl_parser.cpp
+++ b/src/mongo/idl/idl_parser.cpp
@@ -183,6 +183,14 @@ void IDLParserErrorContext::throwMissingField(StringData fieldName) const {
void IDLParserErrorContext::throwUnknownField(StringData fieldName) const {
std::string path = getElementPath(fieldName);
+ if (isMongocryptdArgument(fieldName)) {
+ uasserted(
+ 4662500,
+ str::stream()
+ << "BSON field '" << path
+ << "' is an unknown field. This command may be meant for a mongocryptd process.");
+ }
+
uasserted(40415, str::stream() << "BSON field '" << path << "' is an unknown field.");
}
diff --git a/src/mongo/s/commands/cluster_explain_cmd.cpp b/src/mongo/s/commands/cluster_explain_cmd.cpp
index 3e2b3e16b38..9fd37a65c78 100644
--- a/src/mongo/s/commands/cluster_explain_cmd.cpp
+++ b/src/mongo/s/commands/cluster_explain_cmd.cpp
@@ -170,6 +170,9 @@ std::unique_ptr<CommandInvocation> ClusterExplainCmd::parse(OperationContext* op
CommandHelpers::uassertNoDocumentSequences(getName(), request);
std::string dbName = request.getDatabase().toString();
const BSONObj& cmdObj = request.body;
+ uassert(ErrorCodes::FailedToParse,
+ "Unrecognized field 'jsonSchema'. This command may be meant for a mongocryptd process.",
+ !cmdObj.hasField("jsonSchema"_sd));
ExplainOptions::Verbosity verbosity = uassertStatusOK(ExplainOptions::parseCmdBSON(cmdObj));
// This is the nested command which we are explaining. We need to propagate generic