Skip to content

Commit 96412e3

Browse files
author
Ian Duffy
committed
Allow for length of password on VMs to be set via global settings
1 parent 2498f65 commit 96412e3

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

‎server/src/com/cloud/server/ManagementServerImpl.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,8 @@ protected Map<String, String> getConfigs() {
894894

895895
@Override
896896
public String generateRandomPassword() {
897-
return PasswordGenerator.generateRandomPassword(6);
897+
Integer passwordLength = Integer.parseInt(_configDao.getValue("vm.password.length"));
898+
return PasswordGenerator.generateRandomPassword(passwordLength);
898899
}
899900

900901
@Override

‎server/src/com/cloud/vm/UserVmManagerImpl.java‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import javax.inject.Inject;
3636
import javax.naming.ConfigurationException;
3737

38+
import com.cloud.server.ManagementService;
3839
import org.apache.commons.codec.binary.Base64;
3940
import org.apache.log4j.Logger;
4041

@@ -457,6 +458,8 @@ public enum UserVmCloneType {
457458
VolumeApiService _volumeService;
458459
@Inject
459460
DataStoreManager _dataStoreMgr;
461+
@Inject
462+
ManagementService _mgr;
460463

461464
protected ScheduledExecutorService _executor = null;
462465
protected int _expungeInterval;
@@ -642,7 +645,7 @@ public UserVm resetVMSSHKey(ResetVMSSHKeyCmd cmd) throws ResourceUnavailableExce
642645
String password = null;
643646
String sshPublicKey = s.getPublicKey();
644647
if (template != null && template.getEnablePassword()) {
645-
password = generateRandomPassword();
648+
password = _mgr.generateRandomPassword();
646649
}
647650

648651
boolean result = resetVMSSHKeyInternal(vmId, sshPublicKey, password);
@@ -3353,10 +3356,6 @@ public void finalizeStop(VirtualMachineProfile profile, Answer answer) {
33533356
}
33543357
}
33553358

3356-
public String generateRandomPassword() {
3357-
return PasswordGenerator.generateRandomPassword(6);
3358-
}
3359-
33603359
@Override
33613360
public Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> startVirtualMachine(long vmId, Long hostId, Map<VirtualMachineProfile.Param, Object> additionalParams, String deploymentPlannerToUse)
33623361
throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
@@ -3431,7 +3430,7 @@ public Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> startVirtualMach
34313430

34323431
String password = "saved_password";
34333432
if (template.getEnablePassword()) {
3434-
password = generateRandomPassword();
3433+
password = _mgr.generateRandomPassword();
34353434
}
34363435

34373436
if (!validPassword(password)) {
@@ -4705,7 +4704,7 @@ public UserVm restoreVMInternal(Account caller, UserVmVO vm, Long newTemplateId)
47054704
}
47064705

47074706
if (template.getEnablePassword()) {
4708-
String password = generateRandomPassword();
4707+
String password = _mgr.generateRandomPassword();
47094708
boolean result = resetVMPasswordInternal(vmId, password);
47104709
if (result) {
47114710
vm.setPassword(password);

‎setup/db/db/schema-430to440.sql‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2451,3 +2451,4 @@ CREATE TABLE `cloud`.`snapshot_policy_details` (
24512451
CONSTRAINT `fk_snapshot_policy_details__snapshot_policy_id` FOREIGN KEY `fk_snapshot_policy_details__snapshot_policy_id`(`policy_id`) REFERENCES `snapshot_policy`(`id`) ON DELETE CASCADE
24522452
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
24532453

2454+
INSERT INTO `cloud`.`configuration`(category, instance, component, name, value, description, default_value) VALUES ('Secure', 'DEFAULT', 'management-server', 'vm.password.length', '6', 'Specifies the length of a randomly generated password', '6') ON DUPLICATE KEY UPDATE category='Secure';

0 commit comments

Comments
 (0)