Skip to content

Commit d7c5382

Browse files
committed
CLOUDSTACK-6535: IAM:MS:API createVMSnapshot doesn't preserve access
rights.
1 parent 95e9db2 commit d7c5382

4 files changed

Lines changed: 23 additions & 4 deletions

File tree

api/src/org/apache/cloudstack/api/command/admin/vm/AddNicToVMCmdByAdmin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
import org.apache.cloudstack.context.CallContext;
3232

3333
import com.cloud.uservm.UserVm;
34+
import com.cloud.vm.VirtualMachine;
3435

35-
@APICommand(name = "addNicToVirtualMachine", description = "Adds VM to specified network by creating a NIC", responseObject = UserVmResponse.class, responseView = ResponseView.Full,
36+
@APICommand(name = "addNicToVirtualMachine", description = "Adds VM to specified network by creating a NIC", responseObject = UserVmResponse.class, responseView = ResponseView.Full, entityType = {VirtualMachine.class},
3637
requestHasSensitiveInfo = false, responseHasSensitiveInfo = true)
3738
public class AddNicToVMCmdByAdmin extends AddNicToVMCmd {
3839
public static final Logger s_logger = Logger.getLogger(AddNicToVMCmdByAdmin.class);

api/src/org/apache/cloudstack/api/command/admin/volume/CreateVolumeCmdByAdmin.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@
2828

2929
import com.cloud.storage.Snapshot;
3030
import com.cloud.storage.Volume;
31+
import com.cloud.vm.VirtualMachine;
3132

32-
@APICommand(name = "createVolume", responseObject = VolumeResponse.class, description = "Creates a disk volume from a disk offering. This disk volume must still be attached to a virtual machine to make use of it.", responseView = ResponseView.Full)
33+
@APICommand(name = "createVolume", responseObject = VolumeResponse.class, description = "Creates a disk volume from a disk offering. This disk volume must still be attached to a virtual machine to make use of it.", responseView = ResponseView.Full, entityType = {
34+
Volume.class, VirtualMachine.class},
35+
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
3336
public class CreateVolumeCmdByAdmin extends CreateVolumeCmd {
3437
public static final Logger s_logger = Logger.getLogger(CreateVolumeCmdByAdmin.class.getName());
3538

api/src/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.apache.log4j.Logger;
2020

2121
import org.apache.cloudstack.acl.RoleType;
22+
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
2223
import org.apache.cloudstack.api.ACL;
2324
import org.apache.cloudstack.api.APICommand;
2425
import org.apache.cloudstack.api.ApiCommandJobType;
@@ -42,8 +43,10 @@
4243
import com.cloud.exception.ResourceAllocationException;
4344
import com.cloud.storage.Snapshot;
4445
import com.cloud.storage.Volume;
46+
import com.cloud.vm.VirtualMachine;
4547

46-
@APICommand(name = "createVolume", responseObject = VolumeResponse.class, description = "Creates a disk volume from a disk offering. This disk volume must still be attached to a virtual machine to make use of it.", responseView = ResponseView.Restricted, entityType = {Volume.class},
48+
@APICommand(name = "createVolume", responseObject = VolumeResponse.class, description = "Creates a disk volume from a disk offering. This disk volume must still be attached to a virtual machine to make use of it.", responseView = ResponseView.Restricted, entityType = {
49+
Volume.class, VirtualMachine.class},
4750
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
4851
public class CreateVolumeCmd extends BaseAsyncCreateCustomIdCmd {
4952
public static final Logger s_logger = Logger.getLogger(CreateVolumeCmd.class.getName());
@@ -103,7 +106,7 @@ public class CreateVolumeCmd extends BaseAsyncCreateCustomIdCmd {
103106
@Parameter(name = ApiConstants.DISPLAY_VOLUME, type = CommandType.BOOLEAN, description = "an optional field, whether to display the volume to the end user or not.", authorized = {RoleType.Admin})
104107
private Boolean displayVolume;
105108

106-
@ACL
109+
@ACL(accessType = AccessType.OperateEntry)
107110
@Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID,
108111
type = CommandType.UUID,
109112
entityType = UserVmResponse.class,

server/src/com/cloud/api/dispatch/ParamProcessWorker.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.apache.cloudstack.api.ACL;
4343
import org.apache.cloudstack.api.APICommand;
4444
import org.apache.cloudstack.api.ApiErrorCode;
45+
import org.apache.cloudstack.api.BaseAsyncCreateCmd;
4546
import org.apache.cloudstack.api.BaseCmd;
4647
import org.apache.cloudstack.api.BaseCmd.CommandType;
4748
import org.apache.cloudstack.api.EntityReference;
@@ -227,6 +228,17 @@ private void doAccessChecks(final BaseCmd cmd, final Map<Object, AccessType> ent
227228
owner = caller;
228229
}
229230

231+
if (cmd instanceof BaseAsyncCreateCmd) {
232+
if (owner.getId() != caller.getId()) {
233+
// mimic impersonation either by passing (account, domainId) or through derived owner from other api parameters
234+
// in this case, we should check access using the owner
235+
_accountMgr.checkAccess(caller, null, owner);
236+
}
237+
} else {
238+
// check access using the caller for other operational cmds
239+
owner = caller;
240+
}
241+
230242
APICommand commandAnnotation = cmd.getClass().getAnnotation(APICommand.class);
231243

232244
String apiName = commandAnnotation != null ? commandAnnotation.name() : null;

0 commit comments

Comments
 (0)