Skip to content

Commit 511ebe6

Browse files
authored
Merge pull request apache#927 from karuturi/secure-configs
CLOUDSTACK-9901 secure and hidden config values are returned as plaintext string
2 parents 3ddac36 + 6809ce4 commit 511ebe6

4 files changed

Lines changed: 22 additions & 6 deletions

File tree

framework/config/src/org/apache/cloudstack/config/Configuration.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,10 @@ public interface Configuration {
8181
* parameter is no longer used and can be deleted.
8282
*/
8383
Date getUpdated();
84+
85+
/**
86+
*
87+
* @return returns true if the configuration is encrypted else false.
88+
*/
89+
boolean isEncrypted();
8490
}

framework/config/src/org/apache/cloudstack/framework/config/impl/ConfigurationVO.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,22 +122,23 @@ public void setName(String name) {
122122

123123
@Override
124124
public String getValue() {
125-
if(isEncryptedConfig()) {
125+
if(isEncrypted()) {
126126
return DBEncryptionUtil.decrypt(value);
127127
} else {
128128
return value;
129129
}
130130
}
131131

132132
public void setValue(String value) {
133-
if(isEncryptedConfig()) {
133+
if(isEncrypted()) {
134134
this.value = DBEncryptionUtil.encrypt(value);
135135
} else {
136136
this.value = value;
137137
}
138138
}
139139

140-
private boolean isEncryptedConfig() {
140+
@Override
141+
public boolean isEncrypted() {
141142
return "Hidden".equals(getCategory()) || "Secure".equals(getCategory());
142143
}
143144

server/src/com/cloud/api/ApiResponseHelper.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package com.cloud.api;
1818

19+
import com.cloud.utils.crypt.DBEncryptionUtil;
1920
import com.cloud.agent.api.VgpuTypesInfo;
2021
import com.cloud.api.query.ViewResponseHelper;
2122
import com.cloud.api.query.vo.AccountJoinVO;
@@ -455,7 +456,11 @@ public ConfigurationResponse createConfigurationResponse(Configuration cfg) {
455456
cfgResponse.setCategory(cfg.getCategory());
456457
cfgResponse.setDescription(cfg.getDescription());
457458
cfgResponse.setName(cfg.getName());
458-
cfgResponse.setValue(cfg.getValue());
459+
if(cfg.isEncrypted()) {
460+
cfgResponse.setValue(DBEncryptionUtil.encrypt(cfg.getValue()));
461+
} else {
462+
cfgResponse.setValue(cfg.getValue());
463+
}
459464
cfgResponse.setObjectName("configuration");
460465

461466
return cfgResponse;

test/integration/smoke/test_internal_lb.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,8 +705,12 @@ def get_lb_stats_settings(self):
705705
self.apiclient, name="network.loadbalancer.haproxy.stats.port")[0].value
706706
settings["stats_uri"] = Configurations.list(
707707
self.apiclient, name="network.loadbalancer.haproxy.stats.uri")[0].value
708-
settings["username"], settings["password"] = Configurations.list(
709-
self.apiclient, name="network.loadbalancer.haproxy.stats.auth")[0].value.split(":")
708+
# Update global setting network.loadbalancer.haproxy.stats.auth to a known value
709+
haproxy_auth = "admin:password"
710+
Configurations.update(self.apiclient, "network.loadbalancer.haproxy.stats.auth", haproxy_auth)
711+
self.logger.debug(
712+
"Updated global setting stats network.loadbalancer.haproxy.stats.auth to %s" % (haproxy_auth))
713+
settings["username"], settings["password"] = haproxy_auth.split(":")
710714
settings["visibility"] = Configurations.list(
711715
self.apiclient, name="network.loadbalancer.haproxy.stats.visibility")[0].value
712716
self.logger.debug(settings)

0 commit comments

Comments
 (0)