Skip to content

Commit a2ed3fa

Browse files
author
kishan
committed
bug 12337: encrypt Hidden category config values only
reviewed-by: Abhi
1 parent 3e5e36e commit a2ed3fa

6 files changed

Lines changed: 39 additions & 18 deletions

File tree

‎server/src/com/cloud/configuration/ConfigurationManager.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public interface ConfigurationManager extends ConfigurationService, Manager {
5959
* @param name
6060
* @param value
6161
*/
62-
void updateConfiguration(long userId, String name, String value);
62+
void updateConfiguration(long userId, String name, String category, String value);
6363

6464
/**
6565
* Creates a new service offering

‎server/src/com/cloud/configuration/ConfigurationManagerImpl.java‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ public boolean start() {
299299
s_logger.warn("Management network CIDR is not configured originally. Set it default to " + localCidrs[0]);
300300

301301
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_MANAGMENT_NODE, 0, new Long(0), "Management network CIDR is not configured originally. Set it default to " + localCidrs[0], "");
302-
_configDao.update(Config.ManagementNetwork.key(), localCidrs[0]);
302+
_configDao.update(Config.ManagementNetwork.key(), Config.ManagementNetwork.getCategory(), localCidrs[0]);
303303
} else {
304304
s_logger.warn("Management network CIDR is not properly configured and we are not able to find a default setting");
305305
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_MANAGMENT_NODE, 0, new Long(0), "Management network CIDR is not properly configured and we are not able to find a default setting", "");
@@ -316,7 +316,7 @@ public boolean stop() {
316316

317317
@Override
318318
@DB
319-
public void updateConfiguration(long userId, String name, String value) {
319+
public void updateConfiguration(long userId, String name, String category, String value) {
320320
if (value != null && (value.trim().isEmpty() || value.equals("null"))) {
321321
value = null;
322322
}
@@ -332,7 +332,7 @@ public void updateConfiguration(long userId, String name, String value) {
332332
Transaction txn = Transaction.currentTxn();
333333
txn.start();
334334

335-
if (!_configDao.update(name, value)) {
335+
if (!_configDao.update(name, category, value)) {
336336
s_logger.error("Failed to update configuration option, name: " + name + ", value:" + value);
337337
throw new CloudRuntimeException("Failed to update configuration value. Please contact Cloud Support.");
338338
}
@@ -435,15 +435,16 @@ public Configuration updateConfiguration(UpdateCfgCmd cmd) {
435435
String value = cmd.getValue();
436436
UserContext.current().setEventDetails(" Name: " + name + " New Value: " + ((value == null) ? "" : value));
437437
// check if config value exists
438-
if (_configDao.findByName(name) == null) {
438+
ConfigurationVO config = _configDao.findByName(name);
439+
if (config == null) {
439440
throw new InvalidParameterValueException("Config parameter with name " + name + " doesn't exist");
440441
}
441442

442443
if (value == null) {
443444
return _configDao.findByName(name);
444445
}
445446

446-
updateConfiguration(userId, name, value);
447+
updateConfiguration(userId, name, config.getCategory(), value);
447448
if (_configDao.getValue(name).equalsIgnoreCase(value)) {
448449
return _configDao.findByName(name);
449450
} else {

‎server/src/com/cloud/configuration/dao/ConfigurationDao.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,6 @@ public interface ConfigurationDao extends GenericDao<ConfigurationVO, String> {
6969
boolean isPremium();
7070

7171
ConfigurationVO findByName(String name);
72+
73+
boolean update(String name, String category, String value);
7274
}

‎server/src/com/cloud/configuration/dao/ConfigurationDaoImpl.java‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
122122
return true;
123123
}
124124

125-
@Override
125+
//Use update method with category instead
126+
@Override @Deprecated
126127
public boolean update(String name, String value) {
127128
Transaction txn = Transaction.currentTxn();
128129
try {
@@ -136,6 +137,22 @@ public boolean update(String name, String value) {
136137
}
137138
return false;
138139
}
140+
141+
@Override
142+
public boolean update(String name, String category, String value) {
143+
Transaction txn = Transaction.currentTxn();
144+
try {
145+
value = "Hidden".equals(category) ? DBEncryptionUtil.encrypt(value) : value;
146+
PreparedStatement stmt = txn.prepareStatement(UPDATE_CONFIGURATION_SQL);
147+
stmt.setString(1, value);
148+
stmt.setString(2, name);
149+
stmt.executeUpdate();
150+
return true;
151+
} catch (Exception e) {
152+
s_logger.warn("Unable to update Configuration Value", e);
153+
}
154+
return false;
155+
}
139156

140157
@Override
141158
public String getValue(String name) {

‎server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,8 +1069,8 @@ public void setManagementState(ConsoleProxyManagementState state) {
10691069
}
10701070

10711071
if (lastState != state) {
1072-
_configDao.update(Config.ConsoleProxyManagementLastState.key(), lastState.toString());
1073-
_configDao.update(Config.ConsoleProxyManagementState.key(), state.toString());
1072+
_configDao.update(Config.ConsoleProxyManagementLastState.key(), Config.ConsoleProxyManagementLastState.getCategory(), lastState.toString());
1073+
_configDao.update(Config.ConsoleProxyManagementState.key(), Config.ConsoleProxyManagementState.getCategory(), state.toString());
10741074
}
10751075

10761076
txn.commit();
@@ -1109,7 +1109,7 @@ public void resumeLastManagementState() {
11091109
}
11101110

11111111
if (lastState != state) {
1112-
_configDao.update(Config.ConsoleProxyManagementState.key(), lastState.toString());
1112+
_configDao.update(Config.ConsoleProxyManagementState.key(), Config.ConsoleProxyManagementState.getCategory(), lastState.toString());
11131113
}
11141114

11151115
txn.commit();

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,17 @@ public void persistDefaultValues() throws InternalErrorException {
174174
String instance = "DEFAULT";
175175
String component = c.getComponent();
176176
String value = c.getDefaultValue();
177+
value = ("Hidden".equals(category)) ? DBEncryptionUtil.encrypt(value) : value;
177178
String description = c.getDescription();
178179
ConfigurationVO configVO = new ConfigurationVO(category, instance, component, name, value, description);
179180
_configDao.persist(configVO);
180181
}
181182
}
182183

183-
_configDao.update("secondary.storage.vm", "true");
184+
_configDao.update(Config.UseSecondaryStorageVm.key(), Config.UseSecondaryStorageVm.getCategory(), "true");
184185
s_logger.debug("ConfigurationServer made secondary storage vm required.");
185186

186-
_configDao.update("secstorage.encrypt.copy", "true");
187+
_configDao.update(Config.SecStorageEncryptCopy.key(), Config.SecStorageEncryptCopy.getCategory(), "true");
187188
s_logger.debug("ConfigurationServer made secondary storage copy encrypted.");
188189

189190
_configDao.update("secstorage.secure.copy.cert", "realhostip");
@@ -201,15 +202,15 @@ public void persistDefaultValues() throws InternalErrorException {
201202
// Save the mount parent to the configuration table
202203
String mountParent = getMountParent();
203204
if (mountParent != null) {
204-
_configDao.update("mount.parent", mountParent);
205+
_configDao.update(Config.MountParent.key(), Config.MountParent.getCategory(), mountParent);
205206
s_logger.debug("ConfigurationServer saved \"" + mountParent + "\" as mount.parent.");
206207
} else {
207208
s_logger.debug("ConfigurationServer could not detect mount.parent.");
208209
}
209210

210211
String hostIpAdr = NetUtils.getDefaultHostIp();
211212
if (hostIpAdr != null) {
212-
_configDao.update("host", hostIpAdr);
213+
_configDao.update(Config.ManagementHostIPAdr.key(), Config.ManagementHostIPAdr.getCategory(), hostIpAdr);
213214
s_logger.debug("ConfigurationServer saved \"" + hostIpAdr + "\" as host.");
214215
}
215216

@@ -266,7 +267,7 @@ public void persistDefaultValues() throws InternalErrorException {
266267
updateCloudIdentifier();
267268

268269
// Set init to true
269-
_configDao.update("init", "true");
270+
_configDao.update("init", "Hidden", "true");
270271
}
271272

272273

@@ -402,7 +403,7 @@ protected void updateCloudIdentifier() {
402403
String currentCloudIdentifier = _configDao.getValue("cloud.identifier");
403404
if (currentCloudIdentifier == null || currentCloudIdentifier.isEmpty()) {
404405
String uuid = UUID.randomUUID().toString();
405-
_configDao.update("cloud.identifier", uuid);
406+
_configDao.update(Config.CloudIdentifier.key(),Config.CloudIdentifier.getCategory(), uuid);
406407
}
407408
}
408409

@@ -492,7 +493,7 @@ protected void updateSSLKeystore() {
492493
// Check if they are the same one, otherwise override with local keystore
493494
String base64Keystore = getBase64Keystore(keystorePath);
494495
if (base64Keystore.compareTo(dbString) != 0) {
495-
_configDao.update("ssl.keystore", DBEncryptionUtil.encrypt(base64Keystore));
496+
_configDao.update("ssl.keystore", "Hidden", base64Keystore);
496497
s_logger.info("Updated database keystore with local one.");
497498
}
498499
} else { // !keystoreFile.exists() and dbExisted
@@ -702,7 +703,7 @@ private void updateSSOKey() {
702703
SecretKey key = generator.generateKey();
703704
encodedKey = Base64.encodeBase64URLSafeString(key.getEncoded());
704705

705-
_configDao.update("security.singlesignon.key", encodedKey);
706+
_configDao.update(Config.SSOKey.key(), Config.SSOKey.getCategory(), encodedKey);
706707
} catch (NoSuchAlgorithmException ex) {
707708
s_logger.error("error generating sso key", ex);
708709
}

0 commit comments

Comments
 (0)