Skip to content
Merged
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 @@ -397,9 +397,8 @@
}

public String authenticateConsoleAccess(String host, String port, String vmId, String sid, String ticket,
Boolean isReauthentication, String sessionToken) {

ConsoleAccessAuthenticationCommand cmd = new ConsoleAccessAuthenticationCommand(host, port, vmId, sid, ticket, sessionToken);
Boolean isReauthentication, String sessionToken, String clientAddress) {
ConsoleAccessAuthenticationCommand cmd = new ConsoleAccessAuthenticationCommand(host, port, vmId, sid, ticket, sessionToken, clientAddress);

Check warning on line 401 in agent/src/main/java/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java

View check run for this annotation

Codecov / codecov/patch

agent/src/main/java/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java#L400-L401

Added lines #L400 - L401 were not covered by tests
cmd.setReauthenticating(isReauthentication);

ConsoleProxyAuthenticationResult result = new ConsoleProxyAuthenticationResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public interface ConsoleAccessManager extends Manager, Configurable {

void removeSessions(String[] sessionUuids);

void acquireSession(String sessionUuid);
void acquireSession(String sessionUuid, String clientAddress);

String genAccessTicket(String host, String port, String sid, String tag, String sessionUuid);
String genAccessTicket(String host, String port, String sid, String tag, Date normalizedHashTime, String sessionUuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
private String _sid;
private String _ticket;
private String sessionUuid;
private String clientAddress;

private boolean _isReauthenticating;

Expand All @@ -35,13 +36,14 @@
}

public ConsoleAccessAuthenticationCommand(String host, String port, String vmId, String sid, String ticket,
String sessiontkn) {
String sessiontkn, String clientAddress) {

Check warning on line 39 in core/src/main/java/com/cloud/agent/api/ConsoleAccessAuthenticationCommand.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/ConsoleAccessAuthenticationCommand.java#L39

Added line #L39 was not covered by tests
_host = host;
_port = port;
_vmId = vmId;
_sid = sid;
_ticket = ticket;
sessionUuid = sessiontkn;
this.clientAddress = clientAddress;

Check warning on line 46 in core/src/main/java/com/cloud/agent/api/ConsoleAccessAuthenticationCommand.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/ConsoleAccessAuthenticationCommand.java#L46

Added line #L46 was not covered by tests
}

public String getHost() {
Expand Down Expand Up @@ -79,4 +81,12 @@
public void setSessionUuid(String sessionUuid) {
this.sessionUuid = sessionUuid;
}

public String getClientAddress() {
return clientAddress;
}

Check warning on line 87 in core/src/main/java/com/cloud/agent/api/ConsoleAccessAuthenticationCommand.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/ConsoleAccessAuthenticationCommand.java#L85-L87

Added lines #L85 - L87 were not covered by tests

public void setClientAddress(String clientAddress) {
this.clientAddress = clientAddress;
}

Check warning on line 91 in core/src/main/java/com/cloud/agent/api/ConsoleAccessAuthenticationCommand.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/ConsoleAccessAuthenticationCommand.java#L89-L91

Added lines #L89 - L91 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
import com.cloud.upgrade.dao.Upgrade41900to41910;
import com.cloud.upgrade.dao.Upgrade41910to42000;
import com.cloud.upgrade.dao.Upgrade42000to42010;
import com.cloud.upgrade.dao.Upgrade42010to42100;
import com.cloud.upgrade.dao.Upgrade420to421;
import com.cloud.upgrade.dao.Upgrade421to430;
import com.cloud.upgrade.dao.Upgrade430to440;
Expand Down Expand Up @@ -232,6 +233,7 @@ public DatabaseUpgradeChecker() {
.next("4.19.0.0", new Upgrade41900to41910())
.next("4.19.1.0", new Upgrade41910to42000())
.next("4.20.0.0", new Upgrade42000to42010())
.next("4.20.1.0", new Upgrade42010to42100())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// 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 com.cloud.upgrade.dao;

import com.cloud.upgrade.SystemVmTemplateRegistration;
import com.cloud.utils.exception.CloudRuntimeException;

import java.io.InputStream;
import java.sql.Connection;

public class Upgrade42010to42100 extends DbUpgradeAbstractImpl implements DbUpgrade, DbUpgradeSystemVmTemplate {
private SystemVmTemplateRegistration systemVmTemplateRegistration;

@Override
public String[] getUpgradableVersionRange() {
return new String[] {"4.20.1.0", "4.21.0.0"};
}

Check warning on line 31 in engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42010to42100.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42010to42100.java#L29-L31

Added lines #L29 - L31 were not covered by tests

@Override
public String getUpgradedVersion() {
return "4.21.0.0";
}

@Override
public boolean supportsRollingUpgrade() {
return false;
}

Check warning on line 41 in engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42010to42100.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42010to42100.java#L39-L41

Added lines #L39 - L41 were not covered by tests

@Override
public InputStream[] getPrepareScripts() {
final String scriptFile = "META-INF/db/schema-42010to42100.sql";
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);

Check warning on line 46 in engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42010to42100.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42010to42100.java#L44-L46

Added lines #L44 - L46 were not covered by tests
if (script == null) {
throw new CloudRuntimeException("Unable to find " + scriptFile);

Check warning on line 48 in engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42010to42100.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42010to42100.java#L48

Added line #L48 was not covered by tests
}

return new InputStream[] {script};
}

Check warning on line 52 in engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42010to42100.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42010to42100.java#L51-L52

Added lines #L51 - L52 were not covered by tests

@Override
public void performDataMigration(Connection conn) {
}

Check warning on line 56 in engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42010to42100.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42010to42100.java#L55-L56

Added lines #L55 - L56 were not covered by tests

@Override
public InputStream[] getCleanupScripts() {
final String scriptFile = "META-INF/db/schema-42010to42100-cleanup.sql";
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);

Check warning on line 61 in engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42010to42100.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42010to42100.java#L59-L61

Added lines #L59 - L61 were not covered by tests
if (script == null) {
throw new CloudRuntimeException("Unable to find " + scriptFile);

Check warning on line 63 in engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42010to42100.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42010to42100.java#L63

Added line #L63 was not covered by tests
}

return new InputStream[] {script};
}

Check warning on line 67 in engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42010to42100.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42010to42100.java#L66-L67

Added lines #L66 - L67 were not covered by tests

private void initSystemVmTemplateRegistration() {
systemVmTemplateRegistration = new SystemVmTemplateRegistration("");
}

Check warning on line 71 in engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42010to42100.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42010to42100.java#L69-L71

Added lines #L69 - L71 were not covered by tests

@Override
public void updateSystemVmTemplates(Connection conn) {
logger.debug("Updating System Vm template IDs");
initSystemVmTemplateRegistration();
try {
systemVmTemplateRegistration.updateSystemVmTemplates(conn);
} catch (Exception e) {
throw new CloudRuntimeException("Failed to find / register SystemVM template(s)");
}
}

Check warning on line 82 in engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42010to42100.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42010to42100.java#L74-L82

Added lines #L74 - L82 were not covered by tests
}
22 changes: 22 additions & 0 deletions engine/schema/src/main/java/com/cloud/vm/ConsoleSessionVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@
@Column(name = "removed")
private Date removed;

@Column(name = "console_endpoint_creator_address")
private String consoleEndpointCreatorAddress;

@Column(name = "client_address")
private String clientAddress;

public long getId() {
return id;
}
Expand Down Expand Up @@ -135,4 +141,20 @@
public void setAcquired(Date acquired) {
this.acquired = acquired;
}

public String getConsoleEndpointCreatorAddress() {
return consoleEndpointCreatorAddress;
}

Check warning on line 147 in engine/schema/src/main/java/com/cloud/vm/ConsoleSessionVO.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/vm/ConsoleSessionVO.java#L145-L147

Added lines #L145 - L147 were not covered by tests

public void setConsoleEndpointCreatorAddress(String consoleEndpointCreatorAddress) {
this.consoleEndpointCreatorAddress = consoleEndpointCreatorAddress;
}

Check warning on line 151 in engine/schema/src/main/java/com/cloud/vm/ConsoleSessionVO.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/vm/ConsoleSessionVO.java#L149-L151

Added lines #L149 - L151 were not covered by tests

public String getClientAddress() {
return clientAddress;
}

Check warning on line 155 in engine/schema/src/main/java/com/cloud/vm/ConsoleSessionVO.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/vm/ConsoleSessionVO.java#L153-L155

Added lines #L153 - L155 were not covered by tests

public void setClientAddress(String clientAddress) {
this.clientAddress = clientAddress;
}

Check warning on line 159 in engine/schema/src/main/java/com/cloud/vm/ConsoleSessionVO.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/vm/ConsoleSessionVO.java#L157-L159

Added lines #L157 - L159 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public interface ConsoleSessionDao extends GenericDao<ConsoleSessionVO, Long> {

int expungeSessionsOlderThanDate(Date date);

void acquireSession(String sessionUuid);
void acquireSession(String sessionUuid, String clientAddress);

int expungeByVmList(List<Long> vmIds, Long batchSize);
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@
}

@Override
public void acquireSession(String sessionUuid) {
public void acquireSession(String sessionUuid, String clientAddress) {

Check warning on line 65 in engine/schema/src/main/java/com/cloud/vm/dao/ConsoleSessionDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/vm/dao/ConsoleSessionDaoImpl.java#L65

Added line #L65 was not covered by tests
ConsoleSessionVO consoleSessionVO = findByUuid(sessionUuid);
consoleSessionVO.setAcquired(new Date());
consoleSessionVO.setClientAddress(clientAddress);

Check warning on line 68 in engine/schema/src/main/java/com/cloud/vm/dao/ConsoleSessionDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/vm/dao/ConsoleSessionDaoImpl.java#L68

Added line #L68 was not covered by tests
update(consoleSessionVO.getId(), consoleSessionVO);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- 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.

--;
-- Schema upgrade cleanup from 4.20.1.0 to 4.21.0.0
--;
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- 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.

--;
-- Schema upgrade from 4.20.1.0 to 4.21.0.0
--;

-- Add console_endpoint_creator_address column to cloud.console_session table
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.console_session', 'console_endpoint_creator_address', 'VARCHAR(45)');

-- Add client_address column to cloud.console_session table
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.console_session', 'client_address', 'VARCHAR(45)');
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@

String ticketInUrl = cmd.getTicket();
String sessionUuid = cmd.getSessionUuid();
String clientAddress = cmd.getClientAddress();

Check warning on line 92 in server/src/main/java/com/cloud/consoleproxy/AgentHookBase.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L92 was not covered by tests

if (ticketInUrl == null) {
logger.error("Access ticket could not be found, you could be running an old version of console proxy. vmId: " + cmd.getVmId());
Expand All @@ -111,7 +112,7 @@
}

logger.debug(String.format("Acquiring session [%s] as it was just used.", sessionUuid));
consoleAccessManager.acquireSession(sessionUuid);
consoleAccessManager.acquireSession(sessionUuid, clientAddress);

Check warning on line 115 in server/src/main/java/com/cloud/consoleproxy/AgentHookBase.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L115 was not covered by tests

if (!ticket.equals(ticketInUrl)) {
Date now = new Date();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@
}

@Override
public void acquireSession(String sessionUuid) {
consoleSessionDao.acquireSession(sessionUuid);
public void acquireSession(String sessionUuid, String clientAddress) {
consoleSessionDao.acquireSession(sessionUuid, clientAddress);

Check warning on line 252 in server/src/main/java/org/apache/cloudstack/consoleproxy/ConsoleAccessManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/apache/cloudstack/consoleproxy/ConsoleAccessManagerImpl.java#L251-L252

Added lines #L251 - L252 were not covered by tests
}

protected boolean checkSessionPermission(VirtualMachine vm, Account account) {
Expand Down Expand Up @@ -389,7 +389,7 @@
String url = generateConsoleAccessUrl(rootUrl, param, token, vncPort, vm, hostVo, details);

logger.debug("Adding allowed session: " + sessionUuid);
persistConsoleSession(sessionUuid, vm.getId(), hostVo.getId());
persistConsoleSession(sessionUuid, vm.getId(), hostVo.getId(), addr);

Check warning on line 392 in server/src/main/java/org/apache/cloudstack/consoleproxy/ConsoleAccessManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/apache/cloudstack/consoleproxy/ConsoleAccessManagerImpl.java#L392

Added line #L392 was not covered by tests
managementServer.setConsoleAccessForVm(vm.getId(), sessionUuid);

ConsoleEndpoint consoleEndpoint = new ConsoleEndpoint(true, url);
Expand All @@ -403,13 +403,14 @@
return consoleEndpoint;
}

protected void persistConsoleSession(String sessionUuid, long instanceId, long hostId) {
protected void persistConsoleSession(String sessionUuid, long instanceId, long hostId, String consoleEndpointCreatorAddress) {

Check warning on line 406 in server/src/main/java/org/apache/cloudstack/consoleproxy/ConsoleAccessManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/apache/cloudstack/consoleproxy/ConsoleAccessManagerImpl.java#L406

Added line #L406 was not covered by tests
ConsoleSessionVO consoleSessionVo = new ConsoleSessionVO();
consoleSessionVo.setUuid(sessionUuid);
consoleSessionVo.setAccountId(CallContext.current().getCallingAccountId());
consoleSessionVo.setUserId(CallContext.current().getCallingUserId());
consoleSessionVo.setInstanceId(instanceId);
consoleSessionVo.setHostId(hostId);
consoleSessionVo.setConsoleEndpointCreatorAddress(consoleEndpointCreatorAddress);

Check warning on line 413 in server/src/main/java/org/apache/cloudstack/consoleproxy/ConsoleAccessManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/apache/cloudstack/consoleproxy/ConsoleAccessManagerImpl.java#L413

Added line #L413 was not covered by tests
consoleSessionDao.persist(consoleSessionVo);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@
}

public static ConsoleProxyAuthenticationResult authenticateConsoleAccess(ConsoleProxyClientParam param, boolean reauthentication) {

ConsoleProxyAuthenticationResult authResult = new ConsoleProxyAuthenticationResult();
authResult.setSuccess(true);
authResult.setReauthentication(reauthentication);
Expand Down Expand Up @@ -227,7 +226,7 @@
try {
result =
authMethod.invoke(ConsoleProxy.context, param.getClientHostAddress(), String.valueOf(param.getClientHostPort()), param.getClientTag(),
param.getClientHostPassword(), param.getTicket(), reauthentication, param.getSessionUuid());
param.getClientHostPassword(), param.getTicket(), reauthentication, param.getSessionUuid(), param.getClientIp());

Check warning on line 229 in services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxy.java

View check run for this annotation

Codecov / codecov/patch

services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxy.java#L229

Added line #L229 was not covered by tests
} catch (IllegalAccessException e) {
LOGGER.error("Unable to invoke authenticateConsoleAccess due to IllegalAccessException" + " for vm: " + param.getClientTag(), e);
authResult.setSuccess(false);
Expand Down Expand Up @@ -301,7 +300,7 @@
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
Class<?> contextClazz = loader.loadClass("com.cloud.agent.resource.consoleproxy.ConsoleProxyResource");
authMethod = contextClazz.getDeclaredMethod("authenticateConsoleAccess", String.class, String.class,
String.class, String.class, String.class, Boolean.class, String.class);
String.class, String.class, String.class, Boolean.class, String.class, String.class);
reportMethod = contextClazz.getDeclaredMethod("reportLoadInfo", String.class);
ensureRouteMethod = contextClazz.getDeclaredMethod("ensureRoute", String.class);
} catch (SecurityException e) {
Expand Down
Loading