Skip to content

Commit 2358632

Browse files
Fixed User type accounts being able to change resource limits of their own domain and account (#12046)
Co-authored-by: Lucas Martins <[email protected]>
1 parent 2811217 commit 2358632

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

server/src/main/java/com/cloud/resourcelimit/ResourceLimitManagerImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,11 @@ protected void addTaggedResourceLimits(List<ResourceLimitVO> limits, ResourceTyp
903903
public ResourceLimitVO updateResourceLimit(Long accountId, Long domainId, Integer typeId, Long max, String tag) {
904904
Account caller = CallContext.current().getCallingAccount();
905905

906+
if (caller.getType().equals(Account.Type.NORMAL)) {
907+
logger.info("Throwing exception because only root admins and domain admins are allowed to update resource limits.");
908+
throw new PermissionDeniedException("Your account does not have the permission to update resource limits.");
909+
}
910+
906911
if (max == null) {
907912
max = (long)Resource.RESOURCE_UNLIMITED;
908913
} else if (max < Resource.RESOURCE_UNLIMITED) {

server/src/test/java/com/cloud/resourcelimit/ResourceLimitManagerImplTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ public void setUp() throws Exception {
147147
overrideDefaultConfigValue(ResourceLimitService.ResourceLimitStorageTags, "_defaultValue", StringUtils.join(storageTags, ","));
148148

149149
Account account = mock(Account.class);
150+
when(account.getType()).thenReturn(Account.Type.ADMIN);
150151
User user = mock(User.class);
151152
CallContext.register(user, account);
152153
}

0 commit comments

Comments
 (0)