From 91a607d3a2c748ead682c1a44d37263254de26f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Jos=C3=A9=20Grillo=20Ramirez?= Date: Tue, 5 Apr 2022 17:11:59 +0000 Subject: SERVER-63870 Integrate replica set setClusterParameter into POS with replay protection --- .../configsvr_set_cluster_parameter_command.cpp | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/mongo/db/s/config/configsvr_set_cluster_parameter_command.cpp') diff --git a/src/mongo/db/s/config/configsvr_set_cluster_parameter_command.cpp b/src/mongo/db/s/config/configsvr_set_cluster_parameter_command.cpp index beb08387bb7..6a0109194f6 100644 --- a/src/mongo/db/s/config/configsvr_set_cluster_parameter_command.cpp +++ b/src/mongo/db/s/config/configsvr_set_cluster_parameter_command.cpp @@ -33,6 +33,7 @@ #include "mongo/db/auth/authorization_session.h" #include "mongo/db/commands.h" +#include "mongo/db/commands/set_cluster_parameter_invocation.h" #include "mongo/db/s/config/configsvr_coordinator_service.h" #include "mongo/db/s/config/set_cluster_parameter_coordinator.h" #include "mongo/idl/cluster_server_parameter_gen.h" @@ -62,6 +63,32 @@ public: "featureFlagClusterWideConfig not enabled", gFeatureFlagClusterWideConfig.isEnabled(serverGlobalParams.featureCompatibility)); + // Validate parameter before creating coordinator. + { + BSONObj cmdParamObj = request().getCommandParameter(); + BSONElement commandElement = cmdParamObj.firstElement(); + StringData parameterName = commandElement.fieldName(); + std::unique_ptr sps = + std::make_unique(); + const ServerParameter* serverParameter = sps->getIfExists(parameterName); + + uassert(ErrorCodes::IllegalOperation, + str::stream() << "Unknown Cluster Parameter " << parameterName, + serverParameter != nullptr); + + uassert(ErrorCodes::IllegalOperation, + "Cluster parameter value must be an object", + BSONType::Object == commandElement.type()); + + BSONObjBuilder clusterParamBuilder; + clusterParamBuilder << "_id" << parameterName; + clusterParamBuilder.appendElements(commandElement.Obj()); + + BSONObj clusterParam = clusterParamBuilder.obj(); + + uassertStatusOK(serverParameter->validate(clusterParam)); + } + SetClusterParameterCoordinatorDocument coordinatorDoc; coordinatorDoc.setConfigsvrCoordinatorMetadata( {ConfigsvrCoordinatorTypeEnum::kSetClusterParameter}); -- cgit v1.2.1