Skip to content

Commit 77fb93c

Browse files
authored
core: use the URL scheme same as iframe for non-SSL enabled consoles (#5624)
* core: use the URL scheme same as iframe for non-SSL enabled consoles For environments where SSL is not enabled for console, this forces the URL scheme (http/https) in iframe to match the iframe URL scheme. Signed-off-by: Rohit Yadav <[email protected]> * consoleproxy: enable SSL on CPVM when both console proxy url/domain and ssl setting are configured Signed-off-by: Rohit Yadav <[email protected]> * fix unit test Signed-off-by: Rohit Yadav <[email protected]> * address code review comments Signed-off-by: Rohit Yadav <[email protected]>
1 parent 0a88e71 commit 77fb93c

3 files changed

Lines changed: 17 additions & 15 deletions

File tree

core/src/main/java/com/cloud/info/ConsoleProxyInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public ConsoleProxyInfo(boolean sslEnabled, String proxyIpAddress, int port, int
4646
}
4747

4848
} else {
49-
proxyImageUrl = "http://" + proxyAddress;
49+
proxyImageUrl = "//" + proxyAddress;
5050
if (proxyUrlPort != 80) {
5151
proxyImageUrl += ":" + proxyUrlPort;
5252
}

core/src/test/java/com/cloud/info/ConsoleProxyInfoTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919

2020
package com.cloud.info;
2121

22-
import org.junit.Test;
23-
2422
import static org.junit.Assert.assertEquals;
2523

24+
import org.junit.Test;
25+
2626
public class ConsoleProxyInfoTest {
2727

2828
@Test
@@ -35,7 +35,7 @@ public void testGetProxyImageUrlHttps() {
3535
public void testGetProxyImageUrlHttp() {
3636
ConsoleProxyInfo cpi = new ConsoleProxyInfo(false, "10.10.10.10", 80, 80 , "console.example.com");
3737
String url = cpi.getProxyImageUrl();
38-
assertEquals("http://console.example.com", url);
38+
assertEquals("//console.example.com", url);
3939
}
4040
@Test
4141
public void testGetProxyImageUrlWildcardHttps() {
@@ -47,13 +47,13 @@ public void testGetProxyImageUrlWildcardHttps() {
4747
public void testGetProxyImageUrlWildcardHttp() {
4848
ConsoleProxyInfo cpi = new ConsoleProxyInfo(false, "1.2.3.4", 80, 8888 , "*.example.com");
4949
String url = cpi.getProxyImageUrl();
50-
assertEquals("http://1-2-3-4.example.com:8888", url);
50+
assertEquals("//1-2-3-4.example.com:8888", url);
5151
}
5252
@Test
5353
public void testGetProxyImageUrlIpHttp() {
5454
ConsoleProxyInfo cpi = new ConsoleProxyInfo(false, "1.2.3.4", 80, 8888, "");
5555
String url = cpi.getProxyImageUrl();
56-
assertEquals("http://1.2.3.4:8888", url);
56+
assertEquals("//1.2.3.4:8888", url);
5757
}
5858
@Test
5959
public void testGetProxyImageUrlIpHttps() {

server/src/main/java/com/cloud/consoleproxy/AgentHookBase.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,12 @@
2121
import java.security.SecureRandom;
2222
import java.util.Date;
2323

24-
import org.apache.commons.codec.binary.Base64;
25-
import org.apache.log4j.Logger;
26-
27-
import com.google.gson.Gson;
28-
import com.google.gson.GsonBuilder;
29-
3024
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
3125
import org.apache.cloudstack.framework.security.keys.KeysManager;
3226
import org.apache.cloudstack.framework.security.keystore.KeystoreManager;
27+
import org.apache.commons.codec.binary.Base64;
28+
import org.apache.commons.lang3.StringUtils;
29+
import org.apache.log4j.Logger;
3330

3431
import com.cloud.agent.AgentManager;
3532
import com.cloud.agent.api.AgentControlAnswer;
@@ -54,6 +51,8 @@
5451
import com.cloud.utils.Ternary;
5552
import com.cloud.vm.VirtualMachine;
5653
import com.cloud.vm.dao.VMInstanceDao;
54+
import com.google.gson.Gson;
55+
import com.google.gson.GsonBuilder;
5756

5857
/**
5958
* Utility class to manage interactions with agent-based console access
@@ -198,12 +197,15 @@ public void startAgentHttpHandlerInVM(StartupProxyCommand startupCmd) {
198197
String storePassword = Base64.encodeBase64String(randomBytes);
199198

200199
byte[] ksBits = null;
200+
201201
String consoleProxyUrlDomain = _configDao.getValue(Config.ConsoleProxyUrlDomain.key());
202-
if (consoleProxyUrlDomain == null || consoleProxyUrlDomain.isEmpty()) {
203-
s_logger.debug("SSL is disabled for console proxy based on global config, skip loading certificates");
204-
} else {
202+
String consoleProxySslEnabled = _configDao.getValue("consoleproxy.sslEnabled");
203+
if (!StringUtils.isEmpty(consoleProxyUrlDomain) && !StringUtils.isEmpty(consoleProxySslEnabled)
204+
&& consoleProxySslEnabled.equalsIgnoreCase("true")) {
205205
ksBits = _ksMgr.getKeystoreBits(ConsoleProxyManager.CERTIFICATE_NAME, ConsoleProxyManager.CERTIFICATE_NAME, storePassword);
206206
//ks manager raises exception if ksBits are null, hence no need to explicltly handle the condition
207+
} else {
208+
s_logger.debug("SSL is disabled for console proxy. To enable SSL, please configure consoleproxy.sslEnabled and consoleproxy.url.domain global settings.");
207209
}
208210

209211
cmd = new StartConsoleProxyAgentHttpHandlerCommand(ksBits, storePassword);

0 commit comments

Comments
 (0)