Skip to content

Commit bec9ccb

Browse files
Merge pull request #6520 from nimrod-becker/some_fixes
Only allow admins and operator to create new accounts
2 parents 533db2a + eabf210 commit bec9ccb

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/server/system_services/account_server.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ async function create_account(req) {
5959

6060
const { roles: account_roles = ['admin'] } = req.rpc_params;
6161

62+
validate_create_account_permissions(req);
6263
validate_create_account_params(req);
6364

6465
if (account.name.unwrap() === 'demo' && account.email.unwrap() === '[email protected]') {
@@ -1341,6 +1342,21 @@ function is_support_or_admin_or_me(system, account, target_account) {
13411342
);
13421343
}
13431344

1345+
function validate_create_account_permissions(req) {
1346+
const account = req.account;
1347+
//For new system creation, nothing to be checked
1348+
if (req.rpc_params.new_system_parameters) return;
1349+
1350+
//Only allow support, admin/operator roles and UI login enabled accounts to create new accounts
1351+
if (!account.is_support &&
1352+
!account.has_login &&
1353+
!(account.roles_by_system[req.system._id].some(
1354+
role => role === 'admin' || role === 'operator'
1355+
))) {
1356+
throw new RpcError('UNAUTHORIZED', 'Cannot create new account');
1357+
}
1358+
}
1359+
13441360
function validate_create_account_params(req) {
13451361
// find none-internal pools
13461362
const has_non_internal_resources = (req.system && req.system.pools_by_name) ?

0 commit comments

Comments
 (0)