Skip to content

Commit 66d49c5

Browse files
author
Daan Hoogland
committed
Merge release branch 4.14 to 4.15
* 4.14: server: prevent update vm read-only details (#4629)
2 parents b6b778f + 05301b1 commit 66d49c5

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2529,12 +2529,16 @@ public UserVm updateVirtualMachine(UpdateVMCmd cmd) throws ResourceUnavailableEx
25292529
final List<String> userBlacklistedSettings = Stream.of(QueryService.UserVMBlacklistedDetails.value().split(","))
25302530
.map(item -> (item).trim())
25312531
.collect(Collectors.toList());
2532+
final List<String> userReadOnlySettings = Stream.of(QueryService.UserVMReadOnlyUIDetails.value().split(","))
2533+
.map(item -> (item).trim())
2534+
.collect(Collectors.toList());
25322535
if (cleanupDetails){
25332536
if (caller != null && caller.getType() == Account.ACCOUNT_TYPE_ADMIN) {
25342537
userVmDetailsDao.removeDetails(id);
25352538
} else {
25362539
for (final UserVmDetailVO detail : userVmDetailsDao.listDetails(id)) {
2537-
if (detail != null && !userBlacklistedSettings.contains(detail.getName())) {
2540+
if (detail != null && !userBlacklistedSettings.contains(detail.getName())
2541+
&& !userReadOnlySettings.contains(detail.getName())) {
25382542
userVmDetailsDao.removeDetail(id, detail.getName());
25392543
}
25402544
}
@@ -2546,15 +2550,18 @@ public UserVm updateVirtualMachine(UpdateVMCmd cmd) throws ResourceUnavailableEx
25462550
}
25472551

25482552
if (caller != null && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
2549-
// Ensure blacklisted detail is not passed by non-root-admin user
2553+
// Ensure blacklisted or read-only detail is not passed by non-root-admin user
25502554
for (final String detailName : details.keySet()) {
25512555
if (userBlacklistedSettings.contains(detailName)) {
25522556
throw new InvalidParameterValueException("You're not allowed to add or edit the restricted setting: " + detailName);
25532557
}
2558+
if (userReadOnlySettings.contains(detailName)) {
2559+
throw new InvalidParameterValueException("You're not allowed to add or edit the read-only setting: " + detailName);
2560+
}
25542561
}
2555-
// Add any hidden/blacklisted detail
2562+
// Add any hidden/blacklisted or read-only detail
25562563
for (final UserVmDetailVO detail : userVmDetailsDao.listDetails(id)) {
2557-
if (userBlacklistedSettings.contains(detail.getName())) {
2564+
if (userBlacklistedSettings.contains(detail.getName()) || userReadOnlySettings.contains(detail.getName())) {
25582565
details.put(detail.getName(), detail.getValue());
25592566
}
25602567
}

ui/legacy/scripts/instances.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3995,9 +3995,15 @@
39953995
// It could happen that a stale web page has been opened up when VM was stopped but
39963996
// vm was turned on through another route - UI or API. so we should check again.
39973997
var existingDetails = virtualMachine.details;
3998+
var readOnlyUIDetails = [];
3999+
if (virtualMachine.readonlyuidetails && virtualMachine.readonlyuidetails.length > 0) {
4000+
$.each(virtualMachine.readonlyuidetails.split(","), function(){
4001+
readOnlyUIDetails.push($.trim(this));
4002+
});
4003+
}
39984004
var newDetails = {};
39994005
for (d in existingDetails) {
4000-
if (d != data.name) {
4006+
if (d != data.name && $.inArray(d, readOnlyUIDetails) < 0) {
40014007
newDetails['details[0].' + d] = existingDetails[d];
40024008
}
40034009
}
@@ -4043,9 +4049,15 @@
40434049
// vm was turned on through another route - UI or API. so we should check again.
40444050
var detailToDelete = args.data.jsonObj.name;
40454051
var existingDetails = virtualMachine.details;
4052+
var readOnlyUIDetails = [];
4053+
if (virtualMachine.readonlyuidetails && virtualMachine.readonlyuidetails.length > 0) {
4054+
$.each(virtualMachine.readonlyuidetails.split(","), function(){
4055+
readOnlyUIDetails.push($.trim(this));
4056+
});
4057+
}
40464058
var newDetails = {};
40474059
for (detail in existingDetails) {
4048-
if (detail != detailToDelete) {
4060+
if (detail != detailToDelete && $.inArray(detail, readOnlyUIDetails) < 0) {
40494061
newDetails['details[0].' + detail] = existingDetails[detail];
40504062
}
40514063
}
@@ -4078,12 +4090,20 @@
40784090
var value = args.data.value;
40794091

40804092
var details;
4093+
var readOnlyUIDetails = [];
40814094
$.ajax({
40824095
url: createURL('listVirtualMachines&id=' + args.context.instances[0].id),
40834096
async:false,
40844097
success: function(json) {
4085-
var dets = json.listvirtualmachinesresponse.virtualmachine[0].details;
4086-
details = dets;
4098+
var virtualMachine = json.listvirtualmachinesresponse.virtualmachine[0]
4099+
if (virtualMachine) {
4100+
details = virtualMachine.details;
4101+
if (virtualMachine.readonlyuidetails && virtualMachine.readonlyuidetails.length > 0) {
4102+
$.each(virtualMachine.readonlyuidetails.split(","), function(){
4103+
readOnlyUIDetails.push($.trim(this));
4104+
});
4105+
}
4106+
}
40874107
},
40884108

40894109
error: function(json) {
@@ -4093,7 +4113,9 @@
40934113

40944114
var detailsFormat = '';
40954115
for (key in details) {
4096-
detailsFormat += "details[0]." + key + "=" + details[key] + "&";
4116+
if ($.inArray(key, readOnlyUIDetails) < 0) {
4117+
detailsFormat += "details[0]." + key + "=" + details[key] + "&";
4118+
}
40974119
}
40984120
// Add new detail to the existing ones
40994121
detailsFormat += "details[0]." + name + "=" + value;

0 commit comments

Comments
 (0)