summaryrefslogtreecommitdiff
path: root/src/mongo/db/s
diff options
context:
space:
mode:
authorBen Caimano <ben.caimano@10gen.com>2021-03-30 20:39:45 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-04-01 16:41:07 +0000
commita89fdb7fed2d35a709c7eabc39d3ba36a075b239 (patch)
treea002a259a00445054bae1dbbee9e23d33e5b3c26 /src/mongo/db/s
parentfa9e51dd3791efb8c45121dee1974debd4d9b5fc (diff)
downloadmongo-a89fdb7fed2d35a709c7eabc39d3ba36a075b239.tar.gz
SERVER-52944 Add additional audit sharding tests
Diffstat (limited to 'src/mongo/db/s')
-rw-r--r--src/mongo/db/s/config/configsvr_create_database_command.cpp2
-rw-r--r--src/mongo/db/s/config/configsvr_enable_sharding_command.cpp2
-rw-r--r--src/mongo/db/s/config/configsvr_refine_collection_shard_key_command.cpp5
-rw-r--r--src/mongo/db/s/config/configsvr_shard_collection_command.cpp3
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp2
-rw-r--r--src/mongo/db/s/shardsvr_create_collection_command.cpp4
6 files changed, 13 insertions, 5 deletions
diff --git a/src/mongo/db/s/config/configsvr_create_database_command.cpp b/src/mongo/db/s/config/configsvr_create_database_command.cpp
index b34651b73ca..3d351a57baf 100644
--- a/src/mongo/db/s/config/configsvr_create_database_command.cpp
+++ b/src/mongo/db/s/config/configsvr_create_database_command.cpp
@@ -78,6 +78,8 @@ public:
uassert(ErrorCodes::BadValue,
str::stream() << "Enable sharding can only be set to `true`",
*request().getEnableSharding());
+
+ audit::logEnableSharding(opCtx->getClient(), dbname);
}
auto dbt = ShardingCatalogManager::get(opCtx)->createDatabase(
diff --git a/src/mongo/db/s/config/configsvr_enable_sharding_command.cpp b/src/mongo/db/s/config/configsvr_enable_sharding_command.cpp
index 6a20e63a6a0..c056f161311 100644
--- a/src/mongo/db/s/config/configsvr_enable_sharding_command.cpp
+++ b/src/mongo/db/s/config/configsvr_enable_sharding_command.cpp
@@ -115,7 +115,7 @@ public:
: boost::optional<ShardId>(),
true);
- audit::logEnableSharding(Client::getCurrent(), dbname);
+ audit::logEnableSharding(opCtx->getClient(), dbname);
return true;
}
diff --git a/src/mongo/db/s/config/configsvr_refine_collection_shard_key_command.cpp b/src/mongo/db/s/config/configsvr_refine_collection_shard_key_command.cpp
index d8f90700952..45ca003894b 100644
--- a/src/mongo/db/s/config/configsvr_refine_collection_shard_key_command.cpp
+++ b/src/mongo/db/s/config/configsvr_refine_collection_shard_key_command.cpp
@@ -93,6 +93,8 @@ public:
void _internalRun(OperationContext* opCtx) {
const NamespaceString& nss = ns();
+ audit::logRefineCollectionShardKey(opCtx->getClient(), nss.ns(), request().getKey());
+
// Set the operation context read concern level to local for reads into the config
// database.
repl::ReadConcernArgs::get(opCtx) =
@@ -162,9 +164,6 @@ public:
"CMD: refineCollectionShardKey",
"request"_attr = request().toBSON({}));
- audit::logRefineCollectionShardKey(
- opCtx->getClient(), nss.ns(), newShardKeyPattern.toBSON());
-
ShardingCatalogManager::get(opCtx)->refineCollectionShardKey(
opCtx, nss, newShardKeyPattern);
}
diff --git a/src/mongo/db/s/config/configsvr_shard_collection_command.cpp b/src/mongo/db/s/config/configsvr_shard_collection_command.cpp
index 9f82a0a19b2..807944f807d 100644
--- a/src/mongo/db/s/config/configsvr_shard_collection_command.cpp
+++ b/src/mongo/db/s/config/configsvr_shard_collection_command.cpp
@@ -240,6 +240,9 @@ public:
auto request = ConfigsvrShardCollectionRequest::parse(
IDLParserErrorContext("ConfigsvrShardCollectionRequest"), cmdObj);
+ audit::logShardCollection(
+ opCtx->getClient(), nss.ns(), request.getKey(), request.getUnique());
+
auto const catalogManager = ShardingCatalogManager::get(opCtx);
auto const catalogCache = Grid::get(opCtx)->catalogCache();
auto const catalogClient = Grid::get(opCtx)->catalogClient();
diff --git a/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp
index ac355e4b4f6..f1c51ef9cf1 100644
--- a/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp
+++ b/src/mongo/db/s/config/sharding_catalog_manager_shard_operations.cpp
@@ -802,6 +802,7 @@ BSONObj makeCommitRemoveShardCommand(const std::string& removedShardName,
RemoveShardProgress ShardingCatalogManager::removeShard(OperationContext* opCtx,
const ShardId& shardId) {
const auto name = shardId.toString();
+ audit::logRemoveShard(opCtx->getClient(), name);
const auto configShard = Grid::get(opCtx)->shardRegistry()->getConfigShard();
@@ -907,7 +908,6 @@ RemoveShardProgress ShardingCatalogManager::removeShard(OperationContext* opCtx,
// Draining is done, now finish removing the shard.
LOGV2(
21949, "Going to remove shard: {shardId}", "Going to remove shard", "shardId"_attr = name);
- audit::logRemoveShard(opCtx->getClient(), name);
// Find a controlShard to be updated.
auto controlShardQueryStatus =
diff --git a/src/mongo/db/s/shardsvr_create_collection_command.cpp b/src/mongo/db/s/shardsvr_create_collection_command.cpp
index 1f9b762522f..8ee7a4c88e7 100644
--- a/src/mongo/db/s/shardsvr_create_collection_command.cpp
+++ b/src/mongo/db/s/shardsvr_create_collection_command.cpp
@@ -32,6 +32,7 @@
#include "mongo/platform/basic.h"
#include "mongo/bson/util/bson_extract.h"
+#include "mongo/db/audit.h"
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/commands.h"
#include "mongo/db/dbdirectclient.h"
@@ -169,6 +170,9 @@ CreateCollectionResponse createCollection(OperationContext* opCtx,
uassert(
ErrorCodes::NotImplemented, "create collection not implemented yet", request.getShardKey());
+ audit::logShardCollection(
+ opCtx->getClient(), nss.ns(), *request.getShardKey(), request.getUnique().value_or(false));
+
auto coordinatorDoc = CreateCollectionCoordinatorDocument();
coordinatorDoc.setShardingDDLCoordinatorMetadata(
{{nss, DDLCoordinatorTypeEnum::kCreateCollection}});