diff options
author | Marcos José Grillo Ramirez <marcos.grillo@mongodb.com> | 2022-04-05 17:11:59 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-04-05 20:28:45 +0000 |
commit | 91a607d3a2c748ead682c1a44d37263254de26f8 (patch) | |
tree | 1245c2efd4eb7ebcc46f8128c292c8df8744ec3d /src/mongo/db/s/config/configsvr_set_cluster_parameter_command.cpp | |
parent | c96f8dacc4c71b4774c932a07be4fac71b6db628 (diff) | |
download | mongo-91a607d3a2c748ead682c1a44d37263254de26f8.tar.gz |
SERVER-63870 Integrate replica set setClusterParameter into POS with replay protection
Diffstat (limited to 'src/mongo/db/s/config/configsvr_set_cluster_parameter_command.cpp')
-rw-r--r-- | src/mongo/db/s/config/configsvr_set_cluster_parameter_command.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
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<ServerParameterService> sps = + std::make_unique<ClusterParameterService>(); + 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}); |