Skip to content

Commit 106989c

Browse files
sureshanapartiJoaoJandre
authored andcommitted
User data content size validation, and related code improvements (apache#8418)
Co-authored-by: João Jandre <48719461+JoaoJandre@users.noreply.github.com>
1 parent 7bf2e73 commit 106989c

16 files changed

Lines changed: 88 additions & 113 deletions

File tree

api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmProfileCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public class CreateAutoScaleVmProfileCmd extends BaseAsyncCreateCmd {
100100
description = "an optional binary data that can be sent to the virtual machine upon a successful deployment. " +
101101
"This binary data must be base64 encoded before adding it to the request. " +
102102
"Using HTTP GET (via querystring), you can send up to 4KB of data after base64 encoding. " +
103-
"Using HTTP POST(via POST body), you can send up to 1MB of data after base64 encoding." +
103+
"Using HTTP POST (via POST body), you can send up to 1MB of data after base64 encoding. " +
104104
"You also need to change vm.userdata.max.length value",
105105
length = 1048576,
106106
since = "4.18.0")

api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmProfileCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public class UpdateAutoScaleVmProfileCmd extends BaseAsyncCustomIdCmd {
9595
description = "an optional binary data that can be sent to the virtual machine upon a successful deployment. " +
9696
"This binary data must be base64 encoded before adding it to the request. " +
9797
"Using HTTP GET (via querystring), you can send up to 4KB of data after base64 encoding. " +
98-
"Using HTTP POST(via POST body), you can send up to 1MB of data after base64 encoding." +
98+
"Using HTTP POST (via POST body), you can send up to 1MB of data after base64 encoding. " +
9999
"You also need to change vm.userdata.max.length value",
100100
length = 1048576,
101101
since = "4.18.0")

api/src/main/java/org/apache/cloudstack/api/command/user/userdata/RegisterUserDataCmd.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,14 @@ public class RegisterUserDataCmd extends BaseCmd {
7272
@Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.UUID, entityType = ProjectResponse.class, description = "an optional project for the userdata")
7373
private Long projectId;
7474

75-
@Parameter(name = ApiConstants.USER_DATA, type = CommandType.STRING, required = true, description = "Userdata content", length = 1048576)
75+
@Parameter(name = ApiConstants.USER_DATA,
76+
type = CommandType.STRING,
77+
required = true,
78+
description = "Base64 encoded userdata content. " +
79+
"Using HTTP GET (via querystring), you can send up to 4KB of data after base64 encoding. " +
80+
"Using HTTP POST (via POST body), you can send up to 1MB of data after base64 encoding. " +
81+
"You also need to change vm.userdata.max.length value",
82+
length = 1048576)
7683
private String userData;
7784

7885
@Parameter(name = ApiConstants.PARAMS, type = CommandType.STRING, description = "comma separated list of variables declared in userdata content")

api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,11 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityG
156156
private String hypervisor;
157157

158158
@Parameter(name = ApiConstants.USER_DATA, type = CommandType.STRING,
159-
description = "an optional binary data that can be sent to the virtual machine upon a successful deployment. This binary data must be base64 encoded before adding it to the request. Using HTTP GET (via querystring), you can send up to 4KB of data after base64 encoding. Using HTTP POST(via POST body), you can send up to 1MB of data after base64 encoding.",
159+
description = "an optional binary data that can be sent to the virtual machine upon a successful deployment. " +
160+
"This binary data must be base64 encoded before adding it to the request. " +
161+
"Using HTTP GET (via querystring), you can send up to 4KB of data after base64 encoding. " +
162+
"Using HTTP POST (via POST body), you can send up to 1MB of data after base64 encoding. " +
163+
"You also need to change vm.userdata.max.length value",
160164
length = 1048576)
161165
private String userData;
162166

api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMUserDataCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class ResetVMUserDataCmd extends BaseCmd implements UserCmd {
6060
description = "an optional binary data that can be sent to the virtual machine upon a successful deployment. " +
6161
"This binary data must be base64 encoded before adding it to the request. " +
6262
"Using HTTP GET (via querystring), you can send up to 4KB of data after base64 encoding. " +
63-
"Using HTTP POST(via POST body), you can send up to 1MB of data after base64 encoding." +
63+
"Using HTTP POST (via POST body), you can send up to 1MB of data after base64 encoding. " +
6464
"You also need to change vm.userdata.max.length value",
6565
length = 1048576)
6666
private String userData;

api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public class UpdateVMCmd extends BaseCustomIdCmd implements SecurityGroupAction,
8484
description = "an optional binary data that can be sent to the virtual machine upon a successful deployment. " +
8585
"This binary data must be base64 encoded before adding it to the request. " +
8686
"Using HTTP GET (via querystring), you can send up to 4KB of data after base64 encoding. " +
87-
"Using HTTP POST(via POST body), you can send up to 1MB of data after base64 encoding." +
87+
"Using HTTP POST (via POST body), you can send up to 1MB of data after base64 encoding. " +
8888
"You also need to change vm.userdata.max.length value",
8989
length = 1048576,
9090
since = "4.16.0")

