Skip to content

Commit 527a668

Browse files
bug 10868: CheckAccess - If the domainId = -1 and the accountId is still valid then try and calculate the domainId. This case will be hit for all the entities which do not have domain id column in the DB table. What was happenning due to this was that we were not checking the domain hierarchy in such case which was leading to security leaks. Example - templates.
1 parent e19c51e commit 527a668

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎server/src/com/cloud/user/AccountManagerImpl.java‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
import com.cloud.acl.ControlledEntity;
3939
import com.cloud.acl.SecurityChecker;
40+
import com.cloud.api.ApiDBUtils;
4041
import com.cloud.api.commands.CreateAccountCmd;
4142
import com.cloud.api.commands.CreateUserCmd;
4243
import com.cloud.api.commands.DeleteAccountCmd;
@@ -909,11 +910,16 @@ public void checkAccess(Account caller, ControlledEntity... entities) {
909910
HashMap<Long, List<ControlledEntity>> domains = new HashMap<Long, List<ControlledEntity>>();
910911

911912
for (ControlledEntity entity : entities) {
912-
if (entity.getAccountId() != -1 && entity.getDomainId() != -1) {
913+
long domainId = entity.getDomainId();
914+
if (entity.getAccountId() != -1 && domainId == -1){ // If account exists domainId should too so calculate it. This condition might be hit for templates or entities which miss domainId in their tables
915+
Account account = ApiDBUtils.findAccountById(entity.getAccountId());
916+
domainId = account != null ? account.getDomainId() : -1 ;
917+
}
918+
if (entity.getAccountId() != -1 && domainId != -1) {
913919
List<ControlledEntity> toBeChecked = domains.get(entity.getDomainId());
914920
if (toBeChecked == null) {
915921
toBeChecked = new ArrayList<ControlledEntity>();
916-
domains.put(entity.getDomainId(), toBeChecked);
922+
domains.put(domainId, toBeChecked);
917923
}
918924
toBeChecked.add(entity);
919925
}

0 commit comments

Comments
 (0)