Skip to content

Commit c39cf4c

Browse files
agent: enable ssl only for kvm agent (not in system vms) (apache#6371) (apache#151)
* agent: enable ssl only for kvm agent (not in system vms) * Revert "agent: enable ssl only for kvm agent (not in system vms)" This reverts commit b2d76ba. * Revert "KVM: Enable SSL if keystore exists (apache#6200)" This reverts commit 4525f8c. * KVM: Enable SSL if keystore exists in LibvirtComputingResource.java Co-authored-by: Wei Zhou <weizhou@apache.org>
1 parent 07abb80 commit c39cf4c

File tree

2 files changed

+19
-24
lines changed

2 files changed

+19
-24
lines changed

agent/src/main/java/com/cloud/agent/AgentShell.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
import com.cloud.utils.backoff.impl.ConstantTimeBackoff;
2929
import com.cloud.utils.exception.CloudRuntimeException;
3030
import com.google.common.base.Strings;
31-
import org.apache.cloudstack.utils.security.KeyStoreUtils;
32-
import org.apache.commons.lang3.StringUtils;
3331
import org.apache.commons.daemon.Daemon;
3432
import org.apache.commons.daemon.DaemonContext;
3533
import org.apache.commons.daemon.DaemonInitException;
@@ -376,7 +374,6 @@ public void init(String[] args) throws ConfigurationException {
376374

377375
loadProperties();
378376
parseCommand(args);
379-
enableSSL();
380377

381378
if (s_logger.isDebugEnabled()) {
382379
List<String> properties = Collections.list((Enumeration<String>)_properties.propertyNames());
@@ -400,27 +397,6 @@ public void init(String[] args) throws ConfigurationException {
400397
_backoff.configure("ConstantTimeBackoff", new HashMap<String, Object>());
401398
}
402399

403-
private void enableSSL() {
404-
final File agentFile = PropertiesUtil.findConfigFile("agent.properties");
405-
if (agentFile == null) {
406-
s_logger.info("Failed to find agent.properties file");
407-
return;
408-
}
409-
String keystorePass = getProperty(null, "keystore.passphrase");
410-
if (StringUtils.isBlank(keystorePass)) {
411-
s_logger.info("Failed to find passphrase for keystore: " + KeyStoreUtils.KS_FILENAME);
412-
return;
413-
}
414-
final String keyStoreFile = agentFile.getParent() + "/" + KeyStoreUtils.KS_FILENAME;
415-
File f = new File(keyStoreFile);
416-
if (f.exists() && !f.isDirectory()) {
417-
System.setProperty("javax.net.ssl.trustStore", keyStoreFile);
418-
System.setProperty("javax.net.ssl.trustStorePassword", keystorePass);
419-
} else {
420-
s_logger.info("Failed to find keystore file: " + keyStoreFile);
421-
}
422-
}
423-
424400
private void launchAgent() throws ConfigurationException {
425401
String resourceClassNames = getProperty(null, "resource");
426402
s_logger.trace("resource=" + resourceClassNames);

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,8 @@ public boolean configure(final String name, final Map<String, Object> params) th
10091009
_localStoragePath = "/var/lib/libvirt/images/";
10101010
}
10111011

1012+
enableSSLForKvmAgent(params);
1013+
10121014
/* Directory to use for Qemu sockets like for the Qemu Guest Agent */
10131015
_qemuSocketsPath = new File("/var/lib/libvirt/qemu");
10141016
String _qemuSocketsPathVar = (String)params.get("qemu.sockets.path");
@@ -1291,6 +1293,23 @@ public boolean configure(final String name, final Map<String, Object> params) th
12911293
return true;
12921294
}
12931295

1296+
private void enableSSLForKvmAgent(final Map<String, Object> params) {
1297+
final File keyStoreFile = PropertiesUtil.findConfigFile(KeyStoreUtils.KS_FILENAME);
1298+
if (keyStoreFile == null) {
1299+
s_logger.info("Failed to find keystore file: " + KeyStoreUtils.KS_FILENAME);
1300+
return;
1301+
}
1302+
String keystorePass = (String)params.get(KeyStoreUtils.KS_PASSPHRASE_PROPERTY);
1303+
if (StringUtils.isBlank(keystorePass)) {
1304+
s_logger.info("Failed to find passphrase for keystore: " + KeyStoreUtils.KS_FILENAME);
1305+
return;
1306+
}
1307+
if (keyStoreFile.exists() && !keyStoreFile.isDirectory()) {
1308+
System.setProperty("javax.net.ssl.trustStore", keyStoreFile.getAbsolutePath());
1309+
System.setProperty("javax.net.ssl.trustStorePassword", keystorePass);
1310+
}
1311+
}
1312+
12941313
public boolean configureHostParams(final Map<String, String> params) {
12951314
final File file = PropertiesUtil.findConfigFile("agent.properties");
12961315
if (file == null) {

0 commit comments

Comments
 (0)