Skip to content

Commit f75a194

Browse files
Persist IP addresses related to VM access via CPVM (#9534)
1 parent c94d0ab commit f75a194

File tree

13 files changed

+179
-15
lines changed

13 files changed

+179
-15
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/upgrade/DatabaseUpgradeChecker.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
import com.cloud.upgrade.dao.Upgrade41900to41910;
9090
import com.cloud.upgrade.dao.Upgrade41910to42000;
9191
import com.cloud.upgrade.dao.Upgrade42000to42010;
92+
import com.cloud.upgrade.dao.Upgrade42010to42100;
9293
import com.cloud.upgrade.dao.Upgrade420to421;
9394
import com.cloud.upgrade.dao.Upgrade421to430;
9495
import com.cloud.upgrade.dao.Upgrade430to440;
@@ -232,6 +233,7 @@ public DatabaseUpgradeChecker() {
232233
.next("4.19.0.0", new Upgrade41900to41910())
233234
.next("4.19.1.0", new Upgrade41910to42000())
234235
.next("4.20.0.0", new Upgrade42000to42010())
236+
.next("4.20.1.0", new Upgrade42010to42100())
235237
.build();
236238
}
237239

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.upgrade.dao;
18+
19+
import com.cloud.upgrade.SystemVmTemplateRegistration;
20+
import com.cloud.utils.exception.CloudRuntimeException;
21+
22+
import java.io.InputStream;
23+
import java.sql.Connection;
24+
25+
public class Upgrade42010to42100 extends DbUpgradeAbstractImpl implements DbUpgrade, DbUpgradeSystemVmTemplate {
26+
private SystemVmTemplateRegistration systemVmTemplateRegistration;
27+
28+
@Override
29+
public String[] getUpgradableVersionRange() {
30+
return new String[] {"4.20.1.0", "4.21.0.0"};
31+
}
32+
33+
@Override
34+
public String getUpgradedVersion() {
35+
return "4.21.0.0";
36+
}
37+
38+
@Override
39+
public boolean supportsRollingUpgrade() {
40+
return false;
41+
}
42+
43+
@Override
44+
public InputStream[] getPrepareScripts() {
45+
final String scriptFile = "META-INF/db/schema-42010to42100.sql";
46+
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
47+
if (script == null) {
48+
throw new CloudRuntimeException("Unable to find " + scriptFile);
49+
}
50+
51+
return new InputStream[] {script};
52+
}
53+
54+
@Override
55+
public void performDataMigration(Connection conn) {
56+
}
57+
58+
@Override
59+
public InputStream[] getCleanupScripts() {
60+
final String scriptFile = "META-INF/db/schema-42010to42100-cleanup.sql";
61+
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
62+
if (script == null) {
63+
throw new CloudRuntimeException("Unable to find " + scriptFile);
64+
}
65+
66+
return new InputStream[] {script};
67+
}
68+
69+
private void initSystemVmTemplateRegistration() {
70+
systemVmTemplateRegistration = new SystemVmTemplateRegistration("");
71+
}
72+
73+
@Override
74+
public void updateSystemVmTemplates(Connection conn) {
75+
logger.debug("Updating System Vm template IDs");
76+
initSystemVmTemplateRegistration();
77+
try {
78+
systemVmTemplateRegistration.updateSystemVmTemplates(conn);
79+
} catch (Exception e) {
80+
throw new CloudRuntimeException("Failed to find / register SystemVM template(s)");
81+
}
82+
}
83+
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with the License. You may obtain a copy of the License at
8+
--
9+
-- http://www.apache.org/licenses/LICENSE-2.0
10+
--
11+
-- Unless required by applicable law or agreed to in writing,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
--;
19+
-- Schema upgrade cleanup from 4.20.1.0 to 4.21.0.0
20+
--;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with the License. You may obtain a copy of the License at
8+
--
9+
-- http://www.apache.org/licenses/LICENSE-2.0
10+
--
11+
-- Unless required by applicable law or agreed to in writing,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
--;
19+
-- Schema upgrade from 4.20.1.0 to 4.21.0.0
20+
--;
21+
22+
-- Add console_endpoint_creator_address column to cloud.console_session table
23+
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.console_session', 'console_endpoint_creator_address', 'VARCHAR(45)');
24+
25+
-- Add client_address column to cloud.console_session table
26+
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.console_session', 'client_address', 'VARCHAR(45)');

0 commit comments

Comments
 (0)