Skip to content

Commit a65c36a

Browse files
Kishan KavalaChip Childers
authored andcommitted
CLOUDSTACK-528: Config value has to be encrypted for Hidden category configs
1 parent 7f8b477 commit a65c36a

2 files changed

Lines changed: 41 additions & 3 deletions

File tree

‎server/src/com/cloud/upgrade/dao/Upgrade302to40.java‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.cloud.upgrade.dao;
1919

2020
import java.io.File;
21+
import java.io.UnsupportedEncodingException;
2122
import java.sql.Connection;
2223
import java.sql.PreparedStatement;
2324
import java.sql.ResultSet;
@@ -72,6 +73,7 @@ public void performDataMigration(Connection conn) {
7273
fixForeignKeys(conn);
7374
setupExternalNetworkDevices(conn);
7475
fixZoneUsingExternalDevices(conn);
76+
encryptConfig(conn);
7577
}
7678

7779
@Override
@@ -1079,4 +1081,43 @@ private void fixZoneUsingExternalDevices(Connection conn) {
10791081
s_logger.info("Successfully upgraded networks using F5 and SRX devices to have a entry in the network_external_lb_device_map and network_external_firewall_device_map");
10801082
}
10811083
}
1084+
1085+
private void encryptConfig(Connection conn){
1086+
//Encrypt config params and change category to Hidden
1087+
s_logger.debug("Encrypting Config values");
1088+
PreparedStatement pstmt = null;
1089+
ResultSet rs = null;
1090+
try {
1091+
pstmt = conn.prepareStatement("select name, value from `cloud`.`configuration` where name in ('router.ram.size', 'secondary.storage.vm', 'security.hash.key') and category <> 'Hidden'");
1092+
rs = pstmt.executeQuery();
1093+
while (rs.next()) {
1094+
String name = rs.getString(1);
1095+
String value = rs.getString(2);
1096+
if (value == null) {
1097+
continue;
1098+
}
1099+
String encryptedValue = DBEncryptionUtil.encrypt(value);
1100+
pstmt = conn.prepareStatement("update `cloud`.`configuration` set value=?, category = 'Hidden' where name=?");
1101+
pstmt.setBytes(1, encryptedValue.getBytes("UTF-8"));
1102+
pstmt.setString(2, name);
1103+
pstmt.executeUpdate();
1104+
}
1105+
} catch (SQLException e) {
1106+
throw new CloudRuntimeException("Unable encrypt configuration values ", e);
1107+
} catch (UnsupportedEncodingException e) {
1108+
throw new CloudRuntimeException("Unable encrypt configuration values ", e);
1109+
} finally {
1110+
try {
1111+
if (rs != null) {
1112+
rs.close();
1113+
}
1114+
1115+
if (pstmt != null) {
1116+
pstmt.close();
1117+
}
1118+
} catch (SQLException e) {
1119+
}
1120+
}
1121+
s_logger.debug("Done encrypting Config values");
1122+
}
10821123
}

‎setup/db/db/schema-302to40.sql‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,6 @@ UPDATE `cloud`.`configuration` set component='NetworkManager' where name='router
114114
UPDATE `cloud`.`configuration` set component='NetworkManager' where name='router.template.id';
115115
UPDATE `cloud`.`configuration` set category='Advanced' where name='capacity.skipcounting.hours';
116116
UPDATE `cloud`.`configuration` set category='Advanced' where name='use.local.storage';
117-
UPDATE `cloud`.`configuration` set category='Hidden' where name='router.ram.size';
118-
UPDATE `cloud`.`configuration` set category='Hidden' where name='secondary.storage.vm';
119-
UPDATE `cloud`.`configuration` set category='Hidden' where name='security.hash.key';
120117
UPDATE `cloud`.`configuration` set description = 'Percentage (as a value between 0 and 1) of local storage utilization above which alerts will be sent about low local storage available.' where name = 'cluster.localStorage.capacity.notificationthreshold';
121118

122119
DELETE FROM `cloud`.`configuration` WHERE name='direct.agent.pool.size';

0 commit comments

Comments
 (0)