summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDianna Hohensee <dianna.hohensee@mongodb.com>2023-06-28 19:53:24 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-06-29 01:56:33 +0000
commit2ffc5b8e89ed4a7af49bbd1ed9aec502c8f0eae0 (patch)
tree864b775751051f95b5b5e5e8cac923a48e98ed84
parent337201cd420c9dc1e6241c9087b808c7f39e3b43 (diff)
Revert "SERVER-77003 Allow renames of time-series collection buckets"
This reverts commit 721098ff45959f6e283636f4f5a8d2341e177f47.
-rw-r--r--jstests/auth/rename_system_buckets_collection.js120
-rw-r--r--jstests/core/timeseries/timeseries_bucket_rename.js28
-rw-r--r--src/mongo/db/catalog/rename_collection.cpp10
-rw-r--r--src/mongo/s/commands/cluster_rename_collection_cmd.cpp8
4 files changed, 31 insertions, 135 deletions
diff --git a/jstests/auth/rename_system_buckets_collection.js b/jstests/auth/rename_system_buckets_collection.js
deleted file mode 100644
index 7b9e678ae84..00000000000
--- a/jstests/auth/rename_system_buckets_collection.js
+++ /dev/null
@@ -1,120 +0,0 @@
-// Tests renaming the system.buckets collection.
-(function() {
-"use strict";
-
-// Set up the test database.
-const dbName = "test";
-const collName = "mongosync.tmp.UUID123";
-const bucketsCollName = `system.buckets.${collName}`;
-const targetBucketsCollName = "system.buckets.manual";
-
-function renameBucketsCollection(adminDB, username, shouldSucceed) {
- // Create collection under admin user
- assert.eq(1, adminDB.auth("admin", "admin"));
-
- const testDB = adminDB.getSiblingDB(dbName);
-
- testDB[bucketsCollName].drop();
- testDB[targetBucketsCollName].drop();
-
- assert.commandWorked(
- testDB.createCollection(bucketsCollName, {timeseries: {timeField: "time"}}));
- adminDB.logout();
-
- // Try rename with test users
- jsTestLog("Testing system.buckets renaming with username: " + username);
- assert(adminDB.auth(username, 'password'));
-
- const res = testDB.adminCommand({
- renameCollection: `${testDB}.${bucketsCollName}`,
- to: `${testDB}.${targetBucketsCollName}`,
- dropTarget: true
- });
-
- assert.eq((shouldSucceed) ? 1 : 0,
- res.ok,
- "Rename collection failed or succeeded unexpectedly:" + tojson(res));
-
- adminDB.logout();
-}
-
-function runTest(conn) {
- const adminDB = conn.getDB("admin");
-
- // Create the admin user.
- adminDB.createUser({user: 'admin', pwd: 'admin', roles: ['root']});
- assert.eq(1, adminDB.auth("admin", "admin"));
-
- // Create roles with ability to rename system.buckets collections
- adminDB.createRole({
- role: "renameBucketsOnly",
- privileges: [{
- resource: {db: '', system_buckets: ''},
- actions: [
- "createIndex",
- "dropCollection",
- "find",
- "insert",
- ]
- }],
- roles: []
- });
-
- // Create test users
- adminDB.createUser(
- {user: 'userAdmin', pwd: 'password', roles: ['userAdminAnyDatabase', 'renameBucketsOnly']});
-
- // Create read and write users.
- adminDB.createUser({
- user: 'readWriteAdmin',
- pwd: 'password',
- roles: ['readWriteAnyDatabase', 'renameBucketsOnly']
- });
-
- // Create strong users.
- adminDB.createUser({user: 'restore', pwd: 'password', roles: ['restore', 'renameBucketsOnly']});
- adminDB.createUser({user: 'root', pwd: 'password', roles: ['root', 'renameBucketsOnly']});
- adminDB.createUser(
- {user: 'rootier', pwd: 'password', roles: ['__system', 'renameBucketsOnly']});
- adminDB.createUser(
- {user: 'reader', pwd: 'password', roles: ['readAnyDatabase', 'renameBucketsOnly']});
-
- adminDB.logout();
-
- // Expect renaming system.buckets collection to succeed.
- renameBucketsCollection(adminDB, 'restore', true);
- renameBucketsCollection(adminDB, 'root', true);
- renameBucketsCollection(adminDB, 'rootier', true);
-
- // Second test case should fail for user with inadequate role.
- renameBucketsCollection(adminDB, 'reader', false);
- renameBucketsCollection(adminDB, 'readWriteAdmin', false);
- renameBucketsCollection(adminDB, 'userAdmin', false);
-}
-
-jsTestLog("ReplicaSet: Testing rename timeseries collection");
-{
- const rst = new ReplSetTest({nodes: 1, auth: "", keyFile: 'jstests/libs/key1'});
- rst.startSet();
-
- rst.initiate();
- rst.awaitReplication();
- runTest(rst.getPrimary());
- rst.stopSet();
-}
-
-jsTestLog("Sharding: Testing rename timeseries collection");
-{
- const st = new ShardingTest({
- shards: 1,
- mongos: 1,
- config: 1,
- keyFile: "jstests/libs/key1",
- other: {shardOptions: {auth: ""}}
- });
-
- runTest(st.s);
-
- st.stop();
-}
-})();
diff --git a/jstests/core/timeseries/timeseries_bucket_rename.js b/jstests/core/timeseries/timeseries_bucket_rename.js
new file mode 100644
index 00000000000..98a0b73b810
--- /dev/null
+++ b/jstests/core/timeseries/timeseries_bucket_rename.js
@@ -0,0 +1,28 @@
+/**
+ * Tests that a system.buckets collection cannot be renamed.
+ *
+ * @tags: [
+ * does_not_support_stepdowns,
+ * does_not_support_transactions,
+ * requires_getmore,
+ * ]
+ */
+(function() {
+'use strict';
+
+const coll = db.timeseries_bucket_rename;
+const bucketsColl = db.getCollection('system.buckets.' + coll.getName());
+
+const timeFieldName = 'time';
+
+coll.drop();
+assert.commandWorked(db.createCollection(coll.getName(), {timeseries: {timeField: timeFieldName}}));
+assert.contains(bucketsColl.getName(), db.getCollectionNames());
+
+assert.commandFailedWithCode(db.adminCommand({
+ renameCollection: bucketsColl.getFullName(),
+ to: db.getName() + ".otherColl",
+ dropTarget: false
+}),
+ ErrorCodes.IllegalOperation);
+})();
diff --git a/src/mongo/db/catalog/rename_collection.cpp b/src/mongo/db/catalog/rename_collection.cpp
index 1b50954307e..4a94bb41b27 100644
--- a/src/mongo/db/catalog/rename_collection.cpp
+++ b/src/mongo/db/catalog/rename_collection.cpp
@@ -863,13 +863,9 @@ void validateNamespacesForRenameCollection(OperationContext* opCtx,
"renaming system.views collection or renaming to system.views is not allowed",
!source.isSystemDotViews() && !target.isSystemDotViews());
- if (source.isTimeseriesBucketsCollection() &&
- !AuthorizationSession::get(opCtx->getClient())
- ->isAuthorizedForActionsOnResource(ResourcePattern::forClusterResource(),
- ActionType::setUserWriteBlockMode)) {
- uasserted(ErrorCodes::IllegalOperation,
- "Renaming system.buckets collections is not allowed");
- }
+ uassert(ErrorCodes::IllegalOperation,
+ "Renaming system.buckets collections is not allowed",
+ !source.isTimeseriesBucketsCollection());
}
void validateAndRunRenameCollection(OperationContext* opCtx,
diff --git a/src/mongo/s/commands/cluster_rename_collection_cmd.cpp b/src/mongo/s/commands/cluster_rename_collection_cmd.cpp
index a9698a64bc3..d03d2f23e58 100644
--- a/src/mongo/s/commands/cluster_rename_collection_cmd.cpp
+++ b/src/mongo/s/commands/cluster_rename_collection_cmd.cpp
@@ -75,14 +75,6 @@ public:
"Can't rename a collection to itself",
fromNss != toNss);
- if (fromNss.isTimeseriesBucketsCollection() &&
- !AuthorizationSession::get(opCtx->getClient())
- ->isAuthorizedForActionsOnResource(ResourcePattern::forClusterResource(),
- ActionType::setUserWriteBlockMode)) {
- uasserted(ErrorCodes::IllegalOperation,
- "Renaming a timeseries collection is not allowed");
- }
-
RenameCollectionRequest renameCollReq(request().getTo());
renameCollReq.setStayTemp(request().getStayTemp());
renameCollReq.setExpectedSourceUUID(request().getCollectionUUID());