Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions jstests/audit/audit_getoptions_command.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// test that auditGetOptions command works as expected

if (TestData.testData !== undefined) {
load(TestData.testData + '/audit/_audit_helpers.js');
} else {
load('jstests/audit/_audit_helpers.js');
}

const testDBName = "audit_getoptions_command";

auditTest(
'auditGetOptions',
function(m) {
let adminDB = m.getDB('admin');
let testDB = m.getDB(testDBName);
createAdminUserForAudit(m);
createNoPermissionUserForAudit(m, adminDB);

// Admin user logs in
adminDB.auth('admin','admin');
// Should fail if not executed on 'admin' database
assert.commandFailedWithCode(testDB.runCommand({ 'auditGetOptions': 1 }), ErrorCodes.Unauthorized);
assert.commandWorked(adminDB.runCommand({ 'auditGetOptions': 1 }));
adminDB.logout();

// User (tom) with no permissions logs in.
assert(adminDB.auth('tom', 'tom'));
// Should fail if current user has no 'getParameter' privilege
assert.commandFailedWithCode(testDB.runCommand({ 'auditGetOptions': 1 }), ErrorCodes.Unauthorized);
assert.commandFailedWithCode(adminDB.runCommand({ 'auditGetOptions': 1 }), ErrorCodes.Unauthorized);
adminDB.logout();
},
{ auth:"" }
);
14 changes: 12 additions & 2 deletions src/mongo/db/audit/audit_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,19 @@ class AuditGetOptionsCommand : public AuditCommand {
"Example: { auditGetOptions: 1 }";
}

Status checkAuthForOperation(OperationContext*,
const DatabaseName&,
bool adminOnly() const override {
return true;
}

Status checkAuthForOperation(OperationContext* opCtx,
const DatabaseName& dbName,
const BSONObj&) const override {
auto* as = AuthorizationSession::get(opCtx->getClient());
if (!as->isAuthorizedForActionsOnResource(
ResourcePattern::forClusterResource(dbName.tenantId()), ActionType::getParameter)) {
return {ErrorCodes::Unauthorized, "unauthorized"};
}

return Status::OK();
}

Expand Down
Loading