Skip to content

Commit 8c0bb2b

Browse files
persist IP address that has accessed the CPVM console
1 parent 501d8c1 commit 8c0bb2b

File tree

9 files changed

+45
-13
lines changed

9 files changed

+45
-13
lines changed

agent/src/main/java/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,8 @@ protected void runInContext() {
397397
}
398398

399399
public String authenticateConsoleAccess(String host, String port, String vmId, String sid, String ticket,
400-
Boolean isReauthentication, String sessionToken) {
401-
402-
ConsoleAccessAuthenticationCommand cmd = new ConsoleAccessAuthenticationCommand(host, port, vmId, sid, ticket, sessionToken);
400+
Boolean isReauthentication, String sessionToken, String clientAddress) {
401+
ConsoleAccessAuthenticationCommand cmd = new ConsoleAccessAuthenticationCommand(host, port, vmId, sid, ticket, sessionToken, clientAddress);
403402
cmd.setReauthenticating(isReauthentication);
404403

405404
ConsoleProxyAuthenticationResult result = new ConsoleProxyAuthenticationResult();

api/src/main/java/org/apache/cloudstack/consoleproxy/ConsoleAccessManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public interface ConsoleAccessManager extends Manager, Configurable {
4444

4545
void removeSessions(String[] sessionUuids);
4646

47-
void acquireSession(String sessionUuid);
47+
void acquireSession(String sessionUuid, String clientAddress);
4848

4949
String genAccessTicket(String host, String port, String sid, String tag, String sessionUuid);
5050
String genAccessTicket(String host, String port, String sid, String tag, Date normalizedHashTime, String sessionUuid);

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class ConsoleAccessAuthenticationCommand extends AgentControlCommand {
2727
private String _sid;
2828
private String _ticket;
2929
private String sessionUuid;
30+
private String clientAddress;
3031

3132
private boolean _isReauthenticating;
3233

@@ -35,13 +36,14 @@ public ConsoleAccessAuthenticationCommand() {
3536
}
3637

3738
public ConsoleAccessAuthenticationCommand(String host, String port, String vmId, String sid, String ticket,
38-
String sessiontkn) {
39+
String sessiontkn, String clientAddress) {
3940
_host = host;
4041
_port = port;
4142
_vmId = vmId;
4243
_sid = sid;
4344
_ticket = ticket;
4445
sessionUuid = sessiontkn;
46+
this.clientAddress = clientAddress;
4547
}
4648

4749
public String getHost() {
@@ -79,4 +81,12 @@ public String getSessionUuid() {
7981
public void setSessionUuid(String sessionUuid) {
8082
this.sessionUuid = sessionUuid;
8183
}
84+
85+
public String getClientAddress() {
86+
return clientAddress;
87+
}
88+
89+
public void setClientAddress(String clientAddress) {
90+
this.clientAddress = clientAddress;
91+
}
8292
}

engine/schema/src/main/java/com/cloud/vm/ConsoleSessionVO.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ public class ConsoleSessionVO {
6464
@Column(name = "removed")
6565
private Date removed;
6666

67+
@Column(name = "console_endpoint_creator_address")
68+
private String consoleEndpointCreatorAddress;
69+
70+
@Column(name = "client_address")
71+
private String clientAddress;
72+
6773
public long getId() {
6874
return id;
6975
}
@@ -135,4 +141,20 @@ public Date getAcquired() {
135141
public void setAcquired(Date acquired) {
136142
this.acquired = acquired;
137143
}
144+
145+
public String getConsoleEndpointCreatorAddress() {
146+
return consoleEndpointCreatorAddress;
147+
}
148+
149+
public void setConsoleEndpointCreatorAddress(String consoleEndpointCreatorAddress) {
150+
this.consoleEndpointCreatorAddress = consoleEndpointCreatorAddress;
151+
}
152+
153+
public String getClientAddress() {
154+
return clientAddress;
155+
}
156+
157+
public void setClientAddress(String clientAddress) {
158+
this.clientAddress = clientAddress;
159+
}
138160
}

engine/schema/src/main/java/com/cloud/vm/dao/ConsoleSessionDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public interface ConsoleSessionDao extends GenericDao<ConsoleSessionVO, Long> {
3333

3434
int expungeSessionsOlderThanDate(Date date);
3535

36-
void acquireSession(String sessionUuid);
36+
void acquireSession(String sessionUuid, String clientAddress);
3737

3838
int expungeByVmList(List<Long> vmIds, Long batchSize);
3939
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ public int expungeSessionsOlderThanDate(Date date) {
6262
}
6363

6464
@Override
65-
public void acquireSession(String sessionUuid) {
65+
public void acquireSession(String sessionUuid, String clientAddress) {
6666
ConsoleSessionVO consoleSessionVO = findByUuid(sessionUuid);
6767
consoleSessionVO.setAcquired(new Date());
68+
consoleSessionVO.setClientAddress(clientAddress);
6869
update(consoleSessionVO.getId(), consoleSessionVO);
6970
}
7071

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public AgentControlAnswer onConsoleAccessAuthentication(ConsoleAccessAuthenticat
8989

9090
String ticketInUrl = cmd.getTicket();
9191
String sessionUuid = cmd.getSessionUuid();
92+
String clientAddress = cmd.getClientAddress();
9293

9394
if (ticketInUrl == null) {
9495
logger.error("Access ticket could not be found, you could be running an old version of console proxy. vmId: " + cmd.getVmId());
@@ -111,7 +112,7 @@ public AgentControlAnswer onConsoleAccessAuthentication(ConsoleAccessAuthenticat
111112
}
112113

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

116117
if (!ticket.equals(ticketInUrl)) {
117118
Date now = new Date();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ protected void removeSession(String sessionUuid) {
248248
}
249249

250250
@Override
251-
public void acquireSession(String sessionUuid) {
252-
consoleSessionDao.acquireSession(sessionUuid);
251+
public void acquireSession(String sessionUuid, String clientAddress) {
252+
consoleSessionDao.acquireSession(sessionUuid, clientAddress);
253253
}
254254

255255
protected boolean checkSessionPermission(VirtualMachine vm, Account account) {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ public static ConsoleProxyServerFactory getHttpServerFactory() {
183183
}
184184

185185
public static ConsoleProxyAuthenticationResult authenticateConsoleAccess(ConsoleProxyClientParam param, boolean reauthentication) {
186-
187186
ConsoleProxyAuthenticationResult authResult = new ConsoleProxyAuthenticationResult();
188187
authResult.setSuccess(true);
189188
authResult.setReauthentication(reauthentication);
@@ -227,7 +226,7 @@ public static ConsoleProxyAuthenticationResult authenticateConsoleAccess(Console
227226
try {
228227
result =
229228
authMethod.invoke(ConsoleProxy.context, param.getClientHostAddress(), String.valueOf(param.getClientHostPort()), param.getClientTag(),
230-
param.getClientHostPassword(), param.getTicket(), reauthentication, param.getSessionUuid());
229+
param.getClientHostPassword(), param.getTicket(), reauthentication, param.getSessionUuid(), param.getClientIp());
231230
} catch (IllegalAccessException e) {
232231
LOGGER.error("Unable to invoke authenticateConsoleAccess due to IllegalAccessException" + " for vm: " + param.getClientTag(), e);
233232
authResult.setSuccess(false);
@@ -301,7 +300,7 @@ public static void startWithContext(Properties conf, Object context, byte[] ksBi
301300
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
302301
Class<?> contextClazz = loader.loadClass("com.cloud.agent.resource.consoleproxy.ConsoleProxyResource");
303302
authMethod = contextClazz.getDeclaredMethod("authenticateConsoleAccess", String.class, String.class,
304-
String.class, String.class, String.class, Boolean.class, String.class);
303+
String.class, String.class, String.class, Boolean.class, String.class, String.class);
305304
reportMethod = contextClazz.getDeclaredMethod("reportLoadInfo", String.class);
306305
ensureRouteMethod = contextClazz.getDeclaredMethod("ensureRoute", String.class);
307306
} catch (SecurityException e) {

0 commit comments

Comments
 (0)