Skip to content

Commit 205ebfb

Browse files
committed
Merge release branch 4.20 to main
* 4.20: UI: Fix userdata and load balancer selection (#10016) Prevent password updates for SAML and LDAP users (#9999) cloudstack-migrate-databases: sql AND added (#10033) engine/schema: move SQLs to 4.20.0 to 4.20.1 upgrade (#10018) Remove user from project before deletion (#10008) Simplify validation for creating volume templates via UI (#9828)
2 parents 4ac4d9c + 9960e40 commit 205ebfb

File tree

15 files changed

+189
-24
lines changed

15 files changed

+189
-24
lines changed

api/src/main/java/org/apache/cloudstack/api/command/admin/management/ListMgmtsCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class ListMgmtsCmd extends BaseListCmd {
4242

4343
@Parameter(name = ApiConstants.PEERS, type = CommandType.BOOLEAN,
4444
description = "Whether to return the management server peers or not. By default, the management server peers will not be returned.",
45-
since = "4.20.0.0")
45+
since = "4.20.1.0")
4646
private Boolean peers;
4747

4848
/////////////////////////////////////////////////////

engine/schema/src/main/java/com/cloud/projects/dao/ProjectAccountDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public interface ProjectAccountDao extends GenericDao<ProjectAccountVO, Long> {
4747

4848
void removeAccountFromProjects(long accountId);
4949

50+
void removeUserFromProjects(long userId);
51+
5052
boolean canUserModifyProject(long projectId, long accountId, long userId);
5153

5254
List<ProjectAccountVO> listUsersOrAccountsByRole(long id);

engine/schema/src/main/java/com/cloud/projects/dao/ProjectAccountDaoImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,17 @@ public void removeAccountFromProjects(long accountId) {
192192
}
193193
}
194194

195+
@Override
196+
public void removeUserFromProjects(long userId) {
197+
SearchCriteria<ProjectAccountVO> sc = AllFieldsSearch.create();
198+
sc.setParameters("userId", userId);
199+
200+
int removedCount = remove(sc);
201+
if (removedCount > 0) {
202+
logger.debug(String.format("Removed user [%s] from %s project(s).", userId, removedCount));
203+
}
204+
}
205+
195206
@Override
196207
public boolean canUserModifyProject(long projectId, long accountId, long userId) {
197208
SearchCriteria<ProjectAccountVO> sc = AllFieldsSearch.create();
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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.utils.exception.CloudRuntimeException;
20+
21+
import java.io.InputStream;
22+
import java.sql.Connection;
23+
24+
public class Upgrade41910to41920 implements DbUpgrade {
25+
26+
@Override
27+
public String[] getUpgradableVersionRange() {
28+
return new String[]{"4.19.1.0", "4.19.2.0"};
29+
}
30+
31+
@Override
32+
public String getUpgradedVersion() {
33+
return "4.19.2.0";
34+
}
35+
36+
@Override
37+
public boolean supportsRollingUpgrade() {
38+
return false;
39+
}
40+
41+
@Override
42+
public InputStream[] getPrepareScripts() {
43+
final String scriptFile = "META-INF/db/schema-41910to41920.sql";
44+
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
45+
if (script == null) {
46+
throw new CloudRuntimeException("Unable to find " + scriptFile);
47+
}
48+
49+
return new InputStream[]{script};
50+
}
51+
52+
@Override
53+
public void performDataMigration(Connection conn) {
54+
}
55+
56+
@Override
57+
public InputStream[] getCleanupScripts() {
58+
final String scriptFile = "META-INF/db/schema-41910to41920-cleanup.sql";
59+
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
60+
if (script == null) {
61+
throw new CloudRuntimeException("Unable to find " + scriptFile);
62+
}
63+
64+
return new InputStream[]{script};
65+
}
66+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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.19.1.0 to 4.19.2.0
20+
--;
21+
22+
-- Delete `project_account` entries for users that were removed
23+
DELETE FROM `cloud`.`project_account` WHERE `user_id` IN (SELECT `id` FROM `cloud`.`user` WHERE `removed`);
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 from 4.19.1.0 to 4.19.2.0
20+
--;

engine/schema/src/main/resources/META-INF/db/schema-41910to42000.sql

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -425,10 +425,3 @@ INSERT IGNORE INTO `cloud`.`guest_os_hypervisor` (uuid, hypervisor_type, hypervi
425425

426426
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.vm_instance', 'delete_protection', 'boolean DEFAULT FALSE COMMENT "delete protection for vm" ');
427427
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.volumes', 'delete_protection', 'boolean DEFAULT FALSE COMMENT "delete protection for volumes" ');
428-
429-
-- Modify index for mshost_peer
430-
DELETE FROM `cloud`.`mshost_peer`;
431-
CALL `cloud`.`IDEMPOTENT_DROP_FOREIGN_KEY`('cloud.mshost_peer','fk_mshost_peer__owner_mshost');
432-
CALL `cloud`.`IDEMPOTENT_DROP_INDEX`('i_mshost_peer__owner_peer_runid','mshost_peer');
433-
CALL `cloud`.`IDEMPOTENT_ADD_UNIQUE_KEY`('cloud.mshost_peer', 'i_mshost_peer__owner_peer', '(owner_mshost, peer_mshost)');
434-
CALL `cloud`.`IDEMPOTENT_ADD_FOREIGN_KEY`('cloud.mshost_peer', 'fk_mshost_peer__owner_mshost', '(owner_mshost)', '`mshost`(`id`)');

engine/schema/src/main/resources/META-INF/db/schema-42000to42010.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,10 @@
2222
-- Add column api_key_access to user and account tables
2323
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.user', 'api_key_access', 'boolean DEFAULT NULL COMMENT "is api key access allowed for the user" AFTER `secret_key`');
2424
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.account', 'api_key_access', 'boolean DEFAULT NULL COMMENT "is api key access allowed for the account" ');
25+
26+
-- Modify index for mshost_peer
27+
DELETE FROM `cloud`.`mshost_peer`;
28+
CALL `cloud`.`IDEMPOTENT_DROP_FOREIGN_KEY`('cloud.mshost_peer','fk_mshost_peer__owner_mshost');
29+
CALL `cloud`.`IDEMPOTENT_DROP_INDEX`('i_mshost_peer__owner_peer_runid','mshost_peer');
30+
CALL `cloud`.`IDEMPOTENT_ADD_UNIQUE_KEY`('cloud.mshost_peer', 'i_mshost_peer__owner_peer', '(owner_mshost, peer_mshost)');
31+
CALL `cloud`.`IDEMPOTENT_ADD_FOREIGN_KEY`('cloud.mshost_peer', 'fk_mshost_peer__owner_mshost', '(owner_mshost)', '`mshost`(`id`)');

framework/db/src/main/java/com/cloud/utils/crypt/EncryptionSecretKeyChanger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ private void migrateTemplateDeployAsIsDetails(Connection conn) throws SQLExcepti
656656
String sqlTemplateDeployAsIsDetails = "SELECT template_deploy_as_is_details.value " +
657657
"FROM template_deploy_as_is_details JOIN vm_instance " +
658658
"WHERE template_deploy_as_is_details.template_id = vm_instance.vm_template_id " +
659-
"vm_instance.id = %s AND template_deploy_as_is_details.name = '%s' LIMIT 1";
659+
"AND vm_instance.id = %s AND template_deploy_as_is_details.name = '%s' LIMIT 1";
660660
try (PreparedStatement selectPstmt = conn.prepareStatement("SELECT id, vm_id, name, value FROM user_vm_deploy_as_is_details");
661661
ResultSet rs = selectPstmt.executeQuery();
662662
PreparedStatement updatePstmt = conn.prepareStatement("UPDATE user_vm_deploy_as_is_details SET value=? WHERE id=?")

server/src/main/java/com/cloud/user/AccountManagerImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,6 +1500,8 @@ public UserAccount updateUser(UpdateUserCmd updateUserCmd) {
15001500
* <ul>
15011501
* <li> If 'password' is blank, we throw an {@link InvalidParameterValueException};
15021502
* <li> If 'current password' is not provided and user is not an Admin, we throw an {@link InvalidParameterValueException};
1503+
* <li> If the user whose password is being changed has a source equal to {@link User.Source#SAML2}, {@link User.Source#SAML2DISABLED} or {@link User.Source#LDAP},
1504+
* we throw an {@link InvalidParameterValueException};
15031505
* <li> If a normal user is calling this method, we use {@link #validateCurrentPassword(UserVO, String)} to check if the provided old password matches the database one;
15041506
* </ul>
15051507
*
@@ -1514,6 +1516,12 @@ public void validateUserPasswordAndUpdateIfNeeded(String newPassword, UserVO use
15141516
throw new InvalidParameterValueException("Password cannot be empty or blank.");
15151517
}
15161518

1519+
User.Source userSource = user.getSource();
1520+
if (userSource == User.Source.SAML2 || userSource == User.Source.SAML2DISABLED || userSource == User.Source.LDAP) {
1521+
logger.warn(String.format("Unable to update the password for user [%d], as its source is [%s].", user.getId(), user.getSource().toString()));
1522+
throw new InvalidParameterValueException("CloudStack does not support updating passwords for SAML or LDAP users. Please contact your cloud administrator for assistance.");
1523+
}
1524+
15171525
passwordPolicy.verifyIfPasswordCompliesWithPasswordPolicies(newPassword, user.getUsername(), getAccount(user.getAccountId()).getDomainId());
15181526

15191527
Account callingAccount = getCurrentCallingAccount();

0 commit comments

Comments
 (0)