Files
mongo/jstests/auth/timeseries_ddl.js
Meryama 25177ea67e SERVER-114496 : Forbid all operations targeting legacy timeseries buckets collections (#48591)
GitOrigin-RevId: 5f52cb0224915682f65e0892fd6e2a46b939c80d
2026-03-09 17:18:13 +00:00

68 lines
2.0 KiB
JavaScript

/**
* Verify that DDL operations on timeseries bucket namespaces requires special authorization
*
* @tags: [
* requires_fcv_61,
* ]
*/
import {ShardingTest} from "jstests/libs/shardingtest.js";
const dbName = jsTest.name() + "_db";
const normalCollName = "normalColl";
const timeseriesCollName = "timeseriesColl";
const bucketCollName = "system.buckets." + timeseriesCollName;
const pass = "password";
const st = new ShardingTest({keyFile: "jstests/libs/key1", other: {rsOptions: {auth: ""}}});
// Create the admin user.
st.admin.createUser({user: "root", pwd: pass, roles: ["userAdminAnyDatabase"]});
assert(st.admin.auth("root", pass));
const db = st.s.getDB(dbName);
db.createUser({user: "rw", pwd: pass, roles: ["readWrite"]});
db.createUser({
user: "c2c",
pwd: pass,
roles: [
{db: "admin", role: "restore"},
{db: "admin", role: "backup"},
],
});
st.admin.logout();
function createCollectionsAsRegularUser() {
assert(db.auth("rw", pass));
assert.commandWorked(db.createCollection(normalCollName));
assert.commandWorked(db.createCollection(timeseriesCollName, {timeseries: {timeField: "time"}}));
assert.commandFailedWithCode(db.createCollection(bucketCollName), ErrorCodes.Unauthorized);
db.logout();
}
{
createCollectionsAsRegularUser();
assert(db.auth("rw", pass));
assert.commandWorked(db.runCommand({drop: normalCollName}));
assert.commandFailedWithCode(db.runCommand({drop: bucketCollName}), ErrorCodes.Unauthorized);
assert.commandWorked(db.runCommand({drop: timeseriesCollName}));
db.logout();
}
{
createCollectionsAsRegularUser();
assert(db.auth("c2c", pass));
assert.commandWorked(db.runCommand({drop: normalCollName}));
// TODO SERVER-121176 should fail once 9.0 becomes last LTS
assert.commandWorkedOrFailedWithCode(
db.runCommand({drop: bucketCollName}),
ErrorCodes.CommandNotSupportedOnLegacyTimeseriesBucketsNamespace,
);
assert.commandWorked(db.runCommand({drop: timeseriesCollName}));
db.logout();
}
st.stop();