-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Console access enhancements #6577
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
5d4f274
Console access enhancements
nvazquez b2f71cf
Remove extra logging
nvazquez 52433cc
Fix security hotspot
nvazquez 390c7bb
Fix sonar cloud code smells
nvazquez f8e97c9
Refactor API response
nvazquez e2a2153
Minor fix
nvazquez cd8a537
Refactor and increase timeout on ssh to cpvm
nvazquez 056f763
Add marvin tests and extend permissions
nvazquez 3df57b8
Add unit tests
nvazquez 835c017
Check vncport file exits on CPVM before attempting to add rules
nvazquez 92d6be6
Change how vncport is read on cpvm
nvazquez 2e85bdc
Extra validation refactor
nvazquez 02ce0cd
Fix wrong token API param on UI
nvazquez 44bb753
Refactor vnc port selection to 8080 or 8443
nvazquez f9faa03
Do not display the input token modal and improve error message on con…
nvazquez 6c4271c
Refactor and cleanup
nvazquez 4e04a9e
Improve error message and prevent opening blank popup when errors
nvazquez 998f23f
Fix logging exception due to algorithm
nvazquez 42e4497
Address review comments
nvazquez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
api/src/main/java/org/apache/cloudstack/api/command/user/consoleproxy/ConsoleEndpoint.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
| package org.apache.cloudstack.api.command.user.consoleproxy; | ||
|
|
||
| public class ConsoleEndpoint { | ||
|
|
||
| private boolean result; | ||
| private String details; | ||
| private String url; | ||
| private String websocketToken; | ||
| private String websocketPath; | ||
| private String websocketHost; | ||
| private String websocketPort; | ||
|
|
||
| public ConsoleEndpoint(boolean result, String url) { | ||
| this.result = result; | ||
| this.url = url; | ||
| } | ||
|
|
||
| public ConsoleEndpoint(boolean result, String url, String details) { | ||
| this(result, url); | ||
| this.details = details; | ||
| } | ||
|
|
||
| public boolean isResult() { | ||
| return result; | ||
| } | ||
|
|
||
| public void setResult(boolean result) { | ||
| this.result = result; | ||
| } | ||
|
|
||
| public String getUrl() { | ||
| return url; | ||
| } | ||
|
|
||
| public void setUrl(String url) { | ||
| this.url = url; | ||
| } | ||
|
|
||
| public String getDetails() { | ||
| return details; | ||
| } | ||
|
|
||
| public void setDetails(String details) { | ||
| this.details = details; | ||
| } | ||
|
|
||
| public String getWebsocketToken() { | ||
| return websocketToken; | ||
| } | ||
|
|
||
| public void setWebsocketToken(String websocketToken) { | ||
| this.websocketToken = websocketToken; | ||
| } | ||
|
|
||
| public String getWebsocketPath() { | ||
| return websocketPath; | ||
| } | ||
|
|
||
| public void setWebsocketPath(String websocketPath) { | ||
| this.websocketPath = websocketPath; | ||
| } | ||
|
|
||
| public String getWebsocketHost() { | ||
| return websocketHost; | ||
| } | ||
|
|
||
| public void setWebsocketHost(String websocketHost) { | ||
| this.websocketHost = websocketHost; | ||
| } | ||
|
|
||
| public String getWebsocketPort() { | ||
| return websocketPort; | ||
| } | ||
|
|
||
| public void setWebsocketPort(String websocketPort) { | ||
| this.websocketPort = websocketPort; | ||
| } | ||
| } |
116 changes: 116 additions & 0 deletions
116
...in/java/org/apache/cloudstack/api/command/user/consoleproxy/CreateConsoleEndpointCmd.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
| package org.apache.cloudstack.api.command.user.consoleproxy; | ||
|
|
||
| import com.cloud.exception.ConcurrentOperationException; | ||
| import com.cloud.exception.InsufficientCapacityException; | ||
| import com.cloud.exception.NetworkRuleConflictException; | ||
| import com.cloud.exception.ResourceAllocationException; | ||
| import com.cloud.exception.ResourceUnavailableException; | ||
| import org.apache.cloudstack.api.APICommand; | ||
| import org.apache.cloudstack.api.ApiConstants; | ||
| import org.apache.cloudstack.api.ApiErrorCode; | ||
| import org.apache.cloudstack.api.BaseCmd; | ||
| import org.apache.cloudstack.api.Parameter; | ||
| import org.apache.cloudstack.api.ServerApiException; | ||
| import org.apache.cloudstack.api.response.ConsoleEndpointWebsocketResponse; | ||
| import org.apache.cloudstack.api.response.CreateConsoleEndpointResponse; | ||
| import org.apache.cloudstack.api.response.UserVmResponse; | ||
| import org.apache.cloudstack.consoleproxy.ConsoleAccessManager; | ||
| import org.apache.cloudstack.context.CallContext; | ||
| import org.apache.cloudstack.utils.consoleproxy.ConsoleAccessUtils; | ||
| import org.apache.commons.collections.MapUtils; | ||
| import org.apache.log4j.Logger; | ||
|
|
||
| import javax.inject.Inject; | ||
| import java.util.Map; | ||
|
|
||
| @APICommand(name = CreateConsoleEndpointCmd.APINAME, description = "Create a console endpoint to connect to a VM console", | ||
| responseObject = CreateConsoleEndpointResponse.class, since = "4.18.0", | ||
| requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) | ||
| public class CreateConsoleEndpointCmd extends BaseCmd { | ||
|
|
||
| public static final String APINAME = "createConsoleEndpoint"; | ||
| public static final Logger s_logger = Logger.getLogger(CreateConsoleEndpointCmd.class.getName()); | ||
|
|
||
| @Inject | ||
| private ConsoleAccessManager consoleManager; | ||
|
|
||
| @Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID, | ||
| type = CommandType.UUID, | ||
| entityType = UserVmResponse.class, | ||
| required = true, | ||
| description = "ID of the VM") | ||
| private Long vmId; | ||
|
|
||
| @Override | ||
| public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { | ||
| String clientSecurityToken = getClientSecurityToken(); | ||
| String clientAddress = getClientAddress(); | ||
| ConsoleEndpoint endpoint = consoleManager.generateConsoleEndpoint(vmId, clientSecurityToken, clientAddress); | ||
| if (endpoint != null) { | ||
| CreateConsoleEndpointResponse response = createResponse(endpoint); | ||
| setResponseObject(response); | ||
| } else { | ||
| throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Unable to generate console endpoint for vm " + vmId); | ||
| } | ||
| } | ||
|
|
||
| private CreateConsoleEndpointResponse createResponse(ConsoleEndpoint endpoint) { | ||
| CreateConsoleEndpointResponse response = new CreateConsoleEndpointResponse(); | ||
| response.setResult(endpoint.isResult()); | ||
| response.setDetails(endpoint.getDetails()); | ||
| response.setUrl(endpoint.getUrl()); | ||
| response.setWebsocketResponse(createWebsocketResponse(endpoint)); | ||
| response.setResponseName(getCommandName()); | ||
| response.setObjectName("consoleendpoint"); | ||
| return response; | ||
| } | ||
|
|
||
| private ConsoleEndpointWebsocketResponse createWebsocketResponse(ConsoleEndpoint endpoint) { | ||
| ConsoleEndpointWebsocketResponse wsResponse = new ConsoleEndpointWebsocketResponse(); | ||
| wsResponse.setHost(endpoint.getWebsocketHost()); | ||
| wsResponse.setPort(endpoint.getWebsocketPort()); | ||
| wsResponse.setPath(endpoint.getWebsocketPath()); | ||
| wsResponse.setToken(endpoint.getWebsocketToken()); | ||
| wsResponse.setObjectName("websocket"); | ||
| return wsResponse; | ||
| } | ||
|
|
||
| private String getParameterBase(String paramKey) { | ||
| Map<String, String> params = getFullUrlParams(); | ||
| return MapUtils.isNotEmpty(params) && params.containsKey(paramKey) ? params.get(paramKey) : null; | ||
| } | ||
|
|
||
| private String getClientAddress() { | ||
| return getParameterBase(ConsoleAccessUtils.CLIENT_INET_ADDRESS_KEY); | ||
| } | ||
|
|
||
| private String getClientSecurityToken() { | ||
| return getParameterBase(ConsoleAccessUtils.CLIENT_SECURITY_HEADER_PARAM_KEY); | ||
| } | ||
|
|
||
| @Override | ||
| public String getCommandName() { | ||
| return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX; | ||
| } | ||
|
|
||
| @Override | ||
| public long getEntityOwnerId() { | ||
| return CallContext.current().getCallingAccount().getId(); | ||
| } | ||
| } | ||
76 changes: 76 additions & 0 deletions
76
api/src/main/java/org/apache/cloudstack/api/response/ConsoleEndpointWebsocketResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
| package org.apache.cloudstack.api.response; | ||
|
|
||
| import com.cloud.serializer.Param; | ||
| import com.google.gson.annotations.SerializedName; | ||
| import org.apache.cloudstack.api.ApiConstants; | ||
| import org.apache.cloudstack.api.BaseResponse; | ||
|
|
||
| public class ConsoleEndpointWebsocketResponse extends BaseResponse { | ||
|
|
||
| public ConsoleEndpointWebsocketResponse() { | ||
| } | ||
|
|
||
| @SerializedName(ApiConstants.TOKEN) | ||
| @Param(description = "the console websocket token") | ||
| private String token; | ||
|
|
||
| @SerializedName("host") | ||
| @Param(description = "the console websocket host") | ||
| private String host; | ||
|
|
||
| @SerializedName(ApiConstants.PORT) | ||
| @Param(description = "the console websocket port") | ||
| private String port; | ||
|
|
||
| @SerializedName(ApiConstants.PATH) | ||
| @Param(description = "the console websocket path") | ||
| private String path; | ||
|
|
||
| public String getToken() { | ||
| return token; | ||
| } | ||
|
|
||
| public void setToken(String token) { | ||
| this.token = token; | ||
| } | ||
|
|
||
| public String getHost() { | ||
| return host; | ||
| } | ||
|
|
||
| public void setHost(String host) { | ||
| this.host = host; | ||
| } | ||
|
|
||
| public String getPort() { | ||
| return port; | ||
| } | ||
|
|
||
| public void setPort(String port) { | ||
| this.port = port; | ||
| } | ||
|
|
||
| public String getPath() { | ||
| return path; | ||
| } | ||
|
|
||
| public void setPath(String path) { | ||
| this.path = path; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.