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 @@ protected void runInContext() {
}

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);
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 @@ public class ConsoleAccessAuthenticationCommand extends AgentControlCommand {
private String _sid;
private String _ticket;
private String sessionUuid;
private String clientAddress;

private boolean _isReauthenticating;

Expand All @@ -35,13 +36,14 @@ public ConsoleAccessAuthenticationCommand() {
}

public ConsoleAccessAuthenticationCommand(String host, String port, String vmId, String sid, String ticket,
String sessiontkn) {
String sessiontkn, String clientAddress) {
_host = host;
_port = port;
_vmId = vmId;
_sid = sid;
_ticket = ticket;
sessionUuid = sessiontkn;
this.clientAddress = clientAddress;
}

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

public String getClientAddress() {
return clientAddress;
}

public void setClientAddress(String clientAddress) {
this.clientAddress = clientAddress;
}
}
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"};
}

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

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

@Override
public InputStream[] getPrepareScripts() {
final String scriptFile = "META-INF/db/schema-42010to42100.sql";
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
if (script == null) {
throw new CloudRuntimeException("Unable to find " + scriptFile);
}

return new InputStream[] {script};
}

@Override
public void performDataMigration(Connection conn) {
}

@Override
public InputStream[] getCleanupScripts() {
final String scriptFile = "META-INF/db/schema-42010to42100-cleanup.sql";
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
if (script == null) {
throw new CloudRuntimeException("Unable to find " + scriptFile);
}

return new InputStream[] {script};
}

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

@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)");
}
}
}
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 @@ public class ConsoleSessionVO {
@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 Date getAcquired() {
public void setAcquired(Date acquired) {
this.acquired = acquired;
}

public String getConsoleEndpointCreatorAddress() {
return consoleEndpointCreatorAddress;
}

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

public String getClientAddress() {
return clientAddress;
}

public void setClientAddress(String clientAddress) {
this.clientAddress = clientAddress;
}
}
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 @@ public int expungeSessionsOlderThanDate(Date date) {
}

@Override
public void acquireSession(String sessionUuid) {
public void acquireSession(String sessionUuid, String clientAddress) {
ConsoleSessionVO consoleSessionVO = findByUuid(sessionUuid);
consoleSessionVO.setAcquired(new Date());
consoleSessionVO.setClientAddress(clientAddress);
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 @@ public AgentControlAnswer onConsoleAccessAuthentication(ConsoleAccessAuthenticat

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

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 @@ public AgentControlAnswer onConsoleAccessAuthentication(ConsoleAccessAuthenticat
}

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

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 @@ protected void removeSession(String sessionUuid) {
}

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

protected boolean checkSessionPermission(VirtualMachine vm, Account account) {
Expand Down Expand Up @@ -389,7 +389,7 @@ private ConsoleEndpoint composeConsoleAccessEndpoint(String rootUrl, VirtualMach
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);
managementServer.setConsoleAccessForVm(vm.getId(), sessionUuid);

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

protected void persistConsoleSession(String sessionUuid, long instanceId, long hostId) {
protected void persistConsoleSession(String sessionUuid, long instanceId, long hostId, String consoleEndpointCreatorAddress) {
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);
consoleSessionDao.persist(consoleSessionVo);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ public static ConsoleProxyServerFactory getHttpServerFactory() {
}

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 @@ public static ConsoleProxyAuthenticationResult authenticateConsoleAccess(Console
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());
} 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 @@ public static void startWithContext(Properties conf, Object context, byte[] ksBi
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