api/src/main/java/org/apache/cloudstack/api/response/AutoScaleVmProfileResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public class AutoScaleVmProfileResponse extends BaseResponse implements Controll
6969
private Map<String, String> counterParams;
7070

7171
@SerializedName(ApiConstants.USER_DATA)
72-
@Param(description = "Base 64 encoded VM user data")
72+
@Param(description = "Base64 encoded VM user data")
7373
private String userData;
7474

7575
@SerializedName(ApiConstants.USER_DATA_ID) @Param(description="the id of userdata used for the VM", since = "4.18.1")

api/src/main/java/org/apache/cloudstack/api/response/VMUserDataResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class VMUserDataResponse extends BaseResponse {
3030
private String vmId;
3131

3232
@SerializedName(ApiConstants.USER_DATA)
33-
@Param(description = "Base 64 encoded VM user data")
33+
@Param(description = "Base64 encoded VM user data")
3434
private String userData;
3535

3636
public void setUserData(String userData) {

api/src/main/java/org/apache/cloudstack/userdata/UserDataManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@
1717
package org.apache.cloudstack.userdata;
1818

1919
import org.apache.cloudstack.api.BaseCmd;
20+
import org.apache.cloudstack.framework.config.ConfigKey;
2021
import org.apache.cloudstack.framework.config.Configurable;
2122

2223
import com.cloud.utils.component.Manager;
2324

2425
public interface UserDataManager extends Manager, Configurable {
26+
String VM_USERDATA_MAX_LENGTH_STRING = "vm.userdata.max.length";
27+
ConfigKey<Integer> VM_USERDATA_MAX_LENGTH = new ConfigKey<>("Advanced", Integer.class, VM_USERDATA_MAX_LENGTH_STRING, "32768",
28+
"Max length of vm userdata after base64 encoding. Default is 32768 and maximum is 1048576", true);
29+
2530
String concatenateUserData(String userdata1, String userdata2, String userdataProvider);
2631
String validateUserData(String userData, BaseCmd.HTTPMethod httpmethod);
2732
}

engine/components-api/src/main/java/com/cloud/configuration/ConfigurationManager.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ public interface ConfigurationManager {
6161
public static final String MESSAGE_CREATE_VLAN_IP_RANGE_EVENT = "Message.CreateVlanIpRange.Event";
6262
public static final String MESSAGE_DELETE_VLAN_IP_RANGE_EVENT = "Message.DeleteVlanIpRange.Event";
6363

64-
static final String VM_USERDATA_MAX_LENGTH_STRING = "vm.userdata.max.length";
65-
static final ConfigKey<Integer> VM_USERDATA_MAX_LENGTH = new ConfigKey<>("Advanced", Integer.class, VM_USERDATA_MAX_LENGTH_STRING, "32768",
66-
"Max length of vm userdata after base64 decoding. Default is 32768 and maximum is 1048576", true);
6764
public static final ConfigKey<Boolean> AllowNonRFC1918CompliantIPs = new ConfigKey<>(Boolean.class,
6865
"allow.non.rfc1918.compliant.ips", "Advanced", "false",
6966
"Allows non-compliant RFC 1918 IPs for Shared, Isolated networks and VPCs", true, null);

0 commit comments

Comments
 (0)