mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
server: Global setting to allow/disallow users to force stop a vm (#9569)
Global setting to allow/disallow users to force stop a vm Fixes #6629 Co-authored-by: Suresh Kumar Anaparti <sureshkumar.anaparti@gmail.com> Co-authored-by: Rohit Yadav <rohityadav89@gmail.com> Co-authored-by: Bernardo De Marco Gonçalves <bernardomg2004@gmail.com>
This commit is contained in:
parent
36d37f70a8
commit
b7a2b0419c
@ -30,6 +30,7 @@ public class ApiConstants {
|
|||||||
public static final String ALGORITHM = "algorithm";
|
public static final String ALGORITHM = "algorithm";
|
||||||
public static final String ALIAS = "alias";
|
public static final String ALIAS = "alias";
|
||||||
public static final String ALLOCATED_ONLY = "allocatedonly";
|
public static final String ALLOCATED_ONLY = "allocatedonly";
|
||||||
|
public static final String ALLOW_USER_FORCE_STOP_VM = "allowuserforcestopvm";
|
||||||
public static final String ANNOTATION = "annotation";
|
public static final String ANNOTATION = "annotation";
|
||||||
public static final String API_KEY = "apikey";
|
public static final String API_KEY = "apikey";
|
||||||
public static final String ARCHIVED = "archived";
|
public static final String ARCHIVED = "archived";
|
||||||
|
|||||||
@ -55,6 +55,7 @@ public class ListCapabilitiesCmd extends BaseCmd {
|
|||||||
response.setAllowUserExpungeRecoverVM((Boolean)capabilities.get("allowUserExpungeRecoverVM"));
|
response.setAllowUserExpungeRecoverVM((Boolean)capabilities.get("allowUserExpungeRecoverVM"));
|
||||||
response.setAllowUserExpungeRecoverVolume((Boolean)capabilities.get("allowUserExpungeRecoverVolume"));
|
response.setAllowUserExpungeRecoverVolume((Boolean)capabilities.get("allowUserExpungeRecoverVolume"));
|
||||||
response.setAllowUserViewAllDomainAccounts((Boolean)capabilities.get("allowUserViewAllDomainAccounts"));
|
response.setAllowUserViewAllDomainAccounts((Boolean)capabilities.get("allowUserViewAllDomainAccounts"));
|
||||||
|
response.setAllowUserForceStopVM((Boolean)capabilities.get(ApiConstants.ALLOW_USER_FORCE_STOP_VM));
|
||||||
response.setKubernetesServiceEnabled((Boolean)capabilities.get("kubernetesServiceEnabled"));
|
response.setKubernetesServiceEnabled((Boolean)capabilities.get("kubernetesServiceEnabled"));
|
||||||
response.setKubernetesClusterExperimentalFeaturesEnabled((Boolean)capabilities.get("kubernetesClusterExperimentalFeaturesEnabled"));
|
response.setKubernetesClusterExperimentalFeaturesEnabled((Boolean)capabilities.get("kubernetesClusterExperimentalFeaturesEnabled"));
|
||||||
response.setCustomHypervisorDisplayName((String) capabilities.get("customHypervisorDisplayName"));
|
response.setCustomHypervisorDisplayName((String) capabilities.get("customHypervisorDisplayName"));
|
||||||
|
|||||||
@ -92,6 +92,10 @@ public class CapabilitiesResponse extends BaseResponse {
|
|||||||
@Param(description = "true if users can see all accounts within the same domain, false otherwise")
|
@Param(description = "true if users can see all accounts within the same domain, false otherwise")
|
||||||
private boolean allowUserViewAllDomainAccounts;
|
private boolean allowUserViewAllDomainAccounts;
|
||||||
|
|
||||||
|
@SerializedName(ApiConstants.ALLOW_USER_FORCE_STOP_VM)
|
||||||
|
@Param(description = "true if users are allowed to force stop a vm, false otherwise", since = "4.20.0")
|
||||||
|
private boolean allowUserForceStopVM;
|
||||||
|
|
||||||
@SerializedName("kubernetesserviceenabled")
|
@SerializedName("kubernetesserviceenabled")
|
||||||
@Param(description = "true if Kubernetes Service plugin is enabled, false otherwise")
|
@Param(description = "true if Kubernetes Service plugin is enabled, false otherwise")
|
||||||
private boolean kubernetesServiceEnabled;
|
private boolean kubernetesServiceEnabled;
|
||||||
@ -192,6 +196,10 @@ public class CapabilitiesResponse extends BaseResponse {
|
|||||||
this.allowUserViewAllDomainAccounts = allowUserViewAllDomainAccounts;
|
this.allowUserViewAllDomainAccounts = allowUserViewAllDomainAccounts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAllowUserForceStopVM(boolean allowUserForceStopVM) {
|
||||||
|
this.allowUserForceStopVM = allowUserForceStopVM;
|
||||||
|
}
|
||||||
|
|
||||||
public void setKubernetesServiceEnabled(boolean kubernetesServiceEnabled) {
|
public void setKubernetesServiceEnabled(boolean kubernetesServiceEnabled) {
|
||||||
this.kubernetesServiceEnabled = kubernetesServiceEnabled;
|
this.kubernetesServiceEnabled = kubernetesServiceEnabled;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4461,6 +4461,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
|
|||||||
final boolean allowUserViewDestroyedVM = (QueryService.AllowUserViewDestroyedVM.valueIn(caller.getId()) | _accountService.isAdmin(caller.getId()));
|
final boolean allowUserViewDestroyedVM = (QueryService.AllowUserViewDestroyedVM.valueIn(caller.getId()) | _accountService.isAdmin(caller.getId()));
|
||||||
final boolean allowUserExpungeRecoverVM = (UserVmManager.AllowUserExpungeRecoverVm.valueIn(caller.getId()) | _accountService.isAdmin(caller.getId()));
|
final boolean allowUserExpungeRecoverVM = (UserVmManager.AllowUserExpungeRecoverVm.valueIn(caller.getId()) | _accountService.isAdmin(caller.getId()));
|
||||||
final boolean allowUserExpungeRecoverVolume = (VolumeApiServiceImpl.AllowUserExpungeRecoverVolume.valueIn(caller.getId()) | _accountService.isAdmin(caller.getId()));
|
final boolean allowUserExpungeRecoverVolume = (VolumeApiServiceImpl.AllowUserExpungeRecoverVolume.valueIn(caller.getId()) | _accountService.isAdmin(caller.getId()));
|
||||||
|
final boolean allowUserForceStopVM = (UserVmManager.AllowUserForceStopVm.valueIn(caller.getId()) | _accountService.isAdmin(caller.getId()));
|
||||||
|
|
||||||
final boolean allowUserViewAllDomainAccounts = (QueryService.AllowUserViewAllDomainAccounts.valueIn(caller.getDomainId()));
|
final boolean allowUserViewAllDomainAccounts = (QueryService.AllowUserViewAllDomainAccounts.valueIn(caller.getDomainId()));
|
||||||
|
|
||||||
@ -4488,6 +4489,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
|
|||||||
capabilities.put("allowUserExpungeRecoverVM", allowUserExpungeRecoverVM);
|
capabilities.put("allowUserExpungeRecoverVM", allowUserExpungeRecoverVM);
|
||||||
capabilities.put("allowUserExpungeRecoverVolume", allowUserExpungeRecoverVolume);
|
capabilities.put("allowUserExpungeRecoverVolume", allowUserExpungeRecoverVolume);
|
||||||
capabilities.put("allowUserViewAllDomainAccounts", allowUserViewAllDomainAccounts);
|
capabilities.put("allowUserViewAllDomainAccounts", allowUserViewAllDomainAccounts);
|
||||||
|
capabilities.put(ApiConstants.ALLOW_USER_FORCE_STOP_VM, allowUserForceStopVM);
|
||||||
capabilities.put("kubernetesServiceEnabled", kubernetesServiceEnabled);
|
capabilities.put("kubernetesServiceEnabled", kubernetesServiceEnabled);
|
||||||
capabilities.put("kubernetesClusterExperimentalFeaturesEnabled", kubernetesClusterExperimentalFeaturesEnabled);
|
capabilities.put("kubernetesClusterExperimentalFeaturesEnabled", kubernetesClusterExperimentalFeaturesEnabled);
|
||||||
capabilities.put("customHypervisorDisplayName", HypervisorGuru.HypervisorCustomDisplayName.value());
|
capabilities.put("customHypervisorDisplayName", HypervisorGuru.HypervisorCustomDisplayName.value());
|
||||||
|
|||||||
@ -51,12 +51,15 @@ public interface UserVmManager extends UserVmService {
|
|||||||
String EnableDynamicallyScaleVmCK = "enable.dynamic.scale.vm";
|
String EnableDynamicallyScaleVmCK = "enable.dynamic.scale.vm";
|
||||||
String AllowDiskOfferingChangeDuringScaleVmCK = "allow.diskoffering.change.during.scale.vm";
|
String AllowDiskOfferingChangeDuringScaleVmCK = "allow.diskoffering.change.during.scale.vm";
|
||||||
String AllowUserExpungeRecoverVmCK ="allow.user.expunge.recover.vm";
|
String AllowUserExpungeRecoverVmCK ="allow.user.expunge.recover.vm";
|
||||||
|
String AllowUserForceStopVmCK = "allow.user.force.stop.vm";
|
||||||
ConfigKey<Boolean> EnableDynamicallyScaleVm = new ConfigKey<Boolean>("Advanced", Boolean.class, EnableDynamicallyScaleVmCK, "false",
|
ConfigKey<Boolean> EnableDynamicallyScaleVm = new ConfigKey<Boolean>("Advanced", Boolean.class, EnableDynamicallyScaleVmCK, "false",
|
||||||
"Enables/Disables dynamically scaling a vm", true, ConfigKey.Scope.Zone);
|
"Enables/Disables dynamically scaling a vm", true, ConfigKey.Scope.Zone);
|
||||||
ConfigKey<Boolean> AllowDiskOfferingChangeDuringScaleVm = new ConfigKey<Boolean>("Advanced", Boolean.class, AllowDiskOfferingChangeDuringScaleVmCK, "false",
|
ConfigKey<Boolean> AllowDiskOfferingChangeDuringScaleVm = new ConfigKey<Boolean>("Advanced", Boolean.class, AllowDiskOfferingChangeDuringScaleVmCK, "false",
|
||||||
"Determines whether to allow or disallow disk offering change for root volume during scaling of a stopped or running vm", true, ConfigKey.Scope.Zone);
|
"Determines whether to allow or disallow disk offering change for root volume during scaling of a stopped or running vm", true, ConfigKey.Scope.Zone);
|
||||||
ConfigKey<Boolean> AllowUserExpungeRecoverVm = new ConfigKey<Boolean>("Advanced", Boolean.class, AllowUserExpungeRecoverVmCK, "false",
|
ConfigKey<Boolean> AllowUserExpungeRecoverVm = new ConfigKey<Boolean>("Advanced", Boolean.class, AllowUserExpungeRecoverVmCK, "false",
|
||||||
"Determines whether users can expunge or recover their vm", true, ConfigKey.Scope.Account);
|
"Determines whether users can expunge or recover their vm", true, ConfigKey.Scope.Account);
|
||||||
|
ConfigKey<Boolean> AllowUserForceStopVm = new ConfigKey<Boolean>("Advanced", Boolean.class, AllowUserForceStopVmCK, "true",
|
||||||
|
"Determines whether users are allowed to force stop a vm", true, ConfigKey.Scope.Account);
|
||||||
ConfigKey<Boolean> DisplayVMOVFProperties = new ConfigKey<Boolean>("Advanced", Boolean.class, "vm.display.ovf.properties", "false",
|
ConfigKey<Boolean> DisplayVMOVFProperties = new ConfigKey<Boolean>("Advanced", Boolean.class, "vm.display.ovf.properties", "false",
|
||||||
"Set display of VMs OVF properties as part of VM details", true);
|
"Set display of VMs OVF properties as part of VM details", true);
|
||||||
|
|
||||||
|
|||||||
@ -5348,6 +5348,13 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||||||
public void finalizeExpunge(VirtualMachine vm) {
|
public void finalizeExpunge(VirtualMachine vm) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkForceStopVmPermission(Account callingAccount) {
|
||||||
|
if (!AllowUserForceStopVm.valueIn(callingAccount.getId())) {
|
||||||
|
logger.error("Parameter [{}] can only be passed by Admin accounts or when the allow.user.force.stop.vm config is true for the account.", ApiConstants.FORCED);
|
||||||
|
throw new PermissionDeniedException("Account does not have the permission to force stop the vm.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ActionEvent(eventType = EventTypes.EVENT_VM_STOP, eventDescription = "stopping Vm", async = true)
|
@ActionEvent(eventType = EventTypes.EVENT_VM_STOP, eventDescription = "stopping Vm", async = true)
|
||||||
public UserVm stopVirtualMachine(long vmId, boolean forced) throws ConcurrentOperationException {
|
public UserVm stopVirtualMachine(long vmId, boolean forced) throws ConcurrentOperationException {
|
||||||
@ -5365,6 +5372,10 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||||||
throw new InvalidParameterValueException("unable to find a virtual machine with id " + vmId);
|
throw new InvalidParameterValueException("unable to find a virtual machine with id " + vmId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (forced) {
|
||||||
|
checkForceStopVmPermission(caller);
|
||||||
|
}
|
||||||
|
|
||||||
// check if vm belongs to AutoScale vm group in Disabled state
|
// check if vm belongs to AutoScale vm group in Disabled state
|
||||||
autoScaleManager.checkIfVmActionAllowed(vmId);
|
autoScaleManager.checkIfVmActionAllowed(vmId);
|
||||||
|
|
||||||
@ -8467,7 +8478,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||||||
return new ConfigKey<?>[] {EnableDynamicallyScaleVm, AllowDiskOfferingChangeDuringScaleVm, AllowUserExpungeRecoverVm, VmIpFetchWaitInterval, VmIpFetchTrialMax,
|
return new ConfigKey<?>[] {EnableDynamicallyScaleVm, AllowDiskOfferingChangeDuringScaleVm, AllowUserExpungeRecoverVm, VmIpFetchWaitInterval, VmIpFetchTrialMax,
|
||||||
VmIpFetchThreadPoolMax, VmIpFetchTaskWorkers, AllowDeployVmIfGivenHostFails, EnableAdditionalVmConfig, DisplayVMOVFProperties,
|
VmIpFetchThreadPoolMax, VmIpFetchTaskWorkers, AllowDeployVmIfGivenHostFails, EnableAdditionalVmConfig, DisplayVMOVFProperties,
|
||||||
KvmAdditionalConfigAllowList, XenServerAdditionalConfigAllowList, VmwareAdditionalConfigAllowList, DestroyRootVolumeOnVmDestruction,
|
KvmAdditionalConfigAllowList, XenServerAdditionalConfigAllowList, VmwareAdditionalConfigAllowList, DestroyRootVolumeOnVmDestruction,
|
||||||
EnforceStrictResourceLimitHostTagCheck, StrictHostTags};
|
EnforceStrictResourceLimitHostTagCheck, StrictHostTags, AllowUserForceStopVm};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -133,7 +133,10 @@ export default {
|
|||||||
dataView: true,
|
dataView: true,
|
||||||
groupAction: true,
|
groupAction: true,
|
||||||
groupMap: (selection, values) => { return selection.map(x => { return { id: x, forced: values.forced } }) },
|
groupMap: (selection, values) => { return selection.map(x => { return { id: x, forced: values.forced } }) },
|
||||||
args: ['forced'],
|
args: (record, store, group) => {
|
||||||
|
return (['Admin'].includes(store.userInfo.roletype) || store.features.allowuserforcestopvm)
|
||||||
|
? ['forced'] : []
|
||||||
|
},
|
||||||
show: (record) => { return ['Running'].includes(record.state) }
|
show: (record) => { return ['Running'].includes(record.state) }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user