-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Handle console session in multiple management servers #7094
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
Changes from 3 commits
11e445e
eb58bf8
8670fd1
dec6e3f
9225163
9e66078
d0293c4
6173aa0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // | ||
| // 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.vm; | ||
|
|
||
| import javax.persistence.Column; | ||
| import javax.persistence.Entity; | ||
| import javax.persistence.GeneratedValue; | ||
| import javax.persistence.GenerationType; | ||
| import javax.persistence.Id; | ||
| import javax.persistence.Table; | ||
|
|
||
| @Entity | ||
| @Table(name = "allowed_console_session") | ||
| public class AllowedConsoleSessionVo { | ||
GutoVeronezi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @Column(name = "id") | ||
| private long id; | ||
|
|
||
| @Column(name = "session_uuid") | ||
| private String sessionUuid; | ||
|
|
||
| public AllowedConsoleSessionVo() { | ||
| } | ||
|
|
||
| public AllowedConsoleSessionVo(String sessionUuid) { | ||
| this.sessionUuid = sessionUuid; | ||
| } | ||
|
|
||
| public long getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public void setId(long id) { | ||
| this.id = id; | ||
| } | ||
|
|
||
| public String getSessionUuid() { | ||
| return sessionUuid; | ||
| } | ||
|
|
||
| public void setSessionUuid(String sessionUuid) { | ||
| this.sessionUuid = sessionUuid; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // | ||
| // 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.vm.dao; | ||
|
|
||
| import com.cloud.vm.AllowedConsoleSessionVo; | ||
| import com.cloud.utils.db.GenericDao; | ||
|
|
||
| public interface AllowedConsoleSessionDao extends GenericDao<AllowedConsoleSessionVo, Long> { | ||
|
|
||
| void expungeBySessionUuids(Object[] sessionUuid); | ||
|
|
||
| boolean isSessionUuidAllowed(String sessionUuid); | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // | ||
| // 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.vm.dao; | ||
|
|
||
| import com.cloud.vm.AllowedConsoleSessionVo; | ||
| import com.cloud.utils.db.GenericDaoBase; | ||
| import com.cloud.utils.db.SearchBuilder; | ||
| import com.cloud.utils.db.SearchCriteria; | ||
|
|
||
| public class AllowedConsoleSessionDaoImpl extends GenericDaoBase<AllowedConsoleSessionVo, Long> implements AllowedConsoleSessionDao { | ||
|
|
||
| private final SearchBuilder<AllowedConsoleSessionVo> searchBySessionUuids; | ||
|
|
||
| protected AllowedConsoleSessionDaoImpl() { | ||
| searchBySessionUuids = createSearchBuilder(); | ||
| searchBySessionUuids.and("sessions", searchBySessionUuids.entity().getSessionUuid(), SearchCriteria.Op.IN); | ||
| searchBySessionUuids.done(); | ||
| } | ||
|
|
||
| @Override | ||
| public void expungeBySessionUuids(Object[] sessionsUuids) { | ||
| expunge(getSearchCriteriaBySessionUuids(sessionsUuids)); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isSessionUuidAllowed(String sessionUuid) { | ||
| return findOneBy(getSearchCriteriaBySessionUuids(new String[]{sessionUuid})) != null; | ||
| } | ||
|
|
||
| private SearchCriteria<AllowedConsoleSessionVo> getSearchCriteriaBySessionUuids(Object[] sessionsUuids) { | ||
| SearchCriteria<AllowedConsoleSessionVo> sc = searchBySessionUuids.create(); | ||
| sc.setParameters("sessions", sessionsUuids); | ||
| return sc; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,17 +38,20 @@ | |
| import com.cloud.utils.component.ManagerBase; | ||
| import com.cloud.utils.db.EntityManager; | ||
| import com.cloud.utils.exception.CloudRuntimeException; | ||
| import com.cloud.vm.AllowedConsoleSessionVo; | ||
| import com.cloud.vm.UserVmDetailVO; | ||
| import com.cloud.vm.VirtualMachine; | ||
| import com.cloud.vm.VirtualMachineManager; | ||
| import com.cloud.vm.VmDetailConstants; | ||
| import com.cloud.vm.dao.AllowedConsoleSessionDao; | ||
| import com.cloud.vm.dao.UserVmDetailsDao; | ||
| import com.google.gson.Gson; | ||
| import com.google.gson.GsonBuilder; | ||
| import org.apache.cloudstack.api.command.user.consoleproxy.ConsoleEndpoint; | ||
| import org.apache.cloudstack.context.CallContext; | ||
| import org.apache.cloudstack.framework.security.keys.KeysManager; | ||
| import org.apache.commons.codec.binary.Base64; | ||
| import org.apache.commons.lang3.ArrayUtils; | ||
| import org.apache.commons.lang3.ObjectUtils; | ||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.apache.log4j.Logger; | ||
|
|
@@ -84,6 +87,8 @@ public class ConsoleAccessManagerImpl extends ManagerBase implements ConsoleAcce | |
| private AgentManager agentManager; | ||
| @Inject | ||
| private ConsoleProxyManager consoleProxyManager; | ||
| @Inject | ||
| private AllowedConsoleSessionDao allowedConsoleSessionDao; | ||
|
|
||
| private static KeysManager secretKeysManager; | ||
| private final Gson gson = new GsonBuilder().create(); | ||
|
|
@@ -151,11 +156,16 @@ public boolean isSessionAllowed(String sessionUuid) { | |
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @GutoVeronezi the problem listed previously for one mgmt server comes from the method
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| @Override | ||
| public void removeSessions(String[] sessionUuids) { | ||
| for (String r : sessionUuids) { | ||
| allowedSessions.remove(r); | ||
| if (ArrayUtils.isNotEmpty(sessionUuids)) { | ||
| allowedConsoleSessionDao.expungeBySessionUuids(sessionUuids); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void removeSession(String sessionUuid) { | ||
| removeSessions(new String[] {sessionUuid}); | ||
| } | ||
|
|
||
| protected boolean checkSessionPermission(VirtualMachine vm, Account account) { | ||
| if (accountManager.isRootAdmin(account.getId())) { | ||
| return true; | ||
|
|
@@ -289,7 +299,7 @@ private ConsoleEndpoint composeConsoleAccessEndpoint(String rootUrl, VirtualMach | |
| String url = generateConsoleAccessUrl(rootUrl, param, token, vncPort, vm); | ||
|
|
||
| s_logger.debug("Adding allowed session: " + sessionUuid); | ||
| allowedSessions.add(sessionUuid); | ||
| allowedConsoleSessionDao.persist(new AllowedConsoleSessionVo(sessionUuid)); | ||
| managementServer.setConsoleAccessForVm(vm.getId(), sessionUuid); | ||
|
|
||
| ConsoleEndpoint consoleEndpoint = new ConsoleEndpoint(true, url); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.