Skip to content

Commit e4831ff

Browse files
committed
server: fix network access for addNicToVirtualMachine API
New NICs shouldn't added to VM with network from admin account, same as deployment. Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 16d0795 commit e4831ff

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
import org.apache.cloudstack.api.command.user.vmgroup.CreateVMGroupCmd;
8282
import org.apache.cloudstack.api.command.user.vmgroup.DeleteVMGroupCmd;
8383
import org.apache.cloudstack.api.command.user.volume.ResizeVolumeCmd;
84-
import com.cloud.agent.api.to.deployasis.OVFNetworkTO;
8584
import org.apache.cloudstack.backup.Backup;
8685
import org.apache.cloudstack.backup.BackupManager;
8786
import org.apache.cloudstack.backup.dao.BackupDao;
@@ -145,6 +144,7 @@
145144
import com.cloud.agent.api.to.DiskTO;
146145
import com.cloud.agent.api.to.NicTO;
147146
import com.cloud.agent.api.to.VirtualMachineTO;
147+
import com.cloud.agent.api.to.deployasis.OVFNetworkTO;
148148
import com.cloud.agent.api.to.deployasis.OVFPropertyTO;
149149
import com.cloud.agent.manager.Commands;
150150
import com.cloud.alert.AlertManager;
@@ -1333,12 +1333,8 @@ public UserVm addNicToVirtualMachine(AddNicToVMCmd cmd) throws InvalidParameterV
13331333
throw new InvalidParameterValueException("unable to find a network with id " + networkId);
13341334
}
13351335

1336-
if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
1337-
if (!(network.getGuestType() == Network.GuestType.Shared && network.getAclType() == ACLType.Domain)
1338-
&& !(network.getAclType() == ACLType.Account && network.getAccountId() == vmInstance.getAccountId())) {
1339-
throw new InvalidParameterValueException("only shared network or isolated network with the same account_id can be added to vmId: " + vmId);
1340-
}
1341-
}
1336+
Account vmOwner = _accountMgr.getAccount(vmInstance.getAccountId());
1337+
_networkModel.checkNetworkPermissions(vmOwner, network);
13421338

13431339
List<NicVO> allNics = _nicDao.listByVmId(vmInstance.getId());
13441340
for (NicVO nic : allNics) {

0 commit comments

Comments
 (0)