Skip to content

Commit 7fe3290

Browse files
committed
Fixed security issue in api - regular user can operate only with his own resources (except for the template - when the template is public, it's available for everyone)
1 parent c0d84f3 commit 7fe3290

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

‎api/src/com/cloud/acl/SecurityChecker.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ public interface SecurityChecker extends Adapter {
5858
/**
5959
* Checks if the account can access the object.
6060
*
61-
* @param account account to check against.
61+
* @param caller account to check against.
6262
* @param entity object that the account is trying to access.
6363
* @return true if access allowed. false if this adapter cannot provide permission.
6464
* @throws PermissionDeniedException if this adapter is suppose to authenticate ownership and the check failed.
6565
*/
66-
boolean checkAccess(Account account, ControlledEntity entity) throws PermissionDeniedException;
66+
boolean checkAccess(Account caller, ControlledEntity entity) throws PermissionDeniedException;
6767

6868
/**
6969
* Checks if the user belongs to an account that can access the object.

‎server/src/com/cloud/acl/DomainChecker.java‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,30 +74,36 @@ public boolean checkAccess(User user, Domain domain) throws PermissionDeniedExce
7474
}
7575

7676
@Override
77-
public boolean checkAccess(Account account, ControlledEntity entity) throws PermissionDeniedException {
77+
public boolean checkAccess(Account caller, ControlledEntity entity) throws PermissionDeniedException {
7878
if (entity instanceof VirtualMachineTemplate) {
7979

8080
VirtualMachineTemplate template = (VirtualMachineTemplate)entity;
8181

8282
// validate that the template is usable by the account
8383
if (!template.isPublicTemplate()) {
8484
Account owner = _accountDao.findById(template.getAccountId());
85-
if (BaseCmd.isAdmin(owner.getType()) || (owner.getId() == account.getId())) {
85+
if (BaseCmd.isAdmin(owner.getType()) || (owner.getId() == caller.getId())) {
8686
return true;
8787
}
8888

8989
// since the current account is not the owner of the template, check the launch permissions table to see if the
9090
// account can launch a VM from this template
91-
LaunchPermissionVO permission = _launchPermissionDao.findByTemplateAndAccount(template.getId(), account.getId());
91+
LaunchPermissionVO permission = _launchPermissionDao.findByTemplateAndAccount(template.getId(), caller.getId());
9292
if (permission == null) {
93-
throw new PermissionDeniedException(account + " does not have permission to launch instances from " + template);
93+
throw new PermissionDeniedException(caller + " does not have permission to launch instances from " + template);
9494
}
9595
}
9696

9797
return true;
9898
} else {
99-
return true;
99+
if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL) {
100+
if (caller.getId() != entity.getAccountId()) {
101+
throw new PermissionDeniedException(caller + " does not have permission to operate with resource " + entity);
102+
}
103+
}
100104
}
105+
106+
return true;
101107
}
102108

103109
@Override

0 commit comments

Comments
 (0)