Skip to content

Hide CloudStack version from XML response when unauthenticated #10575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.cloud.api.ApiResponseGsonHelper;
import com.cloud.api.ApiServer;
import com.cloud.serializer.Param;
import com.cloud.server.ManagementServerImpl;
import com.cloud.user.Account;
import com.cloud.utils.HttpUtils;
import com.cloud.utils.encoding.URLEncoder;
Expand Down Expand Up @@ -171,9 +172,18 @@
if (result != null && log != null) {
StringBuilder sb = new StringBuilder();
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
sb.append("<").append(result.getResponseName()).append(" cloud-stack-version=\"").append(ApiDBUtils.getVersion()).append("\">");
log.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
log.append("<").append(result.getResponseName()).append(" cloud-stack-version=\"").append(ApiDBUtils.getVersion()).append("\">");

sb.append("<").append(result.getResponseName());
log.append("<").append(result.getResponseName());

Check warning on line 178 in server/src/main/java/com/cloud/api/response/ApiResponseSerializer.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/api/response/ApiResponseSerializer.java#L177-L178

Added lines #L177 - L178 were not covered by tests

boolean authenticated = CallContext.current().getCallingAccount().getId() != Account.ACCOUNT_ID_SYSTEM;
if (ManagementServerImpl.exposeCloudStackVersionInApiXmlResponse.value() && authenticated) {
sb.append(" cloud-stack-version=\"").append(ApiDBUtils.getVersion()).append("\"");
log.append(" cloud-stack-version=\"").append(ApiDBUtils.getVersion()).append("\"");

Check warning on line 183 in server/src/main/java/com/cloud/api/response/ApiResponseSerializer.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/api/response/ApiResponseSerializer.java#L182-L183

Added lines #L182 - L183 were not covered by tests
}
sb.append(">");
log.append(">");

Check warning on line 186 in server/src/main/java/com/cloud/api/response/ApiResponseSerializer.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/api/response/ApiResponseSerializer.java#L185-L186

Added lines #L185 - L186 were not covered by tests

if (result instanceof ListResponse) {
Integer count = ((ListResponse)result).getCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,9 @@
static final ConfigKey<Integer> sshKeyLength = new ConfigKey<>("Advanced", Integer.class, "ssh.key.length", "2048", "Specifies custom SSH key length (bit)", true, ConfigKey.Scope.Global);
static final ConfigKey<Boolean> humanReadableSizes = new ConfigKey<>("Advanced", Boolean.class, "display.human.readable.sizes", "true", "Enables outputting human readable byte sizes to logs and usage records.", false, ConfigKey.Scope.Global);
public static final ConfigKey<String> customCsIdentifier = new ConfigKey<>("Advanced", String.class, "custom.cs.identifier", UUID.randomUUID().toString().split("-")[0].substring(4), "Custom identifier for the cloudstack installation", true, ConfigKey.Scope.Global);
public static final ConfigKey<Boolean> exposeCloudStackVersionInApiXmlResponse = new ConfigKey<Boolean>("Advanced", Boolean.class, "expose.cloudstack.version.api.xml.response", "true", "Indicates whether ACS version should appear in the root element of an API XML response.", true, ConfigKey.Scope.Global);
public static final ConfigKey<Boolean> exposeCloudStackVersionInApiListCapabilities = new ConfigKey<Boolean>("Advanced", Boolean.class, "expose.cloudstack.version.api.list.capabilities", "true", "Indicates whether ACS version should show in the listCapabilities API.", true, ConfigKey.Scope.Global);

private static final VirtualMachine.Type []systemVmTypes = { VirtualMachine.Type.SecondaryStorageVm, VirtualMachine.Type.ConsoleProxy};
private static final List<HypervisorType> LIVE_MIGRATION_SUPPORTING_HYPERVISORS = List.of(HypervisorType.Hyperv, HypervisorType.KVM,
HypervisorType.LXC, HypervisorType.Ovm, HypervisorType.Ovm3, HypervisorType.Simulator, HypervisorType.VMware, HypervisorType.XenServer);
Expand Down Expand Up @@ -4055,7 +4058,7 @@

@Override
public ConfigKey<?>[] getConfigKeys() {
return new ConfigKey<?>[] {vmPasswordLength, sshKeyLength, humanReadableSizes, customCsIdentifier};
return new ConfigKey<?>[] {exposeCloudStackVersionInApiXmlResponse, exposeCloudStackVersionInApiListCapabilities, vmPasswordLength, sshKeyLength, humanReadableSizes, customCsIdentifier};

Check warning on line 4061 in server/src/main/java/com/cloud/server/ManagementServerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/server/ManagementServerImpl.java#L4061

Added line #L4061 was not covered by tests
}

protected class EventPurgeTask extends ManagedContextRunnable {
Expand Down Expand Up @@ -4481,10 +4484,12 @@

final Integer fsVmMinCpu = Integer.parseInt(_configDao.getValue("sharedfsvm.min.cpu.count"));
final Integer fsVmMinRam = Integer.parseInt(_configDao.getValue("sharedfsvm.min.ram.size"));
if (exposeCloudStackVersionInApiListCapabilities.value()) {
capabilities.put("cloudStackVersion", getVersion());

Check warning on line 4488 in server/src/main/java/com/cloud/server/ManagementServerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/server/ManagementServerImpl.java#L4488

Added line #L4488 was not covered by tests
}

capabilities.put("securityGroupsEnabled", securityGroupsEnabled);
capabilities.put("userPublicTemplateEnabled", userPublicTemplateEnabled);
capabilities.put("cloudStackVersion", getVersion());
capabilities.put("supportELB", supportELB);
capabilities.put("projectInviteRequired", _projectMgr.projectInviteRequired());
capabilities.put("allowusercreateprojects", _projectMgr.allowUserToCreateProject());
Expand Down