Skip to content
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

Persist IP addresses related to VM access via CPVM #9534

Open
wants to merge 3 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 @@ -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
}
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
Expand Up @@ -623,3 +623,9 @@ INSERT IGNORE INTO `cloud`.`guest_os_hypervisor` (uuid, hypervisor_type, hypervi

CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.vm_instance', 'delete_protection', 'boolean DEFAULT FALSE COMMENT "delete protection for vm" ');
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.volumes', 'delete_protection', 'boolean DEFAULT FALSE COMMENT "delete protection for volumes" ');

-- 